Conan: [question] post_download_package hook

Created on 12 Aug 2020  路  8Comments  路  Source: conan-io/conan

Hi guys, I'm experimenting with the post_download_package hook and according to the documentation, it should support the conanfile parameter. The table there says that conanfile is available on download_package on the post stage.
Docs: https://docs.conan.io/en/latest/reference/hooks.html#function-parameters

But it is not present on the example code

def post_download_package(output, conanfile_path, reference, package_id, remote, **kwargs):
    output.info("conanfile_path=%s" % conanfile_path)
    output.info("reference=%s" % str(reference))
    output.info("package_id=%s" % package_id)
    output.info("remote.name=%s" % remote.name)

And if I add it, I get an error

def post_download_package(output, conan, conanfile_path, reference, package_id, remote, **kwargs):
post_download_package(): post_download_package() missing 1 required positional argument: 'conanfile'

Am I doing something wrong?
What I need is checking the content of some variables in the recipe after I download a package,

Thanks.

medium queue look into

All 8 comments

Hi! Indeed, there is a mismatch between the docs and the actual implementation. None of those hooks are receiving the conanfile argument even though after downloading the recipe Conan loads the recipe file.

Thanks for noticing!

Hi! I'm having a look to the sources and I find very difficult to pass the conanfile to some of those hooks, I think it is a bug in the documentation.

We can pass conanfile to post_download and pre/post_upload, but using it in more internal operations like pre/post_download_recipe or pre/post_download_package requires a big refactor.

Two questions:

  • Is hook post_download a good place to perform those operations?
  • Can I ask what kind of checks are you doing that requires the conanfile object? (It is always useful to know how you are using Conan and its features)

Thanks!

What is the difference between post_download and post_download_package?

What I'm doing is kind of a hack. We're integrating conan deeply into our build system, we moved almost all our third party dependencies to conan (eventually all of them will be provided by it) and now we're trying to package SDKs provided by YOCTO builds and use them as build requirements.
The issue with these SDKs is that they have a bunch of hard coded absolute paths that need to be patched after the SDK gets moved around. The YOCTO builds provides a script for this, but it doesn't play nicely with conan's workflow, since it has to be executed in the consuming PC and conan (AFAIK) does not provide a mechanism to modify packages after being downloaded.

What I'm doing right now is executing a post_download_package hook that check the name of the package and, if it is an SDK, it patches the relocation scrips to point to the new package folder and then executes the relocation.

This works, but in the recipe that packages the SDK I have a bunch of variables defined that I would like to access from the hook, so I don't have to define them in both places.

I found this post with people trying to package YOCTO SDKs if you need some more info on the subject https://github.com/conan-io/conan/issues/5059

Hi! Thanks for all the information.

We are currently investigating a new feature, package_install method (https://github.com/conan-io/conan/pull/7313), that will let the consumer modify the package after it is installed in the cache: package files are copied to a different folder (we need the package ones to remain immutable) and the recipe can define a function package_install() that will be executed over the files in that folder. It looks like exactly what you want to do.

Modifying files in the package folder is risky, I think Conan is not computing the checksum again in the conan upload command and you might upload these package with modified files without notice. Depending on your workflow this can be a problem.

Order of _download_ hooks is as follows (for the conan download command):

pre_download_recipe
post_download_recipe
pre_download_package
post_download_package
post_download

but for other commands that are downloading recipes/packages because the graph need them (i.e.: conan install) only the pre_download_recipe, post_download_recipe and pre_download_package and post_download_package are being executed.

Adding some arguments to some hooks might not be something desirable, I need to check with the team and we will come back to you soon (before 1.29).

Thanks for looking into this.
The checksum thing is not a problem for us since the devs do not have permissions to upload packages.

Fixed in https://github.com/conan-io/conan/pull/7968, will be released next Conan 1.31

After the refactor we did to the download it's been a piece of cake to add this feature 馃槂

Thanks guys!

Was this page helpful?
0 / 5 - 0 ratings