Skip to content

Commit 1242d04

Browse files
committed
Expose .idl to DDS .idl conversion via rosidl translate CLI
Signed-off-by: Michel Hidalgo <[email protected]>
1 parent 0539c0a commit 1242d04

File tree

11 files changed

+202
-4
lines changed

11 files changed

+202
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
.DS_Store
2+
__pycache__
3+
*.pyc

rosidl_generator_dds_idl/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ find_package(ament_cmake_python REQUIRED)
88
ament_python_install_package(${PROJECT_NAME})
99

1010
if(BUILD_TESTING)
11+
find_package(ament_cmake_pytest REQUIRED)
1112
find_package(ament_lint_auto REQUIRED)
1213
ament_lint_auto_find_test_dependencies()
14+
ament_add_pytest_test(pytest test)
1315
endif()
1416

1517
ament_package(

rosidl_generator_dds_idl/bin/rosidl_generator_dds_idl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ def main(argv=sys.argv[1:]):
2929
help='The Python module extending the generator')
3030
args = parser.parse_args(argv)
3131

32-
return generate_dds_idl(
32+
generate_dds_idl(
3333
args.generator_arguments_file,
3434
args.subfolders,
3535
args.extension,
3636
args.additional_service_templates,
3737
)
38-
38+
return 0
3939

4040
if __name__ == '__main__':
4141
sys.exit(main())

rosidl_generator_dds_idl/package.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
<buildtool_export_depend>ament_cmake</buildtool_export_depend>
1414
<buildtool_export_depend>rosidl_cmake</buildtool_export_depend>
1515

16+
<exec_depend>ament_index_python</exec_depend>
17+
<exec_depend>rosidl_cli</exec_depend>
18+
19+
<test_depend>ament_cmake_pytest</test_depend>
1620
<test_depend>ament_lint_auto</test_depend>
1721
<test_depend>ament_lint_common</test_depend>
1822

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[pytest]
2+
junit_family=xunit2

rosidl_generator_dds_idl/rosidl_generator_dds_idl/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ def generate_dds_idl(
4848
if hasattr(module, entity_name):
4949
additional_context[entity_name] = \
5050
getattr(module, entity_name)
51-
generate_files(generator_arguments_file, mapping, additional_context, keep_case=True)
52-
return 0
51+
return generate_files(generator_arguments_file, mapping, additional_context, keep_case=True)
5352

5453

5554
# used by the template
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2021 Open Source Robotics Foundation, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import pathlib
16+
17+
from ament_index_python import get_package_share_directory
18+
from rosidl_cli.command.helpers import legacy_generator_arguments_file
19+
from rosidl_cli.command.translate.extensions import TranslateCommandExtension
20+
21+
from rosidl_generator_dds_idl import generate_dds_idl
22+
23+
24+
class TranslateIDLToDDSIDL(TranslateCommandExtension):
25+
26+
input_format = 'idl'
27+
output_format = 'dds_idl'
28+
29+
def translate(
30+
self,
31+
package_name,
32+
interface_files,
33+
include_paths,
34+
output_path
35+
):
36+
package_share_path = pathlib.Path(
37+
get_package_share_directory('rosidl_generator_dds_idl'))
38+
templates_path = package_share_path / 'resource'
39+
40+
with legacy_generator_arguments_file(
41+
package_name=package_name,
42+
interface_files=interface_files,
43+
include_paths=include_paths,
44+
templates_path=templates_path,
45+
output_path=output_path
46+
) as path_to_arguments_file:
47+
generated_files = generate_dds_idl(
48+
path_to_arguments_file,
49+
subfolders=[],
50+
extension_module_name=None,
51+
additional_service_templates=[]
52+
)
53+
translated_interface_files = []
54+
for path in generated_files:
55+
path = pathlib.Path(path)
56+
relative_path = path.relative_to(output_path)
57+
translated_interface_files.append(
58+
f'{output_path}:{relative_path.as_posix()}'
59+
)
60+
return translated_interface_files

rosidl_generator_dds_idl/setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[options.entry_points]
2+
rosidl_cli.command.translate.extensions =
3+
idl2ddsidl = rosidl_generator_dds_idl.cli:TranslateIDLToDDSIDL
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// generated from rosidl_adapter/resource/msg.idl.em
2+
// with input from test_msgs/msg/Test.msg
3+
// generated code does not contain a copyright notice
4+
5+
6+
module test_msgs {
7+
module msg {
8+
struct Test {
9+
boolean bool_value;
10+
11+
octet byte_value;
12+
13+
uint8 char_value;
14+
15+
float float32_value;
16+
17+
double float64_value;
18+
19+
int8 int8_value;
20+
21+
uint8 uint8_value;
22+
23+
int16 int16_value;
24+
25+
uint16 uint16_value;
26+
27+
int32 int32_value;
28+
29+
uint32 uint32_value;
30+
31+
int64 int64_value;
32+
33+
uint64 uint64_value;
34+
};
35+
};
36+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// generated from rosidl_generator_dds_idl/resource/idl.idl.em
2+
// with input from test_msgs:msg/Test.idl
3+
// generated code does not contain a copyright notice
4+
5+
#ifndef __test_msgs__msg__test__idl__
6+
#define __test_msgs__msg__test__idl__
7+
8+
9+
module test_msgs {
10+
11+
module msg {
12+
13+
module dds_ {
14+
15+
16+
struct Test_ {
17+
boolean bool_value_;
18+
octet byte_value_;
19+
octet char_value_;
20+
float float32_value_;
21+
double float64_value_;
22+
octet int8_value_;
23+
octet uint8_value_;
24+
short int16_value_;
25+
unsigned short uint16_value_;
26+
long int32_value_;
27+
unsigned long uint32_value_;
28+
long long int64_value_;
29+
unsigned long long uint64_value_;
30+
31+
};
32+
33+
34+
}; // module dds_
35+
36+
}; // module msg
37+
38+
}; // module test_msgs
39+
40+
41+
#endif // __test_msgs__msg__test__idl__

0 commit comments

Comments
 (0)