conan icon indicating copy to clipboard operation
conan copied to clipboard

[question] Change package_id() function to consider package_id of one dependency

Open MTomBosch opened this issue 1 year ago • 1 comments

What is your question?

Hello, we are using Conan 1 and are using the semver_direct_mode for package_id computation.

Now we have a scenario where for one particular dependency I want to consider also its package_id when computing my own package_id.

Do you have somewhere a code snippet that shows how to accomplish my above goal?

Thank you

Have you read the CONTRIBUTING guide?

  • [X] I've read the CONTRIBUTING guide

MTomBosch avatar May 10 '24 16:05 MTomBosch

Hi @MTomBosch

I guess you are looking for something like this?:

def package_id(self):
     self.info.requires["my_dep"].xxx_mode()

Where the modes in https://docs.conan.io/1/creating_packages/define_abi_compatibility.html#versioning-schema can tell you which ones do take into account the package_id of the dependency, in this case full_package_mode or recipe_revision_mode.

Is this what you are looking for?

memsharded avatar May 10 '24 17:05 memsharded

Partially. Your solution I was already aware of and sorry for not being clear enough that I would not like to use such a solution.

Using "full package mode" or "recipe revision mode" for that one particular dependency would create too many new package ids for the consumer which I would like to avoid. I would only like to react on changes to the package id (and the semver of the dependent packages). Is that posssible at all?

MTomBosch avatar May 14 '24 06:05 MTomBosch

Using "full package mode" or "recipe revision mode" for that one particular dependency would create too many new package ids for the consumer which I would like to avoid. I would only like to react on changes to the package id (and the semver of the dependent packages). Is that posssible at all?

Why? full_package_mode only defines name, version, user, channel and package_id effect. Why this would have more effect on the package_id and create too many different binaries? How is it possible that the package_id of the dependency affects my current binary but the version doesn't?

In any case, yes, you should be able to set individual fields like:

def package_id(self):
    self.info.requires["pkg"].package_id = self.dependencies["pkg"].pref.package_id

Or you could use one of the predefined moedes like full_package_mode and invalidate with =None the fields that you want to ignore.

memsharded avatar May 14 '24 07:05 memsharded

The default package id mode that we use is semver_direct_mode and it does not compute the pkg id based on user and channel but full_package_mode does and this would lead to more package ids. But maybe that is even acceptable, I will check this.

And thank you for the other proposal.

MTomBosch avatar May 14 '24 08:05 MTomBosch

@memsharded Sorry to bother you again. Using the full_package_mode it is working. Now I wanted to try your proposal with the "self.dependencies" but I am getting following error message:

AttributeError: 'PackageReference' object has no attribute 'package_id'

MTomBosch avatar May 15 '24 12:05 MTomBosch

Yes, sorry, my bad, in Conan 1.X it is called PackageReference.id, while in Conan 2.X it is PkgReference.package_id. So please try using .id instead.

memsharded avatar May 15 '24 21:05 memsharded