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

add BUILD_TESTING=OFF to presets if tools.build:skip_test #11935

Conversation

memsharded
Copy link
Member

@memsharded memsharded commented Aug 23, 2022

Changelog: Feature: Add BUILD_TESTING=OFF to CMakeToolchain presets if tools.build:skip_test.
Docs: conan-io/docs#2713

Close #11905

@memsharded memsharded added this to the 1.52 milestone Aug 23, 2022
@memsharded memsharded requested a review from jcar87 August 23, 2022 08:31
@jcar87
Copy link
Contributor

jcar87 commented Aug 23, 2022

This looks good but I have a question!
tools.build:skip_test is documented as:

Do not execute CMake.test() and Meson.test() when enabled

In this PR, we would be a going a step beyond that - and potentially not building tests at all (depending on whether or not the projects use BUILD_TESTING to control the building of the tests.

This can be convenient as on some projects this can save considerable compilation time, but on the other hand in some projects the tests are the first attempt at linking things that consume the library and it can serve as an early way of catching linking issues. Although it could be argued that is the purpose of the test_package anyway.

@memsharded
Copy link
Member Author

Yes, I would say that the expected behavior of the Conan integrations, regarding skip_test is to avoid building them too, if they are not going to be ran anyway. I think the docs can be updated to reflect this. As always, this is only the default, and projects listening to BUILD_TESTING should behave correctly for both True and False values, and can define themselves in the recipe a different logic to tc.cache_variables["BUILD_TESTING"] = xxxx if they want to, and that will be respected.

Copy link
Contributor

@franramirez688 franramirez688 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this is the expected behavior, and the user will save time whenever he does not want to run all the tests.

@franramirez688 franramirez688 merged commit dcf243a into conan-io:develop Aug 23, 2022
@memsharded memsharded deleted the feature/cmaketoolchain_build_testing branch August 23, 2022 16:24
if cmake_make_program:
cmake_make_program = cmake_make_program.replace("\\", "/")
cache_variables["CMAKE_MAKE_PROGRAM"] = cmake_make_program

if "CMAKE_POLICY_DEFAULT_CMP0091" not in cache_variables:
cache_variables["CMAKE_POLICY_DEFAULT_CMP0091"] = "NEW"

if "BUILD_TESTING" not in cache_variables:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about CMakeToolchain.variables? Is it a possible scenario, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It sounds like CMakeToolchain.variables should be for user variables, while everything that is a CMake built-in, should be to cache_variables otherwise there is a risk that the variables will not have enough priority. @jcar87 wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say that's a good approximation!

I can find widespread evidence on GitHub that BUILD_TESTING is treated as a cache variable by projects:

  1. For example here by calling option()

  2. It will also be a cache variable if the user provides it via -DBUILD_TESTING=ON/OFF - in this case, the user's preference will take precedence and be respected regardless of whether we define it as a cache_variable or the project sets an option() -

So I think the way it currently is in this PR is the safest and least likely to have side effects - especially if there's any chance projects define or reference BUILD_TESTING before the first call to project() (have found examples here and here)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, lets recommend that in the docs then 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not in the opposite of using cached_variables, but still, users are free to use both and it will have a different behavior, depending the usage.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but if we explicitly say it in the docs, they should use each one for the documented cases, so they will not be "free" to use them invariantly for all cases.

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

Successfully merging this pull request may close these issues.

[question] Why does test_requires is installed when not testing?
4 participants