-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose .idl to DDS .idl conversion via rosidl translate CLI
Signed-off-by: Michel Hidalgo <[email protected]>
- Loading branch information
Showing
11 changed files
with
202 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
.DS_Store | ||
__pycache__ | ||
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
junit_family=xunit2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright 2021 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import pathlib | ||
|
||
from ament_index_python import get_package_share_directory | ||
from rosidl_cli.command.helpers import legacy_generator_arguments_file | ||
from rosidl_cli.command.translate.extensions import TranslateCommandExtension | ||
|
||
from rosidl_generator_dds_idl import generate_dds_idl | ||
|
||
|
||
class TranslateIDLToDDSIDL(TranslateCommandExtension): | ||
|
||
input_format = 'idl' | ||
output_format = 'dds_idl' | ||
|
||
def translate( | ||
self, | ||
package_name, | ||
interface_files, | ||
include_paths, | ||
output_path | ||
): | ||
package_share_path = pathlib.Path( | ||
get_package_share_directory('rosidl_generator_dds_idl')) | ||
templates_path = package_share_path / 'resource' | ||
|
||
with legacy_generator_arguments_file( | ||
package_name=package_name, | ||
interface_files=interface_files, | ||
include_paths=include_paths, | ||
templates_path=templates_path, | ||
output_path=output_path | ||
) as path_to_arguments_file: | ||
generated_files = generate_dds_idl( | ||
path_to_arguments_file, | ||
subfolders=[], | ||
extension_module_name=None, | ||
additional_service_templates=[] | ||
) | ||
translated_interface_files = [] | ||
for path in generated_files: | ||
path = pathlib.Path(path) | ||
relative_path = path.relative_to(output_path) | ||
translated_interface_files.append( | ||
f'{output_path}:{relative_path.as_posix()}' | ||
) | ||
return translated_interface_files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[options.entry_points] | ||
rosidl_cli.command.translate.extensions = | ||
idl2ddsidl = rosidl_generator_dds_idl.cli:TranslateIDLToDDSIDL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// generated from rosidl_adapter/resource/msg.idl.em | ||
// with input from test_msgs/msg/Test.msg | ||
// generated code does not contain a copyright notice | ||
|
||
|
||
module test_msgs { | ||
module msg { | ||
struct Test { | ||
boolean bool_value; | ||
|
||
octet byte_value; | ||
|
||
uint8 char_value; | ||
|
||
float float32_value; | ||
|
||
double float64_value; | ||
|
||
int8 int8_value; | ||
|
||
uint8 uint8_value; | ||
|
||
int16 int16_value; | ||
|
||
uint16 uint16_value; | ||
|
||
int32 int32_value; | ||
|
||
uint32 uint32_value; | ||
|
||
int64 int64_value; | ||
|
||
uint64 uint64_value; | ||
}; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// generated from rosidl_generator_dds_idl/resource/idl.idl.em | ||
// with input from test_msgs:msg/Test.idl | ||
// generated code does not contain a copyright notice | ||
|
||
#ifndef __test_msgs__msg__test__idl__ | ||
#define __test_msgs__msg__test__idl__ | ||
|
||
|
||
module test_msgs { | ||
|
||
module msg { | ||
|
||
module dds_ { | ||
|
||
|
||
struct Test_ { | ||
boolean bool_value_; | ||
octet byte_value_; | ||
octet char_value_; | ||
float float32_value_; | ||
double float64_value_; | ||
octet int8_value_; | ||
octet uint8_value_; | ||
short int16_value_; | ||
unsigned short uint16_value_; | ||
long int32_value_; | ||
unsigned long uint32_value_; | ||
long long int64_value_; | ||
unsigned long long uint64_value_; | ||
|
||
}; | ||
|
||
|
||
}; // module dds_ | ||
|
||
}; // module msg | ||
|
||
}; // module test_msgs | ||
|
||
|
||
#endif // __test_msgs__msg__test__idl__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Copyright 2021 Open Source Robotics Foundation, Inc. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
import filecmp | ||
import pathlib | ||
|
||
from rosidl_cli.command.translate.api import translate | ||
|
||
|
||
DATA_PATH = pathlib.Path(__file__).parent / 'data' | ||
|
||
|
||
def test_idl2ddsidl_translation(tmp_path, capsys): | ||
# NOTE(hidmic): pytest and empy do not play along, | ||
# the latter expects some proxy will stay in sys.stdout | ||
# and the former insists in overwriting it | ||
import sys | ||
print(sys.path) | ||
|
||
with capsys.disabled(): | ||
# Test .idl to _.idl translation | ||
idl_files = translate( | ||
package_name='test_msgs', | ||
interface_files=[ | ||
f'{DATA_PATH}:msg/Test.idl'], | ||
output_path=tmp_path, | ||
output_format='dds_idl', | ||
translators=['idl2ddsidl'] | ||
) | ||
|
||
assert len(idl_files) == 1 | ||
idl_file = idl_files[0] | ||
assert idl_file == f'{tmp_path}:msg/Test_.idl' | ||
assert filecmp.cmp( | ||
tmp_path / 'msg' / 'Test_.idl', | ||
DATA_PATH / 'msg' / 'Test_.expected.idl', | ||
shallow=False | ||
) |