Skip to content

Commit 7af60e9

Browse files
rsanchez15richiware
authored andcommitted
Python modules support (#194)
* Initial approach Signed-off-by: Ricardo González Moreno <[email protected]> * Refs #18819. Fix location of created library Signed-off-by: Ricardo González Moreno <[email protected]> --------- Signed-off-by: Ricardo González Moreno <[email protected]> Co-authored-by: Ricardo González Moreno <[email protected]>
1 parent df1b50f commit 7af60e9

File tree

5 files changed

+45
-15
lines changed

5 files changed

+45
-15
lines changed

src/main/java/com/eprosima/fastcdr/idl/templates/TypesSwigInterface.stg

+17-8
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ $definitions; separator="\n"$
5555
$"\n"$
5656
>>
5757

58+
module(ctx, parent, module, definition_list) ::= <<
59+
$definition_list$
60+
>>
61+
62+
definition_list(definitions) ::= <<
63+
$definitions; separator="\n"$
64+
65+
>>
66+
5867
fast_macro_declarations() ::= <<
5968
// Macro declarations
6069
// 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() ::= <<
6473

6574
struct_type(ctx, parent, struct, extensions) ::= <<
6675
////////////////////////////////////////////////////////
67-
// Binding for class $struct.name$
76+
// Binding for class $struct.scopedname$
6877
////////////////////////////////////////////////////////
6978

7079
// Ignore overloaded methods that have no application on Python
7180
// Otherwise they will issue a warning
72-
%ignore $struct.name$::$struct.name$($struct.name$&&);
81+
%ignore $struct.scopedname$::$struct.name$($struct.scopedname$&&);
7382

7483
// Overloaded getter methods shadow each other and are equivalent in python
7584
// Avoid a warning ignoring all but one
76-
$struct.members : {$member_getters(struct_name=struct.name, member=it)$}; separator="\n"$
85+
$struct.members : {$member_getters(struct_name=struct.scopedname, member=it)$}; separator="\n"$
7786

78-
%template(_$struct.name$Seq) eprosima::fastdds::dds::LoanableTypedCollection<$struct.name$, std::false_type>;
79-
%template($struct.name$Seq) eprosima::fastdds::dds::LoanableSequence<$struct.name$, std::false_type>;
80-
%extend eprosima::fastdds::dds::LoanableSequence<$struct.name$, std::false_type>
87+
%template(_$struct.name$Seq) eprosima::fastdds::dds::LoanableTypedCollection<$struct.scopedname$, std::false_type>;
88+
%template($struct.name$Seq) eprosima::fastdds::dds::LoanableSequence<$struct.scopedname$, std::false_type>;
89+
%extend eprosima::fastdds::dds::LoanableSequence<$struct.scopedname$, std::false_type>
8190
{
8291
size_t __len__() const
8392
{
8493
return self->length();
8594
}
8695

87-
const $struct.name$& __getitem__(size_t i) const
96+
const $struct.scopedname$& __getitem__(size_t i) const
8897
{
8998
return (*self)[i];
9099
}
@@ -129,7 +138,7 @@ $if(member.typecode.isSequenceType)$
129138
$template_sequence(member.typecode)$
130139
$elseif(member.typecode.isMapType)$
131140
%ignore $struct_name$::$member.name$() const;
132-
%template($member.typecode.keyTypeCode.cppTypename$_$member.typecode.valueTypeCode.cppTypename$_map) std::map<$member.typecode.keyTypeCode.cppTypename$,$member.typecode.valueTypeCode.cppTypename$>;
141+
%template($member.typecode.keyTypeCode.name$_$member.typecode.valueTypeCode.cppTypename$_map) std::map<$member.typecode.keyTypeCode.cppTypename$,$member.typecode.valueTypeCode.cppTypename$>;
133142
$elseif(member.typecode.isType_f)$
134143
%ignore $struct_name$::$member.name$() const;
135144
%template($member.typecode.contentTypeCode.formatedCppTypename$_$member.typecode.dimensions$_array) std::array<$member.typecode.contentTypeCode.cppTypename$,$member.typecode.dimensions$>;

src/main/java/com/eprosima/fastdds/fastddsgen.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ private Project parseIDL(
779779
if (returnedValue)
780780
{
781781
// Create information of project for solution
782-
project = new Project(ctx.getFilename(), idlFilename, ctx.getDependencies());
782+
project = new Project(ctx, idlFilename, ctx.getDependencies());
783783

784784
// Create all custom files for template
785785
if (processCustomTemplates)

src/main/java/com/eprosima/fastdds/idl/templates/DDSPubSubTypeSwigInterface.stg

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ $fileHeader(ctx=ctx, file=[ctx.filename, "PubSubTypes.i"], description=["This h
2929

3030
>>
3131

32+
module(ctx, parent, module, definition_list) ::= <<
33+
>>
34+
35+
definition_list(definitions) ::= <<
36+
>>
37+
3238
struct_type(ctx, parent, struct) ::= <<
3339
>>
3440

src/main/java/com/eprosima/fastdds/idl/templates/SwigCMake.stg

+10-4
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ include_directories(
9696
\${PROJECT_SOURCE_DIR}
9797
)
9898

99+
set_property(SOURCE \${PROJECT_NAME}.i PROPERTY OUTPUT_DIR "\${CMAKE_CURRENT_BINARY_DIR}/$project.context.lastStructure.typeCode.namespaces : {$it$}; separator="/"$")
100+
99101
SWIG_ADD_LIBRARY(\${\${PROJECT_NAME}_MODULE}
100102
TYPE SHARED
101103
LANGUAGE python
@@ -105,13 +107,18 @@ if(UNIX AND CMAKE_SIZEOF_VOID_P EQUAL 8)
105107
set_property(TARGET \${\${PROJECT_NAME}_MODULE} PROPERTY SWIG_COMPILE_DEFINITIONS SWIGWORDSIZE64)
106108
endif()
107109

108-
SWIG_LINK_LIBRARIES(\${\${PROJECT_NAME}_MODULE}
110+
target_link_libraries(\${\${PROJECT_NAME}_MODULE}
109111
Python3::Module
110112
fastrtps
111113
\${PROJECT_NAME}
112114
$project.dependencies : {$it$}; separator=" "$
113115
)
114116

117+
set_target_properties(\${\${PROJECT_NAME}_MODULE}
118+
PROPERTIES LIBRARY_OUTPUT_DIRECTORY "\${CMAKE_CURRENT_BINARY_DIR}/$project.context.lastStructure.typeCode.namespaces : {$it$}; separator="/"$"
119+
)
120+
121+
115122
# Find the installation path
116123
execute_process(COMMAND \${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print(sysconfig.get_python_lib(plat_specific=True, prefix='\${CMAKE_INSTALL_PREFIX}'))"
117124
OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH
@@ -130,9 +137,8 @@ install(TARGETS \${PROJECT_NAME}
130137
LIBRARY DESTINATION lib/
131138
ARCHIVE DESTINATION lib/
132139
)
133-
install(TARGETS \${\${PROJECT_NAME}_MODULE} DESTINATION \${PYTHON_MODULE_PATH})
140+
install(TARGETS \${\${PROJECT_NAME}_MODULE} DESTINATION \${PYTHON_MODULE_PATH}/$project.context.lastStructure.typeCode.namespaces : {$it$}; separator="/"$)
134141
get_property(support_files TARGET \${\${PROJECT_NAME}_MODULE} PROPERTY SWIG_SUPPORT_FILES)
135-
install(FILES \${support_files} DESTINATION \${PYTHON_MODULE_PATH})
142+
install(FILES \${support_files} DESTINATION \${PYTHON_MODULE_PATH}/$project.context.lastStructure.typeCode.namespaces : {$it$}; separator="/"$)
136143

137144
>>
138-

src/main/java/com/eprosima/fastdds/solution/Project.java

+11-2
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
import java.util.LinkedHashSet;
1919

2020
import com.eprosima.solution.GUIDGenerator;
21+
import com.eprosima.fastdds.idl.grammar.Context;
2122
import com.eprosima.idl.util.Util;
2223

2324
public class Project extends com.eprosima.solution.Project
2425
{
25-
public Project(String name, String file, LinkedHashSet<String> dependencies)
26+
public Project(Context ctx, String file, LinkedHashSet<String> dependencies)
2627
{
27-
super(name, file, dependencies);
28+
super(ctx.getFilename(), file, dependencies);
2829

2930
m_subscribersrcfiles = new ArrayList<String>();
3031
m_subscriberincludefiles = new ArrayList<String>();
@@ -36,6 +37,7 @@ public Project(String name, String file, LinkedHashSet<String> dependencies)
3637
m_jniincludefiles = new ArrayList<String>();
3738
m_idlincludefiles = new ArrayList<String>();
3839
m_idlincludefiles.addAll((LinkedHashSet<String>)dependencies);
40+
ctx_ = ctx;
3941
}
4042

4143
public void addSubscriberSrcFile(String file)
@@ -213,6 +215,11 @@ public ArrayList<String> getIDLIncludeFiles()
213215
return m_idlincludefiles;
214216
}
215217

218+
public Context getContext()
219+
{
220+
return ctx_;
221+
}
222+
216223
private boolean m_containsInterfaces = false;
217224
private ArrayList<String> m_subscribersrcfiles = null;
218225
private ArrayList<String> m_subscriberincludefiles = null;
@@ -226,4 +233,6 @@ public ArrayList<String> getIDLIncludeFiles()
226233
private ArrayList<String> m_jniincludefiles = null;
227234
private ArrayList<String> m_idlincludefiles = null;
228235
String m_guid = null;
236+
237+
private Context ctx_ = null;
229238
}

0 commit comments

Comments
 (0)