[bug] order of configuration options not preserved in all cases
Describe the bug
Environment details:
$ conan --version
Conan version 2.13.0
$ lsb_release -d
Description: Ubuntu 22.04.5 LTS
Description:
The order of [conf] options isn't always preserved. Example:
$ cat .conan2/profiles/mold-with-test-options
...
[conf]
&:tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/toolchains/mold.cmake
tools.build:skip_test=true
&:tools.build:skip_test=false
$ conan profile show -pr:a mold-with-test-options
Host profile:
...
[conf]
&:tools.build:skip_test=false
&:tools.cmake.cmaketoolchain:user_toolchain=['/home/me/.conan2/profiles/toolchains/mold.cmake']
tools.build:skip_test=true
As a result, the root project's tests aren't built, I think because tools.build:skip_test=true comes after &:tools.build:skip_test=false and overrides it.
(Note that the "resolved" order given by conan profile show indeed applies to the actual build and is not merely just for display.)
However, this works:
$ cat .conan2/profiles/mold-with-test-options
...
[conf]
tools.build:skip_test=true
&:tools.build:skip_test=false
&:tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/toolchains/mold.cmake
$ conan profile show -pr:a mold-with-test-options
Host profile:
...
[conf]
tools.build:skip_test=true
&:tools.build:skip_test=false
&:tools.cmake.cmaketoolchain:user_toolchain=['/home/me/.conan2/profiles/toolchains/mold.cmake']
And this works, too:
$ cat .conan2/profiles/mold-with-test-options
...
[conf]
tools.build:skip_test=true
&:tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/toolchains/mold.cmake
&:tools.build:skip_test=false
$ conan profile show -pr:a mold-with-test-options
Host profile:
...
[conf]
tools.build:skip_test=true
&:tools.build:skip_test=false
&:tools.cmake.cmaketoolchain:user_toolchain=['/home/me/.conan2/profiles/toolchains/mold.cmake']
The same issue seems to exist when supplying the configuration options on the command line. Example:
$ conan profile show -pr:a no-mold -c "&:tools.cmake.cmaketoolchain:user_toolchain=['/home/me/.conan2/profiles/toolchains/mold.cmake']" -c tools.build:skip_test=true -c "&:tools.build:skip_test=false"
Host profile:
...
[conf]
&:tools.build:skip_test=false
&:tools.cmake.cmaketoolchain:user_toolchain=['/home/me/repos/.conan2/profiles/toolchains/mold.cmake']
tools.build:skip_test=true
How to reproduce it
The simplest way is to just run conan profile show using a profile that has no [conf] section, and with the 3 different options provided on the command line, much like the last example I provided. It doesn't seem to matter whether the toolchain file exists:
$ conan profile show -pr:a default -c tools.build:skip_test=true -c "&:tools.cmake.cmaketoolchain:user_toolchain=['foo.cmake']" -c "&:tools.build:skip_test=false"
Host profile:
...
[conf]
tools.build:skip_test=true
&:tools.build:skip_test=false
&:tools.cmake.cmaketoolchain:user_toolchain=['foo.cmake']
$ conan profile show -pr:a default -c "&:tools.cmake.cmaketoolchain:user_toolchain=['foo.cmake']" -c tools.build:skip_test=true -c "&:tools.build:skip_test=false"
Host profile:
...
[conf]
&:tools.build:skip_test=false
&:tools.cmake.cmaketoolchain:user_toolchain=['foo.cmake']
tools.build:skip_test=true
Hi @wuziq
Thanks for your feedback.
This would be expected and by design, though it is true that it is not clearly documented.
The profiles sections when using patterns such as &:some=value are grouped by patterns in order of appearance.
That means that:
&:tools.cmake.cmaketoolchain:user_toolchain+={{profile_dir}}/toolchains/mold.cmake
tools.build:skip_test=true
&:tools.build:skip_test=false
is discouraged, all confs starting with & should be grouped in consecutive lines.
The examples in https://docs.conan.io/2/reference/config_files/profiles.html always put the patterns in this way, but I agree this is not enough, and it will be better to put it explicitly how profiles should group patterns.
I am moving this to the docs repo to document this properly, thanks again!
What if certain options are contained in the profile, but others are provided on the command line?
For example, what if the cmake toolchain is provided in the profile, but the skip_test options are provided on the command line? How can the grouping be enforced in that case?
For example, what if the cmake toolchain is provided in the profile, but the skip_test options are provided on the command line? How can the grouping be enforced in that case?
In general, by keeping the same ordering everywhere. As the order matters, it is recommended that in general the profiles define first the global matching values (without a pattern), and then the ones with the pattern.
In general, by keeping the same ordering everywhere. As the order matters, it is recommended that in general the profiles define first the global matching values (without a pattern), and then the ones with the pattern.
Is it unreasonable or incorrect to use a pattern globally, and to therefore have that pattern in a profile?
Maybe more specifically, how might we achieve the following?
- Always apply a toolchain to only the root project
- Sometimes skip tests for upstream dependencies without skipping tests for the root project
We'd like to be able to do this for both workflows:
-
conan install+conan build -
conan create