Conan: Retrieve dependency package directory

Created on 8 May 2017  路  5Comments  路  Source: conan-io/conan

Suppose there are two packages, A and B.
B depends on A and B's build script requires A's package_folder.

How can I retrive A's package_folder in B's conanfile.py?

question

Most helpful comment

Hi @xylosper

You can access it through the deps_cpp_info field:

def build(self):
       pkg_folder = self.deps_cpp_info["PkgA"].rootpath
       # you can access the same way other properties, like include_paths, libs, etc

Also, maybe there are some other ways to avoid explicit requirement of the folder. E.g., package A can define environment variable PATH in its package_info() method, to point to its package folder, so dependent packages on A will automatically have it set in the PATH, and thus binaries for example can be found.

All 5 comments

Hi @xylosper

You can access it through the deps_cpp_info field:

def build(self):
       pkg_folder = self.deps_cpp_info["PkgA"].rootpath
       # you can access the same way other properties, like include_paths, libs, etc

Also, maybe there are some other ways to avoid explicit requirement of the folder. E.g., package A can define environment variable PATH in its package_info() method, to point to its package folder, so dependent packages on A will automatically have it set in the PATH, and thus binaries for example can be found.

Oh, thank you!

No worries :)

@memsharded It seems I have rootpath instead of root_path.

dir(self.deps_cpp_info['cppunit'])

I get

['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'bin_paths', 'bindirs', 'build_paths', 'builddirs', 'cflags', 'cppflags', 'defines', 'exelinkflags', 'include_paths', 'includedirs', 'lib_paths', 'libdirs', 'libs', 'res_paths', 'resdirs', 'rootpath', 'sharedlinkflags', 'sysroot']

Hi @vhuber

Thanks very much for noticing, that was a type, indeed, the field is rootpath. I have corrected it here in the issue, and submitted an issue to the docs repo: https://github.com/conan-io/docs/issues/209, so it is better documented.

Was this page helpful?
0 / 5 - 0 ratings