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 30329e5
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 62 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 ${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 ${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())
76 changes: 17 additions & 59 deletions cmake/find_ignore_include_lists.cmake
Original file line number Diff line number Diff line change
@@ -1,68 +1,26 @@
# 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 IGNORE)

set(USE_PKG_IGNORE OFF)
set(USE_PKG_INCLUDE OFF)
set(USE_MSG_IGNORE OFF)
set(USE_MSG_INCLUDE OFF)
cmake_parse_arguments(FILTER_PACKAGES "${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}})
if(BRIDGE_INCLUDE_PKGS)
set(ros2_packages ${${FILTER_PACKAGES_PKG_LIST}})
cmake_print_variables(ros2_packages)
if(FILTER_PACKAGES_INCLUDE)
foreach(pkg ${ros2_packages})
if(NOT ${pkg} IN_LIST BRIDGE_INCLUDE_PKGS)
if(NOT ${pkg} IN_LIST FILTER_PACKAGES_INCLUDE)
list(REMOVE_ITEM ros2_packages ${pkg})
endif(NOT ${pkg} IN_LIST BRIDGE_INCLUDE_PKGS)
endif(NOT ${pkg} IN_LIST FILTER_PACKAGES_INCLUDE)
endforeach()
elseif(BRIDGE_IGNORE_PKGS)
elseif(FILTER_PACKAGES_IGNORE)
foreach(pkg ${ros2_packages})
if(${pkg} IN_LIST BRIDGE_IGNORE_PKGS)
if(${pkg} IN_LIST FILTER_PACKAGES_IGNORE)
list(REMOVE_ITEM ros2_packages ${pkg})
endif(${pkg} IN_LIST BRIDGE_IGNORE_PKGS)
endif(${pkg} IN_LIST FILTER_PACKAGES_IGNORE)
endforeach()
endif(BRIDGE_INCLUDE_PKGS)
set(${pkg_list} "${ros2_packages}" PARENT_SCOPE)
endif(FILTER_PACKAGES_INCLUDE)

set(${FILTER_PACKAGES_PKG_LIST} "${ros2_packages}" PARENT_SCOPE)
endfunction(filter_packages ros2_packages)

0 comments on commit 30329e5

Please sign in to comment.