eclipse-cyclonedds / cyclonedds

Eclipse Cyclone DDS project
https://projects.eclipse.org/projects/iot.cyclonedds
Other
854 stars 352 forks source link

IDL relative includes #1970

Open jakubStefanisin opened 5 months ago

jakubStefanisin commented 5 months ago

Getting weird behavior, Time.idl is found under std_msgs/msg but then generation breaks even if direct include to std_msgs/msg is provided. Seems like relative paths inside included IDL are not processed correctly.

File structure:

AccelStamped.idl:

include "Accel.idl"

include <std_msgs/msg/Header.idl>

module geometry_msgs { module msg {

struct AccelStamped { std_msgs::msg::Header header; geometry_msgs::msg::Accel accel; };

}; }; // module msg::geometry_msgs

Header .idl:

include "Time.idl"

module std_msgs { module msg {

struct Header { std_msgs::msg::Time stamp; string frame_id;
};

}; }; // module msg::std_msgs

ERROR:

./idlc -I /home/xxx/src/interfaces/idl/std_msgs/msg -I /home/xxx/src/interfaces/idl /home/xxx/src/interfaces/idl/geometry_msgs/msg/AccelStamped.idl Invalid line marker: path '/home/xxx/src/interfaces/idl/Time.idl' not found /home/xxx/src/interfaces/idl/std_msgs/msg/Time.idl:20: fatal error: File write error module std_msgs { module msg { from /home/xxx/src/interfaces/idl/std_msgs/msg/Header.idl: 21: #include "Time.idl" from /home/xxx/src/interfaces/idl/geometry_msgs/msg/AccelStamped.idl: 21: #include <std_msgs/msg/Header.idl> 1 error in preprocessor.

Is this expected behavior?

uupks commented 5 months ago

If you want to use idlc to genereta source code for rosidl , you can try How to use idlc to compile *.idl

eboasson commented 5 months ago

This is a bug that I can reproduce without any difficulty, I looked at it for a few minutes and came up with a quick hack that seems to make it work, but it'll take me a bit more time to fix it properly:

diff --git a/src/idl/src/directive.c b/src/idl/src/directive.c
index bb24af39e..ad63afea0 100644
--- a/src/idl/src/directive.c
+++ b/src/idl/src/directive.c
@@ -149,10 +149,13 @@ static idl_retcode_t push_line(idl_pstate_t *pstate, struct line *dir)

     if ((ret = idl_normalize_path(dir->path, &norm)) < 0) {
       idl_error(pstate, NULL, "Invalid line marker: path '%s' not found", dir->path);
+#if 0
       return ret;
+#endif
+    } else {
+      idl_free(dir->path);
+      dir->path = norm;
     }
-    idl_free(dir->path);
-    dir->path = norm;
     assert(dir->file);

     if (idl_isabsolute(dir->file)) {

The idea of the hack is basically to treat it as a warning, rather than an error. It is relaly only about managing the include directory stack and the line markers, and so continuing seems the lesser of the evils.