forked from eclipse-ecal/rosidl_typesupport_protobuf
-
Notifications
You must be signed in to change notification settings - Fork 0
Rosidl cli generate proto test #25
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
Open
gonzodepedro
wants to merge
4
commits into
streamline-file-generation
Choose a base branch
from
rosidl-cli-generate-proto-test
base: streamline-file-generation
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9d028fe
Added test cases for rosidl cli into protobuf typesupports
gonzodepedro e08db98
Removed dead code
gonzodepedro 0665f21
Get package share directory using ament_index_python
gonzodepedro c366f33
Added ament_python_test to package.xml
gonzodepedro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
72 changes: 72 additions & 0 deletions
72
rosidl_typesupport_protobuf_c/rosidl_typesupport_protobuf_c/cli.py
This file contains hidden or 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,72 @@ | ||
import pathlib | ||
|
||
from ament_index_python import get_package_share_directory | ||
|
||
from rosidl_cli.command.generate.extensions import GenerateCommandExtension | ||
from rosidl_cli.command.helpers import generate_visibility_control_file | ||
from rosidl_cli.command.helpers import legacy_generator_arguments_file | ||
from rosidl_cli.command.translate.api import translate | ||
|
||
from rosidl_typesupport_protobuf_c import generate_typesupport_protobuf_c | ||
|
||
|
||
class GenerateProtobufCTypesupport(GenerateCommandExtension): | ||
|
||
def generate( | ||
self, | ||
package_name, | ||
interface_files, | ||
include_paths, | ||
output_path | ||
): | ||
generated_files = [] | ||
|
||
package_share_path = pathlib.Path( | ||
get_package_share_directory('rosidl_typesupport_protobuf_c')) | ||
templates_path = package_share_path / 'resource' | ||
|
||
# Normalize interface definition format to .idl | ||
idl_interface_files = [] | ||
non_idl_interface_files = [] | ||
for path in interface_files: | ||
if not path.endswith('.idl'): | ||
non_idl_interface_files.append(path) | ||
else: | ||
idl_interface_files.append(path) | ||
if non_idl_interface_files: | ||
idl_interface_files.extend(translate( | ||
package_name=package_name, | ||
interface_files=non_idl_interface_files, | ||
include_paths=include_paths, | ||
output_format='idl', | ||
output_path=output_path / 'tmp', | ||
)) | ||
|
||
# Generate visibility control file | ||
visibility_control_file_template_path = \ | ||
'rosidl_typesupport_protobuf_c__visibility_control.h.in' | ||
visibility_control_file_template_path = \ | ||
templates_path / visibility_control_file_template_path | ||
visibility_control_file_path = \ | ||
'rosidl_typesupport_protobuf_c__visibility_control.h' | ||
visibility_control_file_path = \ | ||
output_path / 'msg' / visibility_control_file_path | ||
|
||
generate_visibility_control_file( | ||
package_name=package_name, | ||
template_path=visibility_control_file_template_path, | ||
output_path=visibility_control_file_path | ||
) | ||
generated_files.append(visibility_control_file_path) | ||
|
||
# Generate code | ||
with legacy_generator_arguments_file( | ||
package_name=package_name, | ||
interface_files=idl_interface_files, | ||
include_paths=include_paths, | ||
templates_path=templates_path, | ||
output_path=output_path | ||
) as path_to_arguments_file: | ||
generated_files.extend(generate_typesupport_protobuf_c(path_to_arguments_file)) | ||
|
||
return generated_files |
This file contains hidden or 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.generate.typesupport_extensions = | ||
protobuf_c = rosidl_typesupport_protobuf_c.cli:GenerateProtobufCTypesupport |
30 changes: 30 additions & 0 deletions
30
rosidl_typesupport_protobuf_c/test/test_rosidl_cli_ts_pb_c.py
This file contains hidden or 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,30 @@ | ||
import pytest | ||
import os | ||
import pathlib | ||
import shutil | ||
import subprocess | ||
|
||
from ament_index_python import get_package_share_directory | ||
|
||
def test_ts_files_generation(): | ||
build_then_install('/tmp/pb') | ||
files_exists('/tmp/pb') | ||
|
||
def build_then_install(output_path): | ||
if os.path.exists(output_path): | ||
shutil.rmtree(output_path) | ||
os.makedirs(output_path) | ||
|
||
package_share_path = pathlib.Path( | ||
get_package_share_directory('std_msgs')) | ||
|
||
subprocess.run([ | ||
'rosidl', 'generate', '-ts', 'protobuf_c', '-o', output_path, 'std_msgs', './msg/String.msg' | ||
], cwd=package_share_path, check=True) | ||
|
||
def files_exists(output_path): | ||
assert pathlib.Path('/tmp/pb/tmp/msg/String.idl').exists() | ||
assert pathlib.Path('/tmp/pb/msg/rosidl_typesupport_protobuf_c__visibility_control.h').exists() | ||
assert pathlib.Path('/tmp/pb/msg/string__rosidl_typesupport_protobuf_c.hpp').exists() | ||
assert pathlib.Path('/tmp/pb/msg/detail/string__type_support.cpp').exists() | ||
|
This file contains hidden or 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 hidden or 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 hidden or 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
72 changes: 72 additions & 0 deletions
72
rosidl_typesupport_protobuf_cpp/rosidl_typesupport_protobuf_cpp/cli.py
This file contains hidden or 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,72 @@ | ||
import pathlib | ||
|
||
from ament_index_python import get_package_share_directory | ||
|
||
from rosidl_cli.command.generate.extensions import GenerateCommandExtension | ||
from rosidl_cli.command.helpers import generate_visibility_control_file | ||
from rosidl_cli.command.helpers import legacy_generator_arguments_file | ||
from rosidl_cli.command.translate.api import translate | ||
|
||
from rosidl_typesupport_protobuf_cpp import generate_cpp | ||
|
||
|
||
class GenerateProtobufCppTypesupport(GenerateCommandExtension): | ||
|
||
def generate( | ||
self, | ||
package_name, | ||
interface_files, | ||
include_paths, | ||
output_path | ||
): | ||
generated_files = [] | ||
|
||
package_share_path = pathlib.Path( | ||
get_package_share_directory('rosidl_typesupport_protobuf_cpp')) | ||
templates_path = package_share_path / 'resource' | ||
|
||
# Normalize interface definition format to .idl | ||
idl_interface_files = [] | ||
non_idl_interface_files = [] | ||
for path in interface_files: | ||
if not path.endswith('.idl'): | ||
non_idl_interface_files.append(path) | ||
else: | ||
idl_interface_files.append(path) | ||
if non_idl_interface_files: | ||
idl_interface_files.extend(translate( | ||
package_name=package_name, | ||
interface_files=non_idl_interface_files, | ||
include_paths=include_paths, | ||
output_format='idl', | ||
output_path=output_path / 'tmp', | ||
)) | ||
|
||
# Generate visibility control file | ||
visibility_control_file_template_path = \ | ||
'rosidl_typesupport_protobuf_cpp__visibility_control.h.in' | ||
visibility_control_file_template_path = \ | ||
templates_path / visibility_control_file_template_path | ||
visibility_control_file_path = \ | ||
'rosidl_typesupport_protobuf_cpp__visibility_control.h' | ||
visibility_control_file_path = \ | ||
output_path / 'msg' / visibility_control_file_path | ||
|
||
generate_visibility_control_file( | ||
package_name=package_name, | ||
template_path=visibility_control_file_template_path, | ||
output_path=visibility_control_file_path | ||
) | ||
generated_files.append(visibility_control_file_path) | ||
|
||
# Generate code | ||
with legacy_generator_arguments_file( | ||
package_name=package_name, | ||
interface_files=idl_interface_files, | ||
include_paths=include_paths, | ||
templates_path=templates_path, | ||
output_path=output_path | ||
) as path_to_arguments_file: | ||
generated_files.extend(generate_cpp(path_to_arguments_file)) | ||
|
||
return generated_files |
This file contains hidden or 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.generate.typesupport_extensions = | ||
protobuf_cpp = rosidl_typesupport_protobuf_cpp.cli:GenerateProtobufCppTypesupport |
31 changes: 31 additions & 0 deletions
31
rosidl_typesupport_protobuf_cpp/test/test_rosidl_cli_ts_pb_cpp.py
This file contains hidden or 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,31 @@ | ||
import pytest | ||
import os | ||
import pathlib | ||
import shutil | ||
import subprocess | ||
|
||
from ament_index_python import get_package_share_directory | ||
|
||
def test_ts_files_generation(): | ||
build_then_install('/tmp/pb') | ||
files_exists('/tmp/pb') | ||
|
||
def build_then_install(output_path): | ||
if os.path.exists(output_path): | ||
shutil.rmtree(output_path) | ||
os.makedirs(output_path) | ||
|
||
package_share_path = pathlib.Path( | ||
get_package_share_directory('std_msgs')) | ||
|
||
subprocess.run([ | ||
'rosidl', 'generate', '-ts', 'protobuf_cpp', '-o', output_path, 'std_msgs', './msg/String.msg' | ||
], cwd=package_share_path, check=True) | ||
|
||
def files_exists(output_path): | ||
assert pathlib.Path('/tmp/pb/tmp/msg/String.idl').exists() | ||
assert pathlib.Path('/tmp/pb/msg/rosidl_typesupport_protobuf_cpp__visibility_control.h').exists() | ||
assert pathlib.Path('/tmp/pb/msg/string__rosidl_typesupport_protobuf_cpp.hpp').exists() | ||
assert pathlib.Path('/tmp/pb/msg/string__typeadapter_protobuf_cpp.hpp').exists() | ||
assert pathlib.Path('/tmp/pb/msg/detail/string__type_support.cpp').exists() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needed in package.xml too