conan-io / conan

Conan - The open-source C and C++ package manager
https://conan.io
MIT License
8.29k stars 982 forks source link

[question] private requirements during cross-building not in conanbuildinfo #17349

Closed naggerx closed 1 day ago

naggerx commented 2 days ago

What is your question?

I have to enable cross-building for a project. I'm running into strange behavior regarding private dependencies.

class Ours(ConanFile):

    def requirements(self):
        self.requires("liba/1.0@user/channel", private = True)
        self.requires("libb/1.0@user/channel")

    def build(self):
        print(self.deps_cpp_info["liba"].rootpath)  # not working when using --profile:build
        print(self.deps_cpp_info["libb"].rootpath)  # works everytime

When installing & building with one profile everything works:

conan install .. --profile profileA
#conanbuildinfo.txt contains infos about liba and libb
conan build ..

But when using a build profile, even when its the same as the host profile:

conan install .. --profile:host profileA --profile:build profileA
#conanbuildinfo.txt contains only infos about llibb

Is this expected behavior? Is there a workaround, without changing the "private=True"?

Have you read the CONTRIBUTING guide?

memsharded commented 2 days ago

Hi @naggerx

Thanks for your question. Yes, I am afraid this is a known issue of private=True in legacy Conan 1.

The self.deps_cpp_info is legacy, even within Conan 1.X. Please try to use the self.dependencies interface to access information from dependencies.

naggerx commented 1 day ago

It's really unexpected that self.dependencies is available in build() when using 'conan create', but not when using 'conan install' and 'conan build'. And since I use install&build I have to find another way to transfer the infos from generate() to build()

memsharded commented 1 day ago

The recommended way, both in Conan 1 and Conan 2 is: