I am trying to achieve VS downward compatibility by using the new feature in package info.
I have the following method:
def enable_visual_studio_downward_compatibility(conanfile):
if conanfile.settings.compiler == "Visual Studio" and conanfile.settings.compiler.version == "16":
for version in ("15", "14"):
compatible_pkg = conanfile.info.clone()
compatible_pkg.settings.compiler.version = version
conanfile.compatible_packages.append(compatible_pkg)
if conanfile.settings.compiler == "Visual Studio" and conanfile.settings.compiler.version == "15":
for version in ("14"):
compatible_pkg = conanfile.info.clone()
compatible_pkg.settings.compiler.version = version
conanfile.compatible_packages.append(compatible_pkg)
And the package uses:
def package_id(self):
enable_visual_studio_downward_compatibility(self)
From my understanding and reading the documentation, this is the right way to enable compatibility.
However, when a VS2019 consumer tries to consume a VS2015 package, I get the following error:
ERROR: package/version@user/stable: Error in package_id() method, line 53
enable_visual_studio_downward_compatibility(self)
while calling 'enable_visual_studio_downward_compatibility', line 8
compatible_pkg = conanfile.info.clone()
ConanException: 'minor_mode' is not a known package_id_mode
Is this a bug or am I doing something wrong here? (I am using Conan 1.22.2)
Hmhm I don't get it I created a conan test with that scenario, and that runs just fine.
# -*- coding: utf-8 -*-
import unittest
from conans.test.utils.tools import TestClient
def create_profile(client, name, vs_version):
client.run("profile new {}".format(name))
client.run("profile update settings.os=Windows {}".format(name))
client.run("profile update settings.os_build=Windows {}".format(name))
client.run("profile update settings.arch=x86_64 {}".format(name))
client.run("profile update settings.arch_build=x86_64 {}".format(name))
client.run('profile update settings.compiler="Visual Studio" {}'.format(name))
client.run("profile update settings.compiler.runtime=MD {}".format(name))
client.run("profile update settings.compiler.version={} {}".format(vs_version, name))
test_id_conanfile = """
from conans import ConanFile
def enable_visual_studio_downward_compatibility(conanfile):
if conanfile.settings.compiler == "Visual Studio" and conanfile.settings.compiler.version == "16":
for version in ("15", "14"):
compatible_pkg = conanfile.info.clone()
compatible_pkg.settings.compiler.version = version
conanfile.compatible_packages.append(compatible_pkg)
if conanfile.settings.compiler == "Visual Studio" and conanfile.settings.compiler.version == "15":
for version in ("14"):
compatible_pkg = conanfile.info.clone()
compatible_pkg.settings.compiler.version = version
conanfile.compatible_packages.append(compatible_pkg)
class TestID(ConanFile):
name = "test_id"
version = "0.1.0"
settings = "os", "arch", "compiler"
def package_id(self):
enable_visual_studio_downward_compatibility(self)
"""
consume_id_conanfile = """
from conans import ConanFile
class ConsumeID(ConanFile):
name = "consume_id"
version = "0.1.0"
settings = "os", "arch", "compiler"
requires = "test_id/0.1.0@user/channel"
"""
class CompatiblePackageTest(unittest.TestCase):
def test_compatible(self):
client = TestClient()
create_profile(client, "x86_64_vs2015", "14")
create_profile(client, "x86_64_vs2019", "16")
client.save({"test_id/conanfile.py": test_id_conanfile})
client.save({"consume_id/conanfile.py": consume_id_conanfile})
client.run("create -pr x86_64_vs2015 test_id test_id/0.1.0@user/channel")
client.run("create -pr x86_64_vs2019 consume_id consume_id/0.1.0@user/channel")
Any ideas are highly appreciated!
Hi! I'm having a look at this and implementing a test myself and it also works... Are you getting this error with the recipes you provide in the test too? You get the error using the command line but not running the test?
The error "ConanException: 'minor_mode' is not a known package_id_mode" is raised from the constructor of RequirementInfo or PythonRequireInfo. Right now we are capturing a too broad block:
try:
getattr(self, default_package_id_mode)()
except AttributeError:
raise ConanException("'%s' is not a known package_id_mode" % default_package_id_mode)
it will fail with the same error if the method minor_mode does not exist or if it raises an exception of the same type when executed (notice the invocation after getattr(): ()). We should differentiate both errors.
Meanwhile, can you modify the Conan sources? if not, I can provide you a branch with the required changes so you can pip install git+mybranch to test it. The idea is to check where the error comes from by printing the traceback.
More questions: are playing with the package_id_mode of the requirements? doing anything special in the package_id methods of your graph?
No, I am not doing in anything special with the package_ids, just the function mentioned above to ensure the VS compatibility. (though in my case, the function is provided by a python_requires but I don't think that's the problem).
I observe the behavior on my local machine, so I am free to modify the conan sources and test out something.
There was a fix in https://github.com/conan-io/conan/pull/6563/files (already merged), that produced exactly the same minor_mode error, related to the build_id. Seems that this could be the same reason, this is why running from develop works.
Can you try it with the develop branch, @KerstinKeller?
You can use pip install git+https://github.com/conan-io/conan.git@develop to install that branch directly from Github
Perfect, it does work on the develop branch 馃憤
Will you be cherry picking this for a 1.22.4?
Much better, it will go for 1.22.3 :wink:
One more quick question: I tested on the develop branch, and the above described error was gone, however it seemed to have introduced a new "regression":
ERROR: package/0.6.1@user/stable: Error in source() method, line 26
tools.patch(patch_file=self.patch_file, base_path=self.name + "-" + self.version)
TypeError: apply() got an unexpected keyword argument 'fuzz'
So I wonder: what's the status of "develop": should it be stable or might it contain errors / regressions? If it's not stable, then please ignore this comment, otherwise please take a look.
I switched now to the release/1.22.3 and everything looks good there.
develop should be as stable as possible and if the CI is green it should always be a _release candidate_, so if something is failing we need to fix it.
We are using a patch-ng library, it is listed in the requirements.txt file. Both, develop and release/1.22.3 list the same dependency (patch-ng==1.17.2) and the fuzz argument to the apply() function was added time ago (https://github.com/conan-io/python-patch-ng/commit/bfbdbdcad9d278ccc4cbd3ec6f0c06457ddfa01c).
Can you run pip freeze and check the version you have of patch-ng?
Thanks a lot!
Yeah you are right, there was something wrong with the dependencies. I reinstalled the dev branch and that works fine now. Sorry about that.
Perfect!