-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reduce repeated template parsing to speed up builds
* Separate writing arguments files from the builds of each generator or type support target. * Write all arguments files first, before generating files. * Generate all files for each IDL template at once, avoiding repeated template parsing.
- Loading branch information
Showing
36 changed files
with
730 additions
and
411 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
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,40 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import os | ||
import sys | ||
|
||
try: | ||
from rosidl_pycommon import generate_files_from_arguments_files | ||
except ImportError: | ||
# modifying sys.path and importing the Python package with the same | ||
# name as this script does not work on Windows | ||
rosidl_pycommon_root = os.path.dirname(os.path.dirname(__file__)) | ||
rosidl_pycommon_module = os.path.join( | ||
rosidl_pycommon_root, 'rosidl_pycommon', '__init__.py') | ||
if not os.path.exists(rosidl_pycommon_module): | ||
raise | ||
from importlib.machinery import SourceFileLoader | ||
|
||
loader = SourceFileLoader('rosidl_pycommon', rosidl_pycommon_module) | ||
rosidl_pycommon = loader.load_module() | ||
generate_files_from_arguments_files = rosidl_pycommon.generate_files_from_arguments_files | ||
|
||
|
||
def main(argv=sys.argv[1:]): | ||
parser = argparse.ArgumentParser( | ||
description='Generate the ROS interfaces.', | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter) | ||
parser.add_argument( | ||
'--generator-arguments-files', | ||
required=True, | ||
help='The location of the files containing the generator arguments') | ||
args = parser.parse_args(argv) | ||
|
||
print(args.generator_arguments_files) | ||
|
||
generate_files_from_arguments_files(args.generator_arguments_files) | ||
|
||
|
||
if __name__ == '__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
105 changes: 105 additions & 0 deletions
105
rosidl_cmake/cmake/rosidl_write_additional_context.cmake
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,105 @@ | ||
# Copyright 2023 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. | ||
|
||
# | ||
# Generate a JSON / YAML file containing additional context data for expanding | ||
# IDL templates | ||
# | ||
# | ||
# @public | ||
# | ||
function(rosidl_write_additional_context output_file) | ||
|
||
set(OPTIONAL_ONE_VALUE_KEYWORDS | ||
"DISABLE_DESCRIPTION_CODEGEN") | ||
set(OPTIONAL_MULTI_VALUE_KEYWORDS | ||
"TYPE_SUPPORTS") | ||
|
||
cmake_parse_arguments( | ||
ARG | ||
"" | ||
"${OPTIONAL_ONE_VALUE_KEYWORDS}" | ||
"${OPTIONAL_MULTI_VALUE_KEYWORDS}" | ||
${ARGN}) | ||
if(ARG_UNPARSED_ARGUMENTS) | ||
message(FATAL_ERROR "rosidl_write_additional_context() called with unused " | ||
"arguments: ${ARG_UNPARSED_ARGUMENTS}") | ||
endif() | ||
|
||
# create folder | ||
get_filename_component(output_path "${output_file}" PATH) | ||
file(MAKE_DIRECTORY "${output_path}") | ||
|
||
# open object | ||
file(WRITE "${output_file}" | ||
"{") | ||
|
||
set(first_element TRUE) | ||
|
||
# write string values | ||
foreach(one_value_argument ${OPTIONAL_ONE_VALUE_KEYWORDS}) | ||
if(DEFINED ARG_${one_value_argument}) | ||
# write conditional comma and mandatory newline | ||
if(NOT first_element) | ||
file(APPEND "${output_file}" ",") | ||
else() | ||
set(first_element FALSE) | ||
endif() | ||
file(APPEND "${output_file}" "\n") | ||
|
||
string(TOLOWER "${one_value_argument}" key) | ||
string(REPLACE "\\" "\\\\" value "${ARG_${one_value_argument}}") | ||
file(APPEND "${output_file}" | ||
" \"${key}\": \"${value}\"") | ||
endif() | ||
endforeach() | ||
|
||
# write array values | ||
foreach(multi_value_argument ${OPTIONAL_MULTI_VALUE_KEYWORDS}) | ||
if(ARG_${multi_value_argument}) | ||
# write conditional comma and mandatory newline and indentation | ||
if(NOT first_element) | ||
file(APPEND "${output_file}" ",") | ||
else() | ||
set(first_element FALSE) | ||
endif() | ||
file(APPEND "${output_file}" "\n") | ||
|
||
# write key, open array | ||
string(TOLOWER "${multi_value_argument}" key) | ||
file(APPEND "${output_file}" | ||
" \"${key}\": [\n") | ||
|
||
# write array values, last without trailing colon | ||
list(GET ARG_${multi_value_argument} -1 last_value) | ||
list(REMOVE_AT ARG_${multi_value_argument} -1) | ||
foreach(value ${ARG_${multi_value_argument}}) | ||
string(REPLACE "\\" "\\\\" value "${value}") | ||
file(APPEND "${output_file}" | ||
" \"${value}\",\n") | ||
endforeach() | ||
string(REPLACE "\\" "\\\\" last_value "${last_value}") | ||
file(APPEND "${output_file}" | ||
" \"${last_value}\"\n") | ||
|
||
# close array | ||
file(APPEND "${output_file}" | ||
" ]") | ||
endif() | ||
endforeach() | ||
|
||
# close object | ||
file(APPEND "${output_file}" | ||
"\n}\n") | ||
endfunction() |
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 was deleted.
Oops, something went wrong.
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
Oops, something went wrong.