colcon-core icon indicating copy to clipboard operation
colcon-core copied to clipboard

why does colcon build test packages even if -DBUILD_TESTING=OFF is passed

Open razr opened this issue 3 years ago • 4 comments

I'd like to skip building gtest_vendor and friends, so I do:

wruser@a39833e76266:/work/build/ros2/ros2_ws$ colcon build --merge-install --cmake-force-configure --cmake-args -DBUILD_TESTING=OFF --packages-up-to ament_cmake_gen_version_h
Starting >>> ament_package
Starting >>> gtest_vendor
Finished <<< gtest_vendor [0.45s]
Finished <<< ament_package [1.02s]
Starting >>> ament_cmake_core
Finished <<< ament_cmake_core [0.46s]
Starting >>> ament_cmake_python
Finished <<< ament_cmake_python [0.46s]
Starting >>> ament_cmake_test
Finished <<< ament_cmake_test [0.94s]
Starting >>> ament_cmake_gtest
Finished <<< ament_cmake_gtest [0.47s]
Starting >>> ament_cmake_gen_version_h
Finished <<< ament_cmake_gen_version_h [0.48s]

Summary: 7 packages finished [5.06s]

If I explicitly remove test_depend from the package.xml, it works as I expect

  <!-- <test_depend>ament_cmake_gtest</test_depend> -->
wruser@a39833e76266:/work/build/ros2/ros2_ws$ colcon build --merge-install --cmake-force-configure --cmake-args -DBUILD_TESTING=OFF --packages-up-to ament_cmake_gen_version_h
Starting >>> ament_package
Finished <<< ament_package [1.03s]
Starting >>> ament_cmake_core
Finished <<< ament_cmake_core [0.61s]
Starting >>> ament_cmake_gen_version_h
Finished <<< ament_cmake_gen_version_h [0.95s]

Summary: 3 packages finished [3.77s]

Did I miss something?

razr avatar Oct 02 '22 12:10 razr

Setting -DBUILD_TESTING=OFF would prevent CMake from building anything inside:

if (BUILD_TESTING)
   # Testing code
endif()

colcon build is a utility to help you build your package in your workspace in order, using information purely from package.xml, it won't consider anything passed by the cmake-args (and it doesn't make sense to).

You should be able to use --packages-skip ament_cmake_test ament_cmake_gtest to achieve what you want.

I'm not sure if there is a colcon flag that skips all "test_depend" dependencies without explicitly listing them, but if there isn't one that would sound like a good addition to colcon-core to me.

ijnek avatar Nov 01 '22 01:11 ijnek

I'm not sure if there is a colcon flag that skips all "test_depend" dependencies without explicitly listing them, but if there isn't one that would sound like a good addition to colcon-core to me.

Colcon's package discovery crushes down test depends to be build depends currently; it would be a pretty major design shift for colcon to begin recognizing tests more explicitly.

mikepurvis avatar Nov 01 '22 02:11 mikepurvis

Colcon's package discovery crushes down test depends to be build depends currently; it would be a pretty major design shift for colcon to begin recognizing tests more explicitly.

I'm not sure this is accurate. Part of the issue is that not all package formats support discriminating between dependency types at all, and some just lack consistency in how to do it (looking at you, Python).

For example, for packages which use package.xml, the test dependencies are already enumerated separately. The issue is that the build verb implicitly considers all enumerated dependencies, regardless of type, to be build-time dependencies of the package: https://github.com/colcon/colcon-core/blob/64f06cf523cf211934ee608d0c986774b5997349/colcon_core/package_descriptor.py#L74-L75

cottsay avatar Dec 19 '22 23:12 cottsay

a colcon flag that skips all "test_depend" dependencies without explicitly listing them

@ijnek I think this is exactly what I was looking for. Another way might be to prepend

if (BUILD_TESTING)
# CMakeLists content of the test package
endif()

to all test packages?

razr avatar Dec 20 '22 10:12 razr