-
Notifications
You must be signed in to change notification settings - Fork 125
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
[WIP] restructure rosidl to work with IDL files #298
Closed
Closed
Changes from 8 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
cf56be9
copy ROS msg/srv parser
dirk-thomas 48635bc
remove message/service specific stuff from the other module
dirk-thomas b1caf0d
add rosidl_adapter package
dirk-thomas bd944f8
use rosidl_parser in rosidl_cmake, allow passing interface files with…
dirk-thomas 552b08c
add lark grammar and parsing functions
dirk-thomas 9149d16
update rosidl_generator_c to use IDL files
dirk-thomas 9b0e9d0
fix Python 3.5 issue
dirk-thomas 43a9052
only require either messages or services
dirk-thomas 2425af5
add u16string type and functions and use for wstring, add long double
dirk-thomas 166d457
fix for 43a90521
dirk-thomas e177d0b
[rosidl_generator_c] fix (w)string with upper bound
dirk-thomas 66f9129
get_filename_component(... EXT) includes '.'
sloretz 34b5c46
Try to convert message and service files
sloretz 4393367
Further work on IDL.
mjcarroll 0a4af16
Include message name in constants module
sloretz 028b117
1.125 is a legal floating point literal
sloretz 75593a4
multiple annotation_appl per member
sloretz b5df207
add string literal escaping
sloretz 0bee962
First attempt at char literal escaping
sloretz 88569ee
More informative error message.
mjcarroll 94dbeeb
Change char mapping to int8.
mjcarroll 9cc7654
String escaping fixup.
mjcarroll a069cbc
Check escape before graphic char
sloretz 7aa8d9d
.srv use string literal escape function
sloretz 0202f3d
Allow verbatim rosidl_array_init
sloretz d4e108b
Remove to_character_literal since type changed to uint8
sloretz a5cc511
array values use verbatim annotation
sloretz 208e063
Merge branch 'shane/rosidl-reloaded' into rosidl-reloaded
dirk-thomas 0aee9b7
add additional rule to grammar to distinguish relevants parts of a ma…
dirk-thomas 499028e
add priorities / weights to prefer certain rules
dirk-thomas 25b4f1e
add new object representation for interfaces
dirk-thomas 5fdbd8c
add parser to parse .idl files using lark and transform the AST into …
dirk-thomas bc9578f
add test for .idl parser
dirk-thomas a9fd325
working copy dump
dirk-thomas 4635a93
extract comments and units
dirk-thomas 6bd82b0
replace function pointer with import
dirk-thomas 49463a6
rm obsolete file
dirk-thomas 9116396
migrate rosidl_generator_cpp, fix rosidl_generator_c
dirk-thomas 5ee3cb0
avoid duplicate logic
dirk-thomas 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 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,23 @@ | ||
<?xml version="1.0"?> | ||
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?> | ||
<package format="2"> | ||
<name>rosidl_adapter</name> | ||
<version>0.5.1</version> | ||
<description> | ||
Scripts to convert .msg/.srv files to .idl. | ||
</description> | ||
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer> | ||
<license>Apache License 2.0</license> | ||
|
||
<exec_depend>python3-empy</exec_depend> | ||
<exec_depend>rosidl_parser</exec_depend> | ||
|
||
<test_depend>ament_copyright</test_depend> | ||
<test_depend>ament_flake8</test_depend> | ||
<test_depend>ament_pep257</test_depend> | ||
<test_depend>python3-pytest</test_depend> | ||
|
||
<export> | ||
<build_type>ament_python</build_type> | ||
</export> | ||
</package> |
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,52 @@ | ||
# Copyright 2018 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. | ||
|
||
from enum import Enum | ||
|
||
|
||
class InterfaceType(Enum): | ||
UNKNOWN = 0 | ||
MESSAGE = 1 | ||
SERVICE = 2 | ||
|
||
|
||
def convert_to_idl( | ||
package_dir, package_name, interface_file, output_dir, | ||
interface_type=InterfaceType.UNKNOWN | ||
): | ||
print('convert_to_idl', interface_file) | ||
# TODO use plugin approach rather than hard coded alternatives | ||
if interface_file.suffix == '.idl': | ||
assert interface_type != InterfaceType.UNKNOWN, \ | ||
'.idl files must be passed explicitly as a message or service file' | ||
# just pass through for now | ||
# TODO support e.g. multiple entities in a single input file? | ||
return (interface_type, interface_file) | ||
|
||
if interface_file.suffix == '.msg': | ||
assert interface_type in (InterfaceType.UNKNOWN, InterfaceType.MESSAGE) | ||
from rosidl_adapter.msg import convert_msg_to_idl | ||
return (InterfaceType.MESSAGE, convert_msg_to_idl( | ||
package_dir, package_name, interface_file, | ||
output_dir / package_name / 'msg')) | ||
|
||
if interface_file.suffix == '.srv': | ||
assert interface_type in (InterfaceType.UNKNOWN, InterfaceType.SERVICE) | ||
from rosidl_adapter.srv import convert_srv_to_idl | ||
return (InterfaceType.SERVICE, convert_srv_to_idl( | ||
package_dir, package_name, interface_file, | ||
output_dir / package_name / 'srv')) | ||
|
||
# unknown / unhandled for now | ||
return (InterfaceType.UNKNOWN, interface_file) |
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,19 @@ | ||
# Copyright 2018 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 sys | ||
|
||
from rosidl_adapter.main import main | ||
|
||
sys.exit(main()) | ||
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,83 @@ | ||
# Copyright 2018 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 argparse | ||
import os | ||
import pathlib | ||
import sys | ||
|
||
|
||
from rosidl_adapter import convert_to_idl | ||
from rosidl_adapter import InterfaceType | ||
|
||
|
||
def main(argv=sys.argv[1:]): | ||
parser = argparse.ArgumentParser( | ||
description='Convert interface files to .idl') | ||
parser.add_argument( | ||
'--package-dir', required=True, | ||
help='The base directory of the package') | ||
parser.add_argument( | ||
'--package-name', required=True, | ||
help='The name of the package') | ||
parser.add_argument( | ||
'--message-files', nargs='*', | ||
help='The message files to convert to .idl') | ||
parser.add_argument( | ||
'--service-files', nargs='*', | ||
help='The service files to convert to .idl') | ||
parser.add_argument( | ||
'--interface-files', nargs='*', | ||
help='The interface files to convert to .idl') | ||
parser.add_argument( | ||
'--output-dir', required=True, | ||
help='The base directory to create .idl files in') | ||
parser.add_argument( | ||
'--output-messages-file', required=True, | ||
help='The output file containing the absolute paths to the message ' | ||
'.idl files') | ||
parser.add_argument( | ||
'--output-services-file', required=True, | ||
help='The output file containing the absolute paths to the service ' | ||
'.idl files') | ||
args = parser.parse_args(argv) | ||
output_dir = pathlib.Path(args.output_dir) | ||
|
||
message_files = [] | ||
service_files = [] | ||
for interface_file in args.interface_files: | ||
interface_file = pathlib.Path(interface_file) | ||
|
||
interface_type, idl_file = convert_to_idl( | ||
args.package_dir, args.package_name, interface_file, | ||
output_dir) | ||
if interface_type == InterfaceType.MESSAGE: | ||
message_files.append(idl_file) | ||
elif interface_type == InterfaceType.SERVICE: | ||
service_files.append(idl_file) | ||
elif interface_type == InterfaceType.UNKNOWN: | ||
raise RuntimeError( | ||
'Unsupported interface file format: {interface_file}' | ||
.format_map(locals())) | ||
else: | ||
assert False | ||
|
||
os.makedirs(os.path.dirname(args.output_messages_file), exist_ok=True) | ||
with open(args.output_messages_file, 'w') as h: | ||
for message_file in message_files: | ||
h.write('{message_file}\n'.format_map(locals())) | ||
os.makedirs(os.path.dirname(args.output_services_file), exist_ok=True) | ||
with open(args.output_services_file, 'w') as h: | ||
for service_file in service_files: | ||
h.write('{service_file}\n'.format_map(locals())) |
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,81 @@ | ||
# Copyright 2018 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. | ||
|
||
from rosidl_adapter.msg.parser import parse_message_string | ||
from rosidl_adapter.resource import expand_template | ||
|
||
|
||
def convert_msg_to_idl(package_dir, package_name, input_file, output_dir): | ||
assert input_file.suffix == '.msg' | ||
|
||
print('Reading input file: {input_file}'.format_map(locals())) | ||
content = input_file.read_text(encoding='utf-8') | ||
msg = parse_message_string(package_name, input_file.stem, content) | ||
|
||
output_file = output_dir / input_file.with_suffix('.idl').name | ||
print('Writing output file: {output_file}'.format_map(locals())) | ||
data = { | ||
'pkg_name': package_name, | ||
'relative_input_file': input_file.absolute().relative_to(package_dir), | ||
'msg': msg, | ||
'get_idl_type': get_idl_type, | ||
'get_include_file': get_include_file, | ||
} | ||
expand_template('msg.idl.em', data, output_file) | ||
return output_file | ||
|
||
|
||
MSG_TYPE_TO_IDL = { | ||
'bool': 'boolean', | ||
'byte': 'octet', | ||
'char': 'char', | ||
'int8': 'int8', | ||
'uint8': 'uint8', | ||
'int16': 'int16', | ||
'uint16': 'uint16', | ||
'int32': 'int32', | ||
'uint32': 'uint32', | ||
'int64': 'int64', | ||
'uint64': 'uint64', | ||
'float32': 'float', | ||
'float64': 'double', | ||
'string': 'string', | ||
} | ||
|
||
|
||
def get_include_file(base_type): | ||
if base_type.is_primitive_type(): | ||
return None | ||
return '{base_type.pkg_name}/msg/{base_type.type}.idl'.format_map(locals()) | ||
|
||
|
||
def get_idl_type(type_): | ||
if isinstance(type_, str): | ||
identifier = MSG_TYPE_TO_IDL[type_] | ||
elif type_.is_primitive_type(): | ||
identifier = MSG_TYPE_TO_IDL[type_.type] | ||
else: | ||
identifier = '{type_.pkg_name}::msg::{type_.type}' \ | ||
.format_map(locals()) | ||
|
||
if isinstance(type_, str) or not type_.is_array: | ||
return identifier | ||
|
||
if type_.is_fixed_size_array(): | ||
return '{identifier}[{type_.array_size}]'.format_map(locals()) | ||
|
||
if not type_.is_upper_bound: | ||
return 'sequence<{identifier}>'.format_map(locals()) | ||
|
||
return 'sequence<{identifier}, {type_.array_size}>'.format_map(locals()) |
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,50 @@ | ||
# Copyright 2018 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 argparse | ||
import pathlib | ||
import sys | ||
|
||
from catkin_pkg.package import package_exists_at | ||
from catkin_pkg.package import parse_package | ||
|
||
from rosidl_adapter.msg import convert_msg_to_idl | ||
|
||
|
||
def main(argv=sys.argv[1:]): | ||
parser = argparse.ArgumentParser( | ||
description='Convert .msg files to .idl') | ||
parser.add_argument( | ||
'interface_files', nargs='+', | ||
help='The interface files to convert') | ||
args = parser.parse_args(argv) | ||
|
||
for interface_file in args.interface_files: | ||
interface_file = pathlib.Path(interface_file) | ||
package_dir = interface_file.parent.absolute() | ||
while ( | ||
len(package_dir.parents) and | ||
not package_exists_at(str(package_dir)) | ||
): | ||
package_dir = package_dir.parent | ||
if not package_dir.parents: | ||
print( | ||
"Could not find package for '{interface_file}'" | ||
.format_map(locals()), file=sys.stderr) | ||
continue | ||
warnings = [] | ||
pkg = parse_package(package_dir, warnings=warnings) | ||
|
||
convert_msg_to_idl( | ||
package_dir, pkg.name, interface_file, interface_file.parent) |
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.
Does this need to be an entry point to work on windows?
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.
It doesn't since it is invoked with
python -m rosidl_adapter
.