Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[21592] Test generation of types with -python in ci (backport #399) #403

Open
wants to merge 3 commits into
base: 2.5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/reusable-ubuntu-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {} +
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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];
}
Expand Down Expand Up @@ -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$>;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/eprosima/fastdds/fastddsgen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) ::= <<
>>

Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/eprosima/fastdds/idl/templates/SwigCMake.stg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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="/"$)

>>

13 changes: 11 additions & 2 deletions src/main/java/com/eprosima/fastdds/solution/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> dependencies)
public Project(Context ctx, String file, LinkedHashSet<String> dependencies)
{
super(name, file, dependencies);
super(ctx.getFilename(), file, dependencies);

m_subscribersrcfiles = new ArrayList<String>();
m_subscriberincludefiles = new ArrayList<String>();
Expand All @@ -36,6 +37,7 @@ public Project(String name, String file, LinkedHashSet<String> dependencies)
m_jniincludefiles = new ArrayList<String>();
m_idlincludefiles = new ArrayList<String>();
m_idlincludefiles.addAll((LinkedHashSet<String>)dependencies);
ctx_ = ctx;
}

public void addSubscriberSrcFile(String file)
Expand Down Expand Up @@ -213,6 +215,11 @@ public ArrayList<String> getIDLIncludeFiles()
return m_idlincludefiles;
}

public Context getContext()
{
return ctx_;
}

private boolean m_containsInterfaces = false;
private ArrayList<String> m_subscribersrcfiles = null;
private ArrayList<String> m_subscriberincludefiles = null;
Expand All @@ -226,4 +233,6 @@ public ArrayList<String> getIDLIncludeFiles()
private ArrayList<String> m_jniincludefiles = null;
private ArrayList<String> m_idlincludefiles = null;
String m_guid = null;

private Context ctx_ = null;
}
Loading