Skip to content

Commit

Permalink
Create package whitelist from package.xml
Browse files Browse the repository at this point in the history
The prior mechanism to generate an ignore/include list was to
use a static file at the workspace root. This doesn't play very
well with our build system so instead use package.xml. Any
<build_depend> package will now be included in the ros1_bridge
build.

This is done using a simple python script to parse package.xml
which is then called by cmake (stdout of the script is the list).
We then feed that list into a modified filter_packages() function
that takes a list of include/ignore packages rather than using
the static list.
  • Loading branch information
jprestwo committed Jun 19, 2024
1 parent 4ea6aec commit ca24a3c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 57 deletions.
19 changes: 16 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ cmake_minimum_required(VERSION 3.5)

project(ros1_bridge)

execute_process(
COMMAND python3 bin/ros1_bridge_generate_package_list
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
OUTPUT_VARIABLE pkg_include_list
)

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
Expand Down Expand Up @@ -56,7 +62,10 @@ find_package(xmlrpcpp REQUIRED)
# find ROS 1 packages with messages / services
include(cmake/find_ros1_interface_packages.cmake)
find_ros1_interface_packages(ros1_message_packages)
filter_packages("ros1_message_packages")
filter_packages(
PKG_LIST "ros1_message_packages"
INCLUDE_PKGS ${pkg_include_list}
)

set(prefixed_ros1_message_packages "")
foreach(ros1_message_package ${ros1_message_packages})
Expand Down Expand Up @@ -141,7 +150,10 @@ list(APPEND generated_files "${generated_path}/get_mappings.cpp")

# generate per interface compilation units to keep the memory usage low
ament_index_get_resources(ros2_interface_packages "rosidl_interfaces")
filter_packages("ros2_interface_packages")
filter_packages(
PKG_LIST "ros2_interface_packages"
INCLUDE_PKGS ${pkg_include_list}
)

# actionlib_msgs is deprecated, but we will quiet the warning until the bridge has support for
# ROS actions: https://github.com/ros2/design/issues/195
Expand Down Expand Up @@ -170,6 +182,7 @@ endforeach()

set(target_dependencies
"bin/ros1_bridge_generate_factories"
"bin/ros1_bridge_generate_package_list"
"resource/get_factory.cpp.em"
"resource/get_mappings.cpp.em"
"resource/interface_factories.cpp.em"
Expand All @@ -184,7 +197,7 @@ add_custom_command(
COMMAND Python3::Interpreter
ARGS bin/ros1_bridge_generate_factories
--output-path "${generated_path}" --template-dir resource
--pkg-includes '${BRIDGE_INCLUDE_PKGS}'
--pkg-includes '${pkg_include_list}'
--pkg-ignores '${BRIDGE_IGNORE_PKGS}'
DEPENDS ${target_dependencies}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
Expand Down
16 changes: 16 additions & 0 deletions bin/ros1_bridge_generate_package_list
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env python3

import sys
from catkin_pkg.package import parse_package

def main(argv=sys.argv[1:]):
pkg = parse_package("package.xml")
packages = []

for depend in pkg["build_depends"]:
packages.append(depend.name)

print(';'.join(packages), end='')

if __name__ == '__main__':
sys.exit(main())
61 changes: 9 additions & 52 deletions cmake/find_ignore_include_lists.cmake
Original file line number Diff line number Diff line change
@@ -1,55 +1,12 @@
# Module/Package resp. message ignores and includes
#
# Finds lists of ROS modules/packages resp. messages that shall
# be included resp. ignored by the ROS bridge according to the
# following rules:
# - Include lists over ignore lists. I.e. if an include list is
# present, the ignore list will be ... well, ignored.)
function(filter_packages)
set(options "")
set(oneValueArgs PKG_LIST)
set(multiValueArgs INCLUDE_PKGS IGNORE_PKGS)

set(USE_PKG_IGNORE OFF)
set(USE_PKG_INCLUDE OFF)
set(USE_MSG_IGNORE OFF)
set(USE_MSG_INCLUDE OFF)
cmake_parse_arguments(BRIDGE "${options}"
"${oneValueArgs}" "${multiValueArgs}" "${ARGN}")

set(BRIDGE_IGNORE_PKGS "")
set(BRIDGE_IGNORE_MSGS "")
set(BRIDGE_INCLUDE_PKGS "")
set(BRIDGE_INCLUDE_MSGS "")

# File with packages to ignore/include in ROS 1 Bridge
set(BRIDGE_PACKAGE_IGNORE "${CMAKE_SOURCE_DIR}/../../../BridgePackageIgnore.List")
set(BRIDGE_PACKAGE_INCLUDE "${CMAKE_SOURCE_DIR}/../../../BridgePackageInclude.List")

# File with messages to ignore/include in ROS 1 Bridge
set(BRIDGE_MSG_IGNORE "${CMAKE_SOURCE_DIR}/../../../BridgePackageIgnore.List")
set(BRIDGE_MSG_INCLUDE "${CMAKE_SOURCE_DIR}/../../../BridgePackageInclude.List")

if(EXISTS "${BRIDGE_PACKAGE_INCLUDE}")
set(USE_PKG_INCLUDE ON)
else() # EXISTS "${BRIDGE_PACKAGE_INCLUDE}"
if(EXISTS "${BRIDGE_PACKAGE_IGNORE}")
set(USE_PKG_IGNORE ON)
endif() # EXISTS "${BRIDGE_PACKAGE_IGNORE}"
endif() # EXISTS "${BRIDGE_PACKAGE_INCLUDE}"

if(${USE_PKG_INCLUDE})
FILE(READ "${BRIDGE_PACKAGE_INCLUDE}" BRIDGE_INCLUDE_PKGS)
STRING(REGEX REPLACE ";" "\\\\;" BRIDGE_INCLUDE_PKGS "${BRIDGE_INCLUDE_PKGS}")
STRING(REGEX REPLACE "\n" ";" BRIDGE_INCLUDE_PKGS "${BRIDGE_INCLUDE_PKGS}")
list(REMOVE_DUPLICATES BRIDGE_INCLUDE_PKGS)
message(STATUS "Found package include list, including: ${BRIDGE_INCLUDE_PKGS}")
endif() # USE_PKG_INCLUDE

if(${USE_PKG_IGNORE})
FILE(READ "${BRIDGE_PACKAGE_IGNORE}" BRIDGE_IGNORE_PKGS)
STRING(REGEX REPLACE ";" "\\\\;" BRIDGE_IGNORE_PKGS "${BRIDGE_IGNORE_PKGS}")
STRING(REGEX REPLACE "\n" ";" BRIDGE_IGNORE_PKGS "${BRIDGE_IGNORE_PKGS}")
list(REMOVE_DUPLICATES BRIDGE_IGNORE_PKGS)
message(STATUS "Found package ignore list, ignoring: ${BRIDGE_IGNORE_PKGS}")
endif() # USE_PKG_IGNORE

function(filter_packages pkg_list)
set(ros2_packages ${${pkg_list}})
set(ros2_packages ${${BRIDGE_PKG_LIST}})
if(BRIDGE_INCLUDE_PKGS)
foreach(pkg ${ros2_packages})
if(NOT ${pkg} IN_LIST BRIDGE_INCLUDE_PKGS)
Expand All @@ -63,6 +20,6 @@ function(filter_packages pkg_list)
endif(${pkg} IN_LIST BRIDGE_IGNORE_PKGS)
endforeach()
endif(BRIDGE_INCLUDE_PKGS)
set(${pkg_list} "${ros2_packages}" PARENT_SCOPE)

set(${BRIDGE_PKG_LIST} "${ros2_packages}" PARENT_SCOPE)
endfunction(filter_packages ros2_packages)
3 changes: 1 addition & 2 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<build_depend>rmw_implementation_cmake</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>xmlrpcpp</build_depend>
<build_depend>geometry_msgs</build_depend>

<buildtool_export_depend>pkg-config</buildtool_export_depend>

Expand All @@ -59,8 +60,6 @@
<test_depend>ros2run</test_depend>
<test_depend>sensor_msgs</test_depend>

<group_depend>rosidl_interface_packages</group_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
Expand Down

0 comments on commit ca24a3c

Please sign in to comment.