Skip to content

Commit ec46e6a

Browse files
committed
Extend ament_cmake_python_test to support combined msg & python builds
Signed-off-by: R Kent James <[email protected]>
1 parent b52b39e commit ec46e6a

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

ament_cmake_python/cmake/ament_python_install_registered_packages.cmake

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,16 @@ macro(_ament_cmake_python_copy_build_files package_name)
7373

7474
add_custom_target(${_sync_target} DEPENDS ${_PACKAGE_DIRS} ${_SETUP_CFG})
7575

76+
# Force any interface packages to be at the front of the list to prevent overwrite of
77+
# python package __init__.py files
78+
foreach(_dir IN LISTS _PACKAGE_DIRS)
79+
string(FIND "${_dir}" "rosidl_generator_py" SUBSTRING_INDEX)
80+
if(NOT SUBSTRING_INDEX EQUAL -1)
81+
list(REMOVE_ITEM _PACKAGE_DIRS ${_dir})
82+
list(PREPEND _PACKAGE_DIRS ${_dir})
83+
endif()
84+
endforeach()
85+
7686
foreach(_dir IN LISTS _PACKAGE_DIRS)
7787
add_custom_command(TARGET ${_sync_target}
7888
COMMAND ${CMAKE_COMMAND} -E copy_directory

ament_cmake_python_test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if(BUILD_TESTING)
2626
ament_add_pytest_test(${_test_name} ${_test_path}
2727
APPEND_ENV PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}
2828
ENV SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} PYTHON_INSTALL_DIR=${PYTHON_INSTALL_DIR} PYEGG_VERSION=py${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}
29-
TIMEOUT 60
29+
TIMEOUT 360
3030
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
3131
)
3232
endforeach()

ament_cmake_python_test/package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<build_depend>ament_cmake_python</build_depend>
1515

1616
<test_depend>python-jinja2</test_depend>
17+
<test_depend>rosidl_cmake</test_depend>
1718

1819
<buildtool_export_depend>ament_cmake_core</buildtool_export_depend>
1920

ament_cmake_python_test/test/build_with_colcon.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@
3434
'name': 'python_package',
3535
'description': 'Package with python code',
3636
},
37+
{
38+
'name': 'msg_package',
39+
'description': 'Package with only msg files',
40+
'has_msg': True,
41+
'has_python': False,
42+
},
3743
{
3844
'name': 'python_package_symlink',
3945
'description': 'Package with python code, installed with symlink in build',
@@ -64,12 +70,6 @@
6470
'description': 'Package with python code',
6571
'scripts_destination': 'lib/python_package_with_scripts',
6672
},
67-
{
68-
'name': 'msg_package',
69-
'description': 'Package with only msg files',
70-
'has_msg': True,
71-
'has_python': False,
72-
},
7373
]
7474

7575

@@ -80,9 +80,25 @@ def test_from_template():
8080
packages_dir = PWD / 'packages'
8181
shutil.rmtree(packages_dir, ignore_errors=True)
8282

83-
# Create test packages from template
84-
template_dir = SOURCE_DIR / 'test' / 'pkg_template'
83+
# extend the tests to include combinations of msg and python
84+
additional_options = TESTS_OPTIONS.copy()
8585
for options in TESTS_OPTIONS:
86+
if options['name'].startswith('python_package'):
87+
msg_options = options.copy()
88+
msg_options['name'] += '_with_msg'
89+
msg_options['description'] += 'and msg files'
90+
msg_options['has_msg'] = True
91+
additional_options.append(msg_options)
92+
elif options['name'].startswith('msg_package'):
93+
py_options = options.copy()
94+
py_options['name'] += '_with_python_before'
95+
py_options['description'] += ' and python code before msg'
96+
py_options['has_python_before'] = True
97+
additional_options.append(py_options)
98+
99+
template_dir = SOURCE_DIR / 'test' / 'pkg_template'
100+
# Create test packages from template
101+
for options in additional_options:
86102
options = DEFAULT_OPTIONS | options
87103
print(f"Generating package {options['name']}")
88104
print(f" options: {options}")
@@ -96,7 +112,7 @@ def test_from_template():
96112
if options['has_msg']:
97113
shutil.copytree(template_dir / 'msg', package_dir / 'msg')
98114

99-
if options['has_python']:
115+
if options['has_python'] or options['has_python_before']:
100116
ignore_patterns = shutil.ignore_patterns('*.jinja')
101117
shutil.copytree(template_dir / 'package_directory', package_dir / package_subdir, ignore=ignore_patterns)
102118
template = Template(Path.read_text(template_dir / 'package_directory' / '__init__.py.jinja'))
@@ -161,7 +177,7 @@ def do_test_package(package_name, options):
161177
assert install_path.exists(), f"install path does not exist for {package_name}: {install_path}"
162178
assert (install_path / '__init__.py').exists(), f"missing __init__.py in {install_path}"
163179

164-
if options['has_python']:
180+
if options['has_python'] or options['has_python_before']:
165181
assert Path.read_text (install_path / '__init__.py').startswith(f"# This is {package_name}"), \
166182
f"__init__.py should be from {package_name} python package"
167183

0 commit comments

Comments
 (0)