diff --git a/.github/workflows/reusable-ubuntu-ci.yml b/.github/workflows/reusable-ubuntu-ci.yml index 8ebaf05d..6ffa6d60 100644 --- a/.github/workflows/reusable-ubuntu-ci.yml +++ b/.github/workflows/reusable-ubuntu-ci.yml @@ -212,3 +212,10 @@ jobs: source ${{ github.workspace }}/install/local_setup.bash cd ${{ github.workspace }}/src/fastddsgen ./gradlew test + + - name: Test fastddsgen with python arg + if: ${{ inputs.run-tests == true }} + run: | + source ${{ github.workspace }}/install/local_setup.bash + cd ${{ github.workspace }}/src/fastddsgen/thirdparty/idl-parser/test/idls + find . -path "*.idl*" -exec fastddsgen -python {} + diff --git a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg index 36950815..afd9fc6a 100644 --- a/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg +++ b/src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg @@ -55,6 +55,15 @@ $definitions; separator="\n"$ $"\n"$ >> +module(ctx, parent, module, definition_list) ::= << +$definition_list$ +>> + +definition_list(definitions) ::= << +$definitions; separator="\n"$ + +>> + fast_macro_declarations() ::= << // Macro declarations // Any macro used on the Fast DDS header files will give an error if it is not redefined here @@ -64,27 +73,27 @@ fast_macro_declarations() ::= << struct_type(ctx, parent, struct, extensions) ::= << //////////////////////////////////////////////////////// -// Binding for class $struct.name$ +// Binding for class $struct.scopedname$ //////////////////////////////////////////////////////// // Ignore overloaded methods that have no application on Python // Otherwise they will issue a warning -%ignore $struct.name$::$struct.name$($struct.name$&&); +%ignore $struct.scopedname$::$struct.name$($struct.scopedname$&&); // Overloaded getter methods shadow each other and are equivalent in python // Avoid a warning ignoring all but one -$struct.members : {$member_getters(struct_name=struct.name, member=it)$}; separator="\n"$ +$struct.members : {$member_getters(struct_name=struct.scopedname, member=it)$}; separator="\n"$ -%template(_$struct.name$Seq) eprosima::fastdds::dds::LoanableTypedCollection<$struct.name$, std::false_type>; -%template($struct.name$Seq) eprosima::fastdds::dds::LoanableSequence<$struct.name$, std::false_type>; -%extend eprosima::fastdds::dds::LoanableSequence<$struct.name$, std::false_type> +%template(_$struct.name$Seq) eprosima::fastdds::dds::LoanableTypedCollection<$struct.scopedname$, std::false_type>; +%template($struct.name$Seq) eprosima::fastdds::dds::LoanableSequence<$struct.scopedname$, std::false_type>; +%extend eprosima::fastdds::dds::LoanableSequence<$struct.scopedname$, std::false_type> { size_t __len__() const { return self->length(); } - const $struct.name$& __getitem__(size_t i) const + const $struct.scopedname$& __getitem__(size_t i) const { return (*self)[i]; } @@ -129,7 +138,7 @@ $if(member.typecode.isSequenceType)$ $template_sequence(member.typecode)$ $elseif(member.typecode.isMapType)$ %ignore $struct_name$::$member.name$() const; -%template($member.typecode.keyTypeCode.cppTypename$_$member.typecode.valueTypeCode.cppTypename$_map) std::map<$member.typecode.keyTypeCode.cppTypename$,$member.typecode.valueTypeCode.cppTypename$>; +%template($member.typecode.keyTypeCode.name$_$member.typecode.valueTypeCode.cppTypename$_map) std::map<$member.typecode.keyTypeCode.cppTypename$,$member.typecode.valueTypeCode.cppTypename$>; $elseif(member.typecode.isType_f)$ %ignore $struct_name$::$member.name$() const; %template($member.typecode.contentTypeCode.formatedCppTypename$_$member.typecode.dimensions$_array) std::array<$member.typecode.contentTypeCode.cppTypename$,$member.typecode.dimensions$>; diff --git a/src/main/java/com/eprosima/fastdds/fastddsgen.java b/src/main/java/com/eprosima/fastdds/fastddsgen.java index 718f6c91..6464d116 100644 --- a/src/main/java/com/eprosima/fastdds/fastddsgen.java +++ b/src/main/java/com/eprosima/fastdds/fastddsgen.java @@ -779,7 +779,7 @@ private Project parseIDL( if (returnedValue) { // Create information of project for solution - project = new Project(ctx.getFilename(), idlFilename, ctx.getDependencies()); + project = new Project(ctx, idlFilename, ctx.getDependencies()); // Create all custom files for template if (processCustomTemplates) diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSwigInterface.stg b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSwigInterface.stg index 447b67cf..f8d11655 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSwigInterface.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSwigInterface.stg @@ -29,6 +29,12 @@ $fileHeader(ctx=ctx, file=[ctx.filename, "PubSubTypes.i"], description=["This h >> +module(ctx, parent, module, definition_list) ::= << +>> + +definition_list(definitions) ::= << +>> + struct_type(ctx, parent, struct) ::= << >> diff --git a/src/main/java/com/eprosima/fastdds/idl/templates/SwigCMake.stg b/src/main/java/com/eprosima/fastdds/idl/templates/SwigCMake.stg index 233d51ac..e115d685 100644 --- a/src/main/java/com/eprosima/fastdds/idl/templates/SwigCMake.stg +++ b/src/main/java/com/eprosima/fastdds/idl/templates/SwigCMake.stg @@ -96,6 +96,8 @@ include_directories( \${PROJECT_SOURCE_DIR} ) +set_property(SOURCE \${PROJECT_NAME}.i PROPERTY OUTPUT_DIR "\${CMAKE_CURRENT_BINARY_DIR}/$project.context.lastStructure.typeCode.namespaces : {$it$}; separator="/"$") + SWIG_ADD_LIBRARY(\${\${PROJECT_NAME}_MODULE} TYPE SHARED LANGUAGE python @@ -105,13 +107,18 @@ if(UNIX AND CMAKE_SIZEOF_VOID_P EQUAL 8) set_property(TARGET \${\${PROJECT_NAME}_MODULE} PROPERTY SWIG_COMPILE_DEFINITIONS SWIGWORDSIZE64) endif() -SWIG_LINK_LIBRARIES(\${\${PROJECT_NAME}_MODULE} +target_link_libraries(\${\${PROJECT_NAME}_MODULE} Python3::Module fastrtps \${PROJECT_NAME} $project.dependencies : {$it$}; separator=" "$ ) +set_target_properties(\${\${PROJECT_NAME}_MODULE} + PROPERTIES LIBRARY_OUTPUT_DIRECTORY "\${CMAKE_CURRENT_BINARY_DIR}/$project.context.lastStructure.typeCode.namespaces : {$it$}; separator="/"$" + ) + + # Find the installation path execute_process(COMMAND \${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(plat_specific=True, prefix='\${CMAKE_INSTALL_PREFIX}'))" OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH @@ -130,9 +137,8 @@ install(TARGETS \${PROJECT_NAME} LIBRARY DESTINATION lib/ ARCHIVE DESTINATION lib/ ) -install(TARGETS \${\${PROJECT_NAME}_MODULE} DESTINATION \${PYTHON_MODULE_PATH}) +install(TARGETS \${\${PROJECT_NAME}_MODULE} DESTINATION \${PYTHON_MODULE_PATH}/$project.context.lastStructure.typeCode.namespaces : {$it$}; separator="/"$) get_property(support_files TARGET \${\${PROJECT_NAME}_MODULE} PROPERTY SWIG_SUPPORT_FILES) -install(FILES \${support_files} DESTINATION \${PYTHON_MODULE_PATH}) +install(FILES \${support_files} DESTINATION \${PYTHON_MODULE_PATH}/$project.context.lastStructure.typeCode.namespaces : {$it$}; separator="/"$) >> - diff --git a/src/main/java/com/eprosima/fastdds/solution/Project.java b/src/main/java/com/eprosima/fastdds/solution/Project.java index 4f177a11..cbaa122f 100644 --- a/src/main/java/com/eprosima/fastdds/solution/Project.java +++ b/src/main/java/com/eprosima/fastdds/solution/Project.java @@ -18,13 +18,14 @@ import java.util.LinkedHashSet; import com.eprosima.solution.GUIDGenerator; +import com.eprosima.fastdds.idl.grammar.Context; import com.eprosima.idl.util.Util; public class Project extends com.eprosima.solution.Project { - public Project(String name, String file, LinkedHashSet dependencies) + public Project(Context ctx, String file, LinkedHashSet dependencies) { - super(name, file, dependencies); + super(ctx.getFilename(), file, dependencies); m_subscribersrcfiles = new ArrayList(); m_subscriberincludefiles = new ArrayList(); @@ -36,6 +37,7 @@ public Project(String name, String file, LinkedHashSet dependencies) m_jniincludefiles = new ArrayList(); m_idlincludefiles = new ArrayList(); m_idlincludefiles.addAll((LinkedHashSet)dependencies); + ctx_ = ctx; } public void addSubscriberSrcFile(String file) @@ -213,6 +215,11 @@ public ArrayList getIDLIncludeFiles() return m_idlincludefiles; } + public Context getContext() + { + return ctx_; + } + private boolean m_containsInterfaces = false; private ArrayList m_subscribersrcfiles = null; private ArrayList m_subscriberincludefiles = null; @@ -226,4 +233,6 @@ public ArrayList getIDLIncludeFiles() private ArrayList m_jniincludefiles = null; private ArrayList m_idlincludefiles = null; String m_guid = null; + + private Context ctx_ = null; }