Skip to content

Commit

Permalink
Fix up generate script
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Carroll <[email protected]>
  • Loading branch information
mjcarroll committed Feb 6, 2024
1 parent cf54236 commit 4fc843f
Showing 1 changed file with 25 additions and 52 deletions.
77 changes: 25 additions & 52 deletions tools/gz_msgs_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,15 @@ def main(argv=sys.argv[1:]):
help='Flag to indicate if C++ bindings should be generated',
action='store_true')
parser.add_argument(
'--generate-ruby',
help='Flag to indicate if Ruby bindings should be generated',
action='store_true')
parser.add_argument(
'--generate-ignition',
help='Flag to indicate if ignition/ headers should be generated',
'--generate-python',
help='Flag to indicate if Python bindings should be generated',
action='store_true')
parser.add_argument(
'--output-cpp-path',
help='The basepath of the generated C++ files')
parser.add_argument(
'--output-ruby-path',
help='The basepath of the generated C++ files')
'--output-python-path',
help='The basepath of the generated Python files')
parser.add_argument(
'--proto-path',
required=True,
Expand All @@ -58,23 +54,36 @@ def main(argv=sys.argv[1:]):
required=True,
help='The location of the template files',
action='append')
parser.add_argument(
'--dependency-proto-descs',
nargs='*',
help='The location of proto descriptor files these messages depend on')
parser.add_argument(
'--dllexport-decl',
help='The DLL visibility macro to use, if not set, no macro will be used')
args = parser.parse_args(argv)

for input_file in args.input_path:
# First generate the base cpp and ruby files
# First generate the base cpp files
cmd = [args.protoc_exec]

for pp in args.proto_path:
cmd += [f'--proto_path={pp}']
for path in args.proto_path:
cmd += [f'--proto_path={path}']

if args.generate_cpp:
cmd += [f'--plugin=protoc-gen-ignmsgs={args.gz_generator_bin}']
cmd += [f'--cpp_out=dllexport_decl=GZ_MSGS_VISIBLE:{args.output_cpp_path}']
cmd += [f'--ignmsgs_out={args.output_cpp_path}']
if args.generate_ruby:
cmd += [f'--ruby_out=dllexport_decl=GZ_MSGS_VISIBLE:{args.output_ruby_path}']
cmd += [f'--plugin=protoc-gen-gzmsgs={args.gz_generator_bin}']
if args.dllexport_decl:
cmd += [f'--cpp_out=dllexport_decl={args.dllexport_decl}:{args.output_cpp_path}']
else:
cmd += [f'--cpp_out={args.output_cpp_path}']

cmd += [f'--gzmsgs_out={args.output_cpp_path}']
if args.generate_python:
cmd += [f'--python_out={args.output_python_path}']
cmd += [input_file]

os.makedirs(args.output_cpp_path, exist_ok=True)

try:
subprocess.check_call(cmd)
except subprocess.CalledProcessError as e:
Expand All @@ -90,7 +99,6 @@ def main(argv=sys.argv[1:]):
continue

detail_proto_file = proto_file.split(os.sep)

detail_proto_dir = detail_proto_file[:-1]
detail_proto_dir.append('details')
detail_proto_dir = os.path.join(*detail_proto_dir)
Expand All @@ -117,40 +125,5 @@ def main(argv=sys.argv[1:]):
print(f'Failed to manipulate gz-msgs headers: {e}')
sys.exit(-1)


if args.generate_ignition:
ignition_header_dir = os.path.join(args.output_cpp_path, 'ignition', 'msgs')
ignition_header = proto_file.split(os.sep)
ignition_header[0] = 'ignition'

proto_name = ignition_header[2]

ignition_header = os.path.join(*ignition_header)
ignition_header = os.path.join(args.output_cpp_path, ignition_header + ".pb.h")

os.makedirs(os.path.join(args.output_cpp_path, ignition_header_dir),
exist_ok=True)

with open(ignition_header, 'w') as f:
f.write('''/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* 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.
*
*/
''')
f.write(f'#include <gz/msgs/{proto_name}.pb.h>\n')
f.write('#include <ignition/msgs/config.hh>\n')

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

0 comments on commit 4fc843f

Please sign in to comment.