How to use conan_info() to define complex compatibility setting
The manual giving one example of using 'Any', which will allow any single setting to be compatible. The other example looks like
def conan_info(self):
v = self.settings.compiler.version
if self.settings.compiler == "gcc" and (v == "4.8" or v == "4.9"):
self.info.settings.compiler.version = "4.8-9"
What's the exact syntax of the version variable? Does it work if I say 4.8-6.2?
If we want to push a little more, how can I define compatibility of a few settings combined together? It's more like a function of is_compatible(self.setting, self.option) which gives true or false for a given set of settings. And if we have such power, then it's possible that a set of package built with different setting/option will match for a given requirement, then how does conan choose? Is there a way in requirement, we can put more restriction on setting of individual packages?
The values that you can put into self.info fields are strings, anything you want to write there, it is possible, as they are not constrained, as normal self.settings or self.options.
Lets put an example: you are building a C library with gcc 4.8 and you know that it is ABI compatible with gcc up to 6.2. Also, you are building it in "release" mode, i.e. optimized, but it is no problem to link against it from a project using debug mode. Those settings are actually necessary to build the package, so they are declared in the recipe, used in the build() method, then changed in:
def conan_info(self):
if self.settings.compiler.version .... : # There is a Version class, can be used for comparison
self.info.settings.compiler.version = "4.8-6.2"
self.info.settings.build_type = "Any"
The hash, or binary package ID, is computed hashing the strings of all the settings and options. So, if using:
gcc 4.8, Release => "gcc", "4.8-6.2", "Any" => Hash1
Now, you or someone else, references the same package, with other settings:
gcc 4.9, Debug=> "gcc", "4.8-6.2", "Any" => Hash1
They will get exactly the same Hash1, and then retrieve and use the same package binary, the one that was build with gcc 4.8.
If someone uses it with another, out of range compiler version:
gcc 6.3, Debug=> "gcc", "6.3", "Any" => Hash2
They will get a new Hash2, and as the binary is not existing, will build it with its current settings from source.
Please tell me if this clarifies your question, or need further explanation. Thanks!
Thanks for the detailed explanation!
So basically the actual build setting get broadened and hashed into a id, and later if somebody request it with a different compatible setting, the same broadened setting's hash can be produced and there is a match. But if we have multiple setting of package matching a requirement, how does conan decide to use which one? Also can package require more specific version of another package (e.g. with some specific setting)?
This is a very relevant question, yet to be properly addressed, and carefully explained or documented. The UI was improved in the latest versions, but still not properly documented. Especially the hashing of requirements, which by default has a semver policy, but it cannot be the best for some cases.
Lets prioritize this, for next 0.19 release.
There is now a detailed how-to in the docs for this issue: http://docs.conan.io/en/latest/howtos/define_abi_compatibility.html
We have done some improvements also in 0.19:
- Rename it to
package_id() - Support for
Versionpatch, pre, build - Completed
modeshelper methods
Feedback on it welcome (in the docs repo)