[question] build_requires in lockfiles
Hi,
This question is related to this one : https://github.com/conan-io/conan/issues/8268 In a nutshell, i use CONAN_RUN_TESTS to be able to run "conan create" by specifying whether the build_requires should be populated with gtest. It seems to cause problem when working with lockfiles.
For this example i have the same graph as this page : https://docs.conan.io/en/latest/versioning/lockfiles/build_order.html
The issue is that i lose the gtest dependency when deriving the lockfile for app1 :
1 ) Create base lockfile for app1
conan lock create conanfile.py
--lockfile=liba_base.lock
--lockfile-out=app1_base.lock
--base
-e CONAN_RUN_TESTS=1
Build requirements
gtest/1.8.1@bincrafters/stable from 'conan-center' - Cache <== OK, present in app1_base.lock
2 ) Derive base lockfile
conan lock create
--reference=app1/1.0.1@foo/stable
--lockfile=app1_base.lock
--lockfile-out=app1_Release.lock
-s build_type=Release
-e CONAN_RUN_TESTS=1
Build requirements
none <== thus no gtest in app1_Release.lock
(note that app1/1.0.1@foo/stable was created with CONAN_RUN_TESTS=1 so gtest appeared in the build_requires)
3 ) This leads to the error :
conan install app1/1.0.1@foo/stable
--lockfile=app1_Release.lock
--lockfile-out=locks/app1_Release_updated.lock
--build missing
ERROR: Build-require 'gtest' cannot be found in lockfile
4 ) I noticed that by using command without --reference, i still get the gtest dependency in the lockfile
conan lock create conanfile.py
--lockfile=app1_base.lock
--lockfile-out=app1_Release.lock
-s build_type=Release
-e CONAN_RUN_TESTS=1
Build requirements
gtest/1.8.1@bincrafters/stable from 'conan-center' - Cache <== OK, present in app1_Release.lock
But surprinsingly i still get the same error :
conan install app1_src/ --lockfile=app1_Release.lock
--lockfile-out=app1_Release_updated.lock
--build=missing
ERROR: Build-require 'gtest' cannot be found in lockfile
Even if gtest appears in the lockfile.
Could you help me clarify this a bit ? I wonder if i am shooting myself in the foot by using this technique with CONAN_RUN_TESTS. Thanks !
- [X] I've read the CONTRIBUTING guide.
Hi @GPages
I think the important concept to highlight here is that conan lock create captures a lockfile from a expanded dependency graph. If the build require is not there at the moment of creating the lock, it will not be possible to be used later.
If you need the build requires later, you need to guarantee that the build_requires are there, using the necessary graph --build policy.
So something like this:
# use policy --build=missing will expand build requires as well
$ conan lock create conanfile.py ... --base --build=missing
# The derived lockfile needs to expand and capture the build_requires as well
$ conan lock create --reference=app1/1.0.1@foo/stable -s build_type=Release --build=missing
# Check the build_requires is there in the .lock file
Please try that, using --build=missing in the lock commands as well, and let us know. Thanks!
It fixed the issue, and now my entire CI automated building of the dependency graph is working well. Great, thanks a lot ! I might have missed it in the documentation but if it is not present it might be worth adding a note about the use of build=missing with the conan lock create command.
But anyway, thank you for your help 👍