Repository: open-dynamic-robot-initiative/master-board (language: python)

Issue:
Fetching Catch2 is a problem for packaging or when using a container.
For testing Catch2 is fetch here:
https://github.com/open-dynamic-robot-initiative/master-board/blob/e95c1c4b6879a4512d9060dd5e6ed2899757086f/sdk/master_board_sdk/CMakeLists.txt#L154

For packaging purposes, or when using a container having to fetch is a real pain.

I did some tests, and the difference between Ubuntu 22.04 and 24.04 is only the header's filename.
Thus I prepared a PR to detect the version and modify the inclusion and remove this fetch.


Discussion / hints:

Fix patch:
diff --git a/.github/workflows/ros-humble-ci.yml b/.github/workflows/ros-humble-ci.yml
new file mode 100644
index 00000000..f559a874
--- /dev/null
+++ b/.github/workflows/ros-humble-ci.yml
@@ -0,0 +1,40 @@
+# This config uses industrial_ci (https://github.com/ros-industrial/industrial_ci.git).
+# For troubleshooting, see readme (https://github.com/ros-industrial/industrial_ci/blob/master/README.rst)
+
+name: CI - Linux ROS Humble
+
+# This determines when this workflow is run
+on: [push, pull_request] # on all pushes and PRs
+
+jobs:
+  CI:
+    strategy:
+      matrix:
+        env:
+          - {ROS_DISTRO: humble, BUILDER: colcon}
+    env:
+      CCACHE_DIR: /github/home/.ccache             # Enable ccache
+      # The following is a work-around for ROS tooling in conjunction with jrl-cmakemodules:
+      #  - catkin_make_isolated has issues with Industrial-CI right now
+      #  - colcon cannot find example-robot-data's python bindings due to ROS1 workspace integration hooks
+      #  - catkin_tools correctly finds example-robot-data in the upstream_ws, but does not execute the 'run_tests' target
+      #    as catkin-tools performs tests as '--catkin-make-args' instead of '--make-args' as colcon and catkin_make_isolated
+      # The work-around is thus to use catkin_tools for building and sourcing, and to manually specify execution of the test
+      # target after completion of the regular test target. The output of this step does affect the output of the CI process.
+      # Note, this does not affect projects that do not have pure CMake projects in their upstream_ws.
+      BUILDER: catkin_tools
+      AFTER_RUN_TARGET_TEST: 'ici_with_unset_variables source /root/target_ws/install/setup.bash && cd /root/target_ws/build/master_board_sdk && make test'
+      IMMEDIATE_TEST_OUTPUT: 1
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          submodules: recursive
+      # This step will fetch/store the directory used by ccache before/after the ci run
+      - uses: actions/cache@v4
+        with:
+          path: ${{ env.CCACHE_DIR }}
+          key: ccache-${{ matrix.env.ROS_DISTRO }}-${{ matrix.env.ROS_REPO }}
+      # Run industrial_ci
+      - uses: 'ros-industrial/industrial_ci@875c2aebfd634eebaa84dbe5198f2fdb4c5f1b7e'
+        env: ${{ matrix.env }}
diff --git a/.github/workflows/ros-ci.yml b/.github/workflows/ros-rolling-ci.yml
similarity index 98%
rename from .github/workflows/ros-ci.yml
rename to .github/workflows/ros-rolling-ci.yml
index f5650b93..54d411d6 100644
--- a/.github/workflows/ros-ci.yml
+++ b/.github/workflows/ros-rolling-ci.yml
@@ -1,7 +1,7 @@
 # This config uses industrial_ci (https://github.com/ros-industrial/industrial_ci.git).
 # For troubleshooting, see readme (https://github.com/ros-industrial/industrial_ci/blob/master/README.rst)
 
-name: CI - Linux via ROS
+name: CI - Linux ROS Rolling
 
 # This determines when this workflow is run
 on: [push, pull_request] # on all pushes and PRs
diff --git a/sdk/master_board_sdk/CMakeLists.txt b/sdk/master_board_sdk/CMakeLists.txt
index 9ba917f6..33094116 100644
--- a/sdk/master_board_sdk/CMakeLists.txt
+++ b/sdk/master_board_sdk/CMakeLists.txt
@@ -150,19 +150,11 @@ install(TARGETS master_board_example_imu_data_collection DESTINATION bin)
 
 # --- UNIT TESTS -----------------------------------------------------------
 if(BUILD_TESTING)
-  find_package(Catch2 3.1 QUIET)
-  if(NOT Catch2_FOUND)
-    include(FetchContent)
-    FetchContent_Declare(
-      Catch2
-      GIT_REPOSITORY https://github.com/catchorg/Catch2.git
-      GIT_TAG v3.4.0)
-    FetchContent_MakeAvailable(Catch2)
-  endif()
+  find_package(Catch2)
+  add_definitions(-DFOUND_CATCH2_MAJOR_VERSION=${Catch2_VERSION_MAJOR})
   add_unit_test(test_protocol tests/test_protocol.cpp)
   target_link_libraries(test_protocol PRIVATE Catch2::Catch2WithMain)
 endif()
-
 # Allows Colcon to find non-Ament packages when using workspace underlays
 file(
   WRITE
diff --git a/sdk/master_board_sdk/package.xml b/sdk/master_board_sdk/package.xml
index c47286d4..b953ac6b 100644
--- a/sdk/master_board_sdk/package.xml
+++ b/sdk/master_board_sdk/package.xml
@@ -17,6 +17,8 @@
     <depend condition="$ROS_PYTHON_VERSION == 3">python3-numpy</depend>
     <depend condition="$ROS_PYTHON_VERSION == 3">libboost-python-dev</depend>
 
+    <test_depend>catch2</test_depend>
+    
     <depend>git</depend>
     <export>
       <build_type>cmake</build_type>


Test patch:
diff --git a/sdk/master_board_sdk/tests/test_protocol.cpp b/sdk/master_board_sdk/tests/test_protocol.cpp
index 71bae3d8..25f097e9 100644
--- a/sdk/master_board_sdk/tests/test_protocol.cpp
+++ b/sdk/master_board_sdk/tests/test_protocol.cpp
@@ -1,4 +1,14 @@
+#ifdef FOUND_CATCH2_MAJOR_VERSION
+#if (FOUND_CATCH2_MAJOR_VERSION == 2 )
+#include "catch2/catch.hpp"
+#elif (FOUND_CATCH2_MAJOR_VERSION == 3)
 #include "catch2/catch_all.hpp"
+#else
+#error "FOUND_CATCH_MAJOR_VERSION not supported"
+#endif
+#endif
+
+
 #include "master_board_sdk/protocol.h"
 #include <limits>