diff --git a/bazel_ros2_rules/ros2/resources/ros2bzl/scraping/metadata.py b/bazel_ros2_rules/ros2/resources/ros2bzl/scraping/metadata.py index 35993f6e..d715595f 100644 --- a/bazel_ros2_rules/ros2/resources/ros2bzl/scraping/metadata.py +++ b/bazel_ros2_rules/ros2/resources/ros2bzl/scraping/metadata.py @@ -1,10 +1,27 @@ import os import xml.etree.ElementTree as ET +# Remove elemets that have a condition attribute on ROS1 +def remove_ros1_elements(root): + ros1_condition_value = "$ROS_VERSION == 1" + elements_to_remove = [] + + for parent in root.iter(): + for child in list(parent): + if "condition" in child.attrib: + if child.get('condition') == ros1_condition_value : + elements_to_remove.append((parent, child)) + else : + child.attrib.pop("condition") + + for parent, child in elements_to_remove: + parent.remove(child) def parse_package_xml(path_to_package_xml): tree = ET.parse(path_to_package_xml) + remove_ros1_elements(tree.getroot()) + depends = set([ tag.text for tag in tree.findall('./depend') ]) diff --git a/bazel_ros2_rules/ros2/resources/ros2bzl/templates.py b/bazel_ros2_rules/ros2/resources/ros2bzl/templates.py index 115530e1..7948f95a 100644 --- a/bazel_ros2_rules/ros2/resources/ros2bzl/templates.py +++ b/bazel_ros2_rules/ros2/resources/ros2bzl/templates.py @@ -1,5 +1,6 @@ import os import pathlib +import glob from ros2bzl.resources import load_resource from ros2bzl.scraping.system import find_library_path @@ -108,6 +109,13 @@ def configure_package_cc_library( sandbox(find_library_path(library)) for library in metadata['plugin_libraries'] ) + # Add an exception for plotjuggler-ros, as it does not + # use pluginlib, and the manifest does not mention its plugins. + # The paths for the plugins are hardcoded in plotjuggler : + # https://github.com/facontidavide/PlotJuggler/blob/15dce41f598daed841bf2093aa10ebdf2aa1052f/plotjuggler_app/mainwindow.cpp#L560-L566 + if 'plotjuggler_ros' in target_name: + prefix = "_opt_ros_humble/lib/plotjuggler_ros/" + data.extend(glob.glob(prefix + "lib*.so")) # Prepare runfiles to support dynamic loading data.extend(library for library in libraries if library not in data) diff --git a/bazel_ros2_rules/ros2/resources/templates/ament_cmake_CMakeLists.txt.in b/bazel_ros2_rules/ros2/resources/templates/ament_cmake_CMakeLists.txt.in index 984039c7..e25fb533 100644 --- a/bazel_ros2_rules/ros2/resources/templates/ament_cmake_CMakeLists.txt.in +++ b/bazel_ros2_rules/ros2/resources/templates/ament_cmake_CMakeLists.txt.in @@ -13,6 +13,10 @@ if("@PACKAGE@" STREQUAL "rviz_ogre_vendor") set(CMAKE_FIND_LIBRARY_PREFIXES ";lib") endif() +if("@PACKAGE@" STREQUAL "plotjuggler") + find_package(Qt5 COMPONENTS Widgets Concurrent Svg REQUIRED) +endif() + find_package(@PACKAGE@ REQUIRED) file(WRITE empty.cc "") diff --git a/ros2_example_bazel_installed/WORKSPACE b/ros2_example_bazel_installed/WORKSPACE index eb32431b..7f201cb7 100644 --- a/ros2_example_bazel_installed/WORKSPACE +++ b/ros2_example_bazel_installed/WORKSPACE @@ -64,6 +64,8 @@ git_repository( # Please keep this list sorted ROS2_PACKAGES = [ + "plotjuggler", + "plotjuggler_ros", "action_msgs", "builtin_interfaces", "console_bridge_vendor", diff --git a/ros2_example_bazel_installed/ros2_example_apps/BUILD.bazel b/ros2_example_bazel_installed/ros2_example_apps/BUILD.bazel index 92183db5..106d6918 100644 --- a/ros2_example_bazel_installed/ros2_example_apps/BUILD.bazel +++ b/ros2_example_bazel_installed/ros2_example_apps/BUILD.bazel @@ -272,3 +272,21 @@ ros_cc_test( "@ros2//resources/rmw_isolation:rmw_isolation_cc", ], ) + +# This is a roll-up target to use plotjuggler with the required +# ROS plugins. Usage : +# bazel run //ros2_example_apps:plotjuggler +ros_py_binary( + name = "plotjuggler", + srcs = ["plotjuggler.py"], + data = [ + "@ros2//:plotjuggler_ros_cc", + "@ros2//:plotjuggler_ros_share", + "@ros2//:plotjuggler_ros_transitive_py", + ], + deps = [ + "//:ros_msgs_all_py", + "@bazel_tools//tools/python/runfiles", + "@ros2//:plotjuggler_plotjuggler", + ], +) diff --git a/ros2_example_bazel_installed/ros2_example_apps/plotjuggler.py b/ros2_example_bazel_installed/ros2_example_apps/plotjuggler.py new file mode 100644 index 00000000..134f1d11 --- /dev/null +++ b/ros2_example_bazel_installed/ros2_example_apps/plotjuggler.py @@ -0,0 +1,21 @@ +""" +Roll up script for plotjuggler with ROS. +""" + + +import os +import subprocess +from bazel_tools.tools.python.runfiles import runfiles + +def main(): + r = runfiles.Create() + binary_path = r.Rlocation("ros2/plotjuggler_plotjuggler") + + if not binary_path: + raise FileNotFoundError("Could not find plotjuggler binary") + + # Run the binary + subprocess.run(binary_path, check=True) + +if __name__ == "__main__": + main() diff --git a/ros2_example_bazel_installed/setup/install_prereqs.sh b/ros2_example_bazel_installed/setup/install_prereqs.sh index 2ab1b9d3..96c2ddc1 100755 --- a/ros2_example_bazel_installed/setup/install_prereqs.sh +++ b/ros2_example_bazel_installed/setup/install_prereqs.sh @@ -85,6 +85,7 @@ if [[ -z "${ROS2_DISTRO_PREFIX:-}" ]]; then apt install ros-humble-desktop apt install ros-humble-rmw-cyclonedds-cpp apt install ros-dev-tools + apt install ros-humble-plotjuggler-ros fi # Install Python dependencies diff --git a/ros2_example_bazel_installed/setup/prereq-rosdep-keys.txt b/ros2_example_bazel_installed/setup/prereq-rosdep-keys.txt index 895c17b0..5d747c42 100644 --- a/ros2_example_bazel_installed/setup/prereq-rosdep-keys.txt +++ b/ros2_example_bazel_installed/setup/prereq-rosdep-keys.txt @@ -1,4 +1,6 @@ assimp +binutils +boost bullet cmake cppcheck @@ -20,16 +22,23 @@ libpcl-all-dev libqt5-core libqt5-gui libqt5-opengl +libqt5-opengl-dev libqt5-svg +libqt5-svg-dev +libqt5-websockets-dev libqt5-widgets +libqt5x11extras5-dev libsqlite3-dev libx11-dev libxaw libxml2-utils libxrandr +libzmq3-dev libzstd-dev +lz4 opengl pkg-config +protobuf-dev pybind11-dev pydocstyle python3