Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
razr opened this issue Oct 2, 2022 · 4 comments
Open

Comments

@razr
Copy link

razr commented Oct 2, 2022

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?

@ijnek
Copy link
Contributor

ijnek commented Nov 1, 2022

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.

@mikepurvis
Copy link
Contributor

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.

@cottsay
Copy link
Member

cottsay commented Dec 19, 2022

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:

if categories is None:
categories = self.dependencies.keys()

@razr
Copy link
Author

razr commented Dec 20, 2022

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants