From 68074ef7c8a31fe6683a4ebaa7cb8fa22704e7e7 Mon Sep 17 00:00:00 2001 From: memsharded Date: Fri, 2 Feb 2024 21:56:36 +0100 Subject: [PATCH 1/8] fix for msvc toolset version overflow --- conan/tools/cmake/toolchain/blocks.py | 3 ++- .../unittests/tools/cmake/test_cmaketoolchain.py | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/conan/tools/cmake/toolchain/blocks.py b/conan/tools/cmake/toolchain/blocks.py index 455cc5743c9..61663a08bf8 100644 --- a/conan/tools/cmake/toolchain/blocks.py +++ b/conan/tools/cmake/toolchain/blocks.py @@ -697,7 +697,8 @@ def get_toolset(generator, conanfile): compiler_update = str(settings.compiler.update) if compiler_update != "None": # It is full one(19.28), not generic 19.2X # The equivalent of compiler 19.26 is toolset 14.26 - toolset = "version=14.{}{}".format(compiler_version[-1], compiler_update) + compiler_ver = int(compiler_version[-1]) * 10 + int(compiler_update) + toolset = "version=14.{}".format(compiler_ver) else: toolset = msvc_version_to_toolset_version(compiler_version) elif compiler == "clang": diff --git a/conans/test/unittests/tools/cmake/test_cmaketoolchain.py b/conans/test/unittests/tools/cmake/test_cmaketoolchain.py index 98c514bb8e0..505261726ac 100644 --- a/conans/test/unittests/tools/cmake/test_cmaketoolchain.py +++ b/conans/test/unittests/tools/cmake/test_cmaketoolchain.py @@ -198,7 +198,7 @@ def conanfile_msvc(): c = ConanFile(None) c.settings = Settings({"os": ["Windows"], "compiler": {"msvc": {"version": ["193"], "cppstd": ["20"], - "update": [None]}}, + "update": ["ANY"]}}, "build_type": ["Release"], "arch": ["x86"]}) c.settings.build_type = "Release" @@ -223,6 +223,19 @@ def test_toolset(conanfile_msvc): assert 'CMAKE_CXX_STANDARD 20' in toolchain.content +def test_toolset_update_version(conanfile_msvc): + conanfile_msvc.settings.compiler.update = "8" + toolchain = CMakeToolchain(conanfile_msvc) + assert 'set(CMAKE_GENERATOR_TOOLSET "version=14.38" CACHE STRING "" FORCE)' in toolchain.content + + +def test_toolset_update_version_overflow(conanfile_msvc): + # https://github.com/conan-io/conan/issues/15583 + conanfile_msvc.settings.compiler.update = "10" + toolchain = CMakeToolchain(conanfile_msvc) + assert 'set(CMAKE_GENERATOR_TOOLSET "version=14.40" CACHE STRING "" FORCE)' in toolchain.content + + def test_toolset_x64(conanfile_msvc): # https://github.com/conan-io/conan/issues/11144 conanfile_msvc.conf.define("tools.cmake.cmaketoolchain:toolset_arch", "x64") From fb9bbe611e411de2174f53adddf9fd6397df9133 Mon Sep 17 00:00:00 2001 From: memsharded Date: Fri, 22 Mar 2024 15:38:41 +0100 Subject: [PATCH 2/8] review --- conan/tools/microsoft/visual.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/conan/tools/microsoft/visual.py b/conan/tools/microsoft/visual.py index 429e52dd62e..219c48357f0 100644 --- a/conan/tools/microsoft/visual.py +++ b/conan/tools/microsoft/visual.py @@ -137,7 +137,14 @@ def generate(self, scope="build"): "v144": "14.4"}.get(toolset_version) else: vs_version = vs_ide_version(conanfile) - vcvars_ver = _vcvars_vers(conanfile, compiler, vs_version) + if int(vs_version) <= 14: + vcvars_ver = None + else: + compiler_version = str(conanfile.settings.compiler.version) + compiler_update = conanfile.settings.get_safe("compiler.update", "") + # The equivalent of compiler 19.26 is toolset 14.26 + vcvars_ver = "14.{}{}".format(compiler_version[-1], compiler_update) + vcvarsarch = _vcvars_arch(conanfile) winsdk_version = conanfile.conf.get("tools.microsoft:winsdk_version", check_type=str) @@ -320,18 +327,6 @@ def _vcvars_arch(conanfile): return arch -def _vcvars_vers(conanfile, compiler, vs_version): - if int(vs_version) <= 14: - return None - - assert compiler == "msvc" - # Code similar to CMakeToolchain toolset one - compiler_version = str(conanfile.settings.compiler.version) - # The equivalent of compiler 192 is toolset 14.2 - vcvars_ver = "14.{}".format(compiler_version[-1]) - return vcvars_ver - - def is_msvc(conanfile, build_context=False): """ Validates if the current compiler is ``msvc``. From ebe0442f44c6368e25d4465b3031a5e84a1c568b Mon Sep 17 00:00:00 2001 From: memsharded Date: Fri, 22 Mar 2024 16:04:47 +0100 Subject: [PATCH 3/8] wip --- conan/internal/api/detect_api.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/conan/internal/api/detect_api.py b/conan/internal/api/detect_api.py index 7c7d6c3130d..1e5f2e63d54 100644 --- a/conan/internal/api/detect_api.py +++ b/conan/internal/api/detect_api.py @@ -383,11 +383,12 @@ def detect_default_compiler(): return None, None, None if platform.system() == "Windows": - version = _detect_vs_ide_version() - update = detect_msvc_update(version) - version = {"17": "193", "16": "192", "15": "191"}.get(str(version)) # Map to compiler - if version == "193" and update and int(update) >= 10: - version = "194" + ide_version = _detect_vs_ide_version() + version = {"17": "193", "16": "192", "15": "191"}.get(str(ide_version)) # Map to compiler + if ide_version == "17": + update = detect_msvc_update(version) # FIXME weird passing here the 193 compiler version + if update and int(update) >= 10: + version = "194" if version: return 'msvc', Version(version), None From 8839620d80020513abc3d9033d9df6420ebc3031 Mon Sep 17 00:00:00 2001 From: memsharded Date: Wed, 17 Apr 2024 19:01:40 +0200 Subject: [PATCH 4/8] compatibility --- conans/client/graph/compatibility.py | 43 +++++++++++++------ .../package_id/test_cache_compatibles.py | 42 ++++++++++++++++++ 2 files changed, 73 insertions(+), 12 deletions(-) diff --git a/conans/client/graph/compatibility.py b/conans/client/graph/compatibility.py index c72c4377c0a..8f476fbd041 100644 --- a/conans/client/graph/compatibility.py +++ b/conans/client/graph/compatibility.py @@ -30,26 +30,45 @@ def compatibility(conanfile): def cppstd_compat(conanfile): # It will try to find packages with all the cppstd versions extension_properties = getattr(conanfile, "extension_properties", {}) - if extension_properties.get("compatibility_cppstd") is False: - return [] compiler = conanfile.settings.get_safe("compiler") compiler_version = conanfile.settings.get_safe("compiler.version") cppstd = conanfile.settings.get_safe("compiler.cppstd") - if not compiler or not compiler_version or not cppstd: + if not compiler or not compiler_version: return [] base = dict(conanfile.settings.values_list) - cppstd_possible_values = supported_cppstd(conanfile) - if cppstd_possible_values is None: - conanfile.output.warning(f'No cppstd compatibility defined for compiler "{compiler}"') - return [] - ret = [] - for _cppstd in cppstd_possible_values: - if _cppstd is None or _cppstd == cppstd: + factors = [] # List of list, each sublist is a potential combination + if cppstd is not None and extension_properties.get("compatibility_cppstd") is not False: + cppstd_possible_values = supported_cppstd(conanfile) + if cppstd_possible_values is None: + conanfile.output.warning(f'No cppstd compatibility defined for compiler "{compiler}"') + else: + factors.append([{"compiler.cppstd": v} for v in cppstd_possible_values if v != cppstd]) + + if compiler == "msvc": + msvc_fallback = {"193": "194", "194": "193"}.get(compiler_version) + if msvc_fallback: + factors.append([{"compiler.version": msvc_fallback}]) + + conanfile.output.info(f"FACTORS {factors}") + combinations = [] + for factor in factors: + if not combinations: + combinations = factor continue + new_combinations = [] + for comb in combinations: + for f in factor: + comb = comb.copy() + comb.update(f) + new_combinations.append(comb) + combinations = new_combinations + + conanfile.output.info(f"COMbINATIONS {combinations}") + ret = [] + for comb in combinations: configuration = base.copy() - configuration["compiler.cppstd"] = _cppstd + configuration.update(comb) ret.append({"settings": [(k, v) for k, v in configuration.items()]}) - return ret """ diff --git a/conans/test/integration/package_id/test_cache_compatibles.py b/conans/test/integration/package_id/test_cache_compatibles.py index f98dd7fe628..3f2f1d091a5 100644 --- a/conans/test/integration/package_id/test_cache_compatibles.py +++ b/conans/test/integration/package_id/test_cache_compatibles.py @@ -377,6 +377,48 @@ def test_unnecessary_builds(self): c.run("install --requires=app/0.1 --build=missing") assert re.search(r"Skipped binaries(\s*)tool/0.1", c.out) + def test_msvc_194_fallback(self): + c = TestClient() + save(c.cache.default_profile_path, "") + c.save({"conanfile.py": GenConanfile("mylib", "1.0").with_settings("os", "arch", + "compiler", "build_type"), + "profile_build": "[settings]\nos=Windows\narch=x86_64"}) + + c.run("create . -s os=Windows -s arch=x86_64 -s build_type=Release " + "-s compiler=msvc " + "-s compiler.version=193 -s compiler.cppstd=17 " + "-s compiler.runtime=dynamic -pr:b=profile_build") + package_id1 = c.created_package_id("mylib/1.0") + + # Try to install with cppstd 14, it will find cppstd 17 as compatible + c.run("install --requires=mylib/1.0@ -s os=Windows -s arch=x86_64 -s build_type=Release " + "-s compiler=msvc " + "-s compiler.version=194 -s compiler.cppstd=14 " + "-s compiler.runtime=dynamic -pr:b=profile_build") + assert "mylib/1.0: Main binary package 'e340edd75790e7156c595edebd3d98b10a2e091e' missing."\ + f"Using compatible package '{package_id1}'" + + def test_msvc_194_forward(self): + c = TestClient() + save(c.cache.default_profile_path, "") + c.save({"conanfile.py": GenConanfile("mylib", "1.0").with_settings("os", "arch", + "compiler", "build_type"), + "profile_build": "[settings]\nos=Windows\narch=x86_64"}) + + c.run("create . -s os=Windows -s arch=x86_64 -s build_type=Release " + "-s compiler=msvc " + "-s compiler.version=194 -s compiler.cppstd=17 " + "-s compiler.runtime=dynamic -pr:b=profile_build") + package_id1 = c.created_package_id("mylib/1.0") + + # Try to install with cppstd 14, it will find cppstd 17 as compatible + c.run("install --requires=mylib/1.0@ -s os=Windows -s arch=x86_64 -s build_type=Release " + "-s compiler=msvc " + "-s compiler.version=193 -s compiler.cppstd=14 " + "-s compiler.runtime=dynamic -pr:b=profile_build") + assert "mylib/1.0: Main binary package 'e340edd75790e7156c595edebd3d98b10a2e091e' missing."\ + f"Using compatible package '{package_id1}'" + class TestErrorsCompatibility: """ when the plugin fails, we want a clear message and a helpful trace From 704b45451c9dab8e96f177eefea707c576de0b8b Mon Sep 17 00:00:00 2001 From: memsharded Date: Wed, 17 Apr 2024 19:34:48 +0200 Subject: [PATCH 5/8] compat only forward --- conans/client/graph/compatibility.py | 2 +- .../package_id/test_cache_compatibles.py | 21 ------------------- 2 files changed, 1 insertion(+), 22 deletions(-) diff --git a/conans/client/graph/compatibility.py b/conans/client/graph/compatibility.py index 8f476fbd041..817109abc42 100644 --- a/conans/client/graph/compatibility.py +++ b/conans/client/graph/compatibility.py @@ -45,7 +45,7 @@ def cppstd_compat(conanfile): factors.append([{"compiler.cppstd": v} for v in cppstd_possible_values if v != cppstd]) if compiler == "msvc": - msvc_fallback = {"193": "194", "194": "193"}.get(compiler_version) + msvc_fallback = {"194": "193"}.get(compiler_version) if msvc_fallback: factors.append([{"compiler.version": msvc_fallback}]) diff --git a/conans/test/integration/package_id/test_cache_compatibles.py b/conans/test/integration/package_id/test_cache_compatibles.py index 3f2f1d091a5..702b11e6d90 100644 --- a/conans/test/integration/package_id/test_cache_compatibles.py +++ b/conans/test/integration/package_id/test_cache_compatibles.py @@ -398,27 +398,6 @@ def test_msvc_194_fallback(self): assert "mylib/1.0: Main binary package 'e340edd75790e7156c595edebd3d98b10a2e091e' missing."\ f"Using compatible package '{package_id1}'" - def test_msvc_194_forward(self): - c = TestClient() - save(c.cache.default_profile_path, "") - c.save({"conanfile.py": GenConanfile("mylib", "1.0").with_settings("os", "arch", - "compiler", "build_type"), - "profile_build": "[settings]\nos=Windows\narch=x86_64"}) - - c.run("create . -s os=Windows -s arch=x86_64 -s build_type=Release " - "-s compiler=msvc " - "-s compiler.version=194 -s compiler.cppstd=17 " - "-s compiler.runtime=dynamic -pr:b=profile_build") - package_id1 = c.created_package_id("mylib/1.0") - - # Try to install with cppstd 14, it will find cppstd 17 as compatible - c.run("install --requires=mylib/1.0@ -s os=Windows -s arch=x86_64 -s build_type=Release " - "-s compiler=msvc " - "-s compiler.version=193 -s compiler.cppstd=14 " - "-s compiler.runtime=dynamic -pr:b=profile_build") - assert "mylib/1.0: Main binary package 'e340edd75790e7156c595edebd3d98b10a2e091e' missing."\ - f"Using compatible package '{package_id1}'" - class TestErrorsCompatibility: """ when the plugin fails, we want a clear message and a helpful trace From a56c6395d6b039184859726d37b854cd1ab84256 Mon Sep 17 00:00:00 2001 From: memsharded Date: Fri, 3 May 2024 12:06:26 +0200 Subject: [PATCH 6/8] fixes --- conan/tools/microsoft/visual.py | 10 ++++------ conans/client/conf/__init__.py | 4 ++-- .../test/unittests/tools/cmake/test_cmaketoolchain.py | 2 +- .../unittests/tools/microsoft/test_msvs_toolset.py | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/conan/tools/microsoft/visual.py b/conan/tools/microsoft/visual.py index cbd28f74c53..1632e3b9585 100644 --- a/conan/tools/microsoft/visual.py +++ b/conan/tools/microsoft/visual.py @@ -77,7 +77,7 @@ def msvc_version_to_toolset_version(version): '191': 'v141', '192': 'v142', "193": 'v143', - "194": 'v144'} + "194": 'v143'} return toolsets.get(str(version)) @@ -126,15 +126,13 @@ def generate(self, scope="build"): vs_version = {"v140": "14", "v141": "15", "v142": "16", - "v143": "17", - "v144": "17"}.get(toolset_version) + "v143": "17"}.get(toolset_version) if vs_version is None: - raise ConanException("Visual Studio Runtime version (v140-v144) not defined") + raise ConanException("Visual Studio Runtime version (v140-v143) not defined") vcvars_ver = {"v140": "14.0", "v141": "14.1", "v142": "14.2", - "v143": "14.3", - "v144": "14.4"}.get(toolset_version) + "v143": "14.3"}.get(toolset_version) else: vs_version = vs_ide_version(conanfile) if int(vs_version) <= 14: diff --git a/conans/client/conf/__init__.py b/conans/client/conf/__init__.py index 80a04722dad..129ceb76f42 100644 --- a/conans/client/conf/__init__.py +++ b/conans/client/conf/__init__.py @@ -94,7 +94,7 @@ "10", "10.1", "10.2", "10.3", "10.4", "10.5", "11", "11.1", "11.2", "11.3", "11.4", "12", "12.1", "12.2", "12.3", - "13", "13.1", "13.2", + "13", "13.1", "13.2", "14", "14.1"] libcxx: [libstdc++, libstdc++11] threads: [null, posix, win32] # Windows MinGW @@ -115,7 +115,7 @@ cppstd: [null, 98, gnu98, 11, gnu11, 14, gnu14, 17, gnu17, 20, gnu20, 23, gnu23] runtime: [null, static, dynamic] runtime_type: [null, Debug, Release] - runtime_version: [null, v140, v141, v142, v143, v144] + runtime_version: [null, v140, v141, v142, v143] apple-clang: version: ["5.0", "5.1", "6.0", "6.1", "7.0", "7.3", "8.0", "8.1", "9.0", "9.1", "10.0", "11.0", "12.0", "13", "13.0", "13.1", "14", "14.0", "15", "15.0"] diff --git a/conans/test/unittests/tools/cmake/test_cmaketoolchain.py b/conans/test/unittests/tools/cmake/test_cmaketoolchain.py index 4d7fd7013a5..8bba79509f8 100644 --- a/conans/test/unittests/tools/cmake/test_cmaketoolchain.py +++ b/conans/test/unittests/tools/cmake/test_cmaketoolchain.py @@ -231,7 +231,7 @@ def test_toolset_update_version_overflow(conanfile_msvc): conanfile_msvc.settings.compiler.version = "194" conanfile_msvc.settings.compiler.update = "8" toolchain = CMakeToolchain(conanfile_msvc) - assert 'set(CMAKE_GENERATOR_TOOLSET "v144,version=14.48" CACHE STRING "" FORCE)' in toolchain.content + assert 'set(CMAKE_GENERATOR_TOOLSET "v143,version=14.48" CACHE STRING "" FORCE)' in toolchain.content def test_toolset_x64(conanfile_msvc): diff --git a/conans/test/unittests/tools/microsoft/test_msvs_toolset.py b/conans/test/unittests/tools/microsoft/test_msvs_toolset.py index 43e72f35a42..14574127e26 100644 --- a/conans/test/unittests/tools/microsoft/test_msvs_toolset.py +++ b/conans/test/unittests/tools/microsoft/test_msvs_toolset.py @@ -15,7 +15,7 @@ def test_invalid_compiler(): @pytest.mark.parametrize("compiler_version,expected_toolset", [ - ("194", "v144"), + ("194", "v143"), ("193", "v143"), ("192", "v142"), ("191", "v141"), From 5e9ccecf8b0f4a8bbde4357c4c5444bc9d9e59af Mon Sep 17 00:00:00 2001 From: James Date: Fri, 3 May 2024 12:08:29 +0200 Subject: [PATCH 7/8] new test for PkgConfigDeps (#16198) --- .../toolchains/gnu/test_pkgconfigdeps.py | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/conans/test/integration/toolchains/gnu/test_pkgconfigdeps.py b/conans/test/integration/toolchains/gnu/test_pkgconfigdeps.py index 31d10d75601..eacad94118c 100644 --- a/conans/test/integration/toolchains/gnu/test_pkgconfigdeps.py +++ b/conans/test/integration/toolchains/gnu/test_pkgconfigdeps.py @@ -227,6 +227,55 @@ def package_info(self): assert "componentdir=${prefix}/mydir" in pc_content assert "Version: 19.8.199" in pc_content + # Now with lockfile + # https://github.com/conan-io/conan/issues/16197 + lockfile = textwrap.dedent(""" + { + "version": "0.5", + "requires": [ + "pkg/0.1#9a5fed2bf506fd28817ddfbc92b07fc1" + ] + } + """) + client.save({"conan.lock": lockfile}) + client.run("install --requires=pkg/0.1 -g PkgConfigDeps --lockfile=conan.lock") + pc_content = client.load("pkg-mycomponent.pc") + assert "componentdir=${prefix}/mydir" in pc_content + assert "Version: 19.8.199" in pc_content + + +def test_custom_version(): + # https://github.com/conan-io/conan/issues/16197 + conanfile = textwrap.dedent(""" + from conan import ConanFile + + class PkgConfigConan(ConanFile): + def package_info(self): + self.cpp_info.set_property("system_package_version", "19.8.199") + """) + client = TestClient() + client.save({"conanfile.py": conanfile}) + client.run("create . --name=pkg --version=0.1") + client.run("install --requires=pkg/0.1 -g PkgConfigDeps") + + pc_content = client.load("pkg.pc") + assert "Version: 19.8.199" in pc_content + + # Now with lockfile + # https://github.com/conan-io/conan/issues/16197 + lockfile = textwrap.dedent(""" + { + "version": "0.5", + "requires": [ + "pkg/0.1#0fe93a852dd6a177bca87cb2d4491a18" + ] + } + """) + client.save({"conan.lock": lockfile}) + client.run("install --requires=pkg/0.1 -g PkgConfigDeps --lockfile=conan.lock") + pc_content = client.load("pkg.pc") + assert "Version: 19.8.199" in pc_content + def test_pkg_with_public_deps_and_component_requires(): """ From 01fc52ebaeeede8aa52216ae147ca0961133e71f Mon Sep 17 00:00:00 2001 From: memsharded Date: Sun, 12 May 2024 11:33:03 +0200 Subject: [PATCH 8/8] removed prints --- conans/client/graph/compatibility.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/conans/client/graph/compatibility.py b/conans/client/graph/compatibility.py index 817109abc42..967ddc90efe 100644 --- a/conans/client/graph/compatibility.py +++ b/conans/client/graph/compatibility.py @@ -49,7 +49,6 @@ def cppstd_compat(conanfile): if msvc_fallback: factors.append([{"compiler.version": msvc_fallback}]) - conanfile.output.info(f"FACTORS {factors}") combinations = [] for factor in factors: if not combinations: @@ -63,7 +62,6 @@ def cppstd_compat(conanfile): new_combinations.append(comb) combinations = new_combinations - conanfile.output.info(f"COMbINATIONS {combinations}") ret = [] for comb in combinations: configuration = base.copy()