From 69c143d104d4f1854be3388870ac62134673aa69 Mon Sep 17 00:00:00 2001 From: Francisco Ramirez de Anton Date: Tue, 19 Mar 2024 16:59:19 +0100 Subject: [PATCH 1/8] Add failing tests --- .../toolchains/cmake/test_cmaketoolchain.py | 57 +++++++++++++++++ .../toolchains/gnu/test_autotoolstoolchain.py | 58 +++++++++++++++++ .../toolchains/meson/test_mesontoolchain.py | 64 +++++++++++++++++++ 3 files changed, 179 insertions(+) diff --git a/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py b/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py index 2f36c4b3ff9..73427512bb5 100644 --- a/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py +++ b/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py @@ -1334,3 +1334,60 @@ def test_toolchain_ends_newline(): client.run("install . -g CMakeToolchain") toolchain = client.load("conan_toolchain.cmake") assert toolchain[-1] == "\n" + + +def test_toolchain_and_compilers_build_context(): + """ + Tests how CMakeToolchain manages the build context profile if the build profile is + specifying another compiler path (using conf) + + Issue related: https://github.com/conan-io/conan/issues/15878 + """ + host = textwrap.dedent(""" + [settings] + arch=armv8 + build_type=Release + compiler=gcc + compiler.cppstd=gnu17 + compiler.libcxx=libstdc++11 + compiler.version=11 + os=Linux + """) + build = textwrap.dedent(""" + [settings] + os=Linux + arch=x86_64 + compiler=clang + compiler.version=12 + compiler.libcxx=libc++ + compiler.cppstd=11 + + [conf] + tools.build:compiler_executables={"asm": "clang", "c": "clang", "cpp": "clang++"} + """) + conanfile = textwrap.dedent(""" + import os + from conan import ConanFile + from conan.tools.files import replace_in_file + class helloRecipe(ConanFile): + name = "hello" + version = "1.0.0" + package_type = "application" + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + generators = "CMakeToolchain" + + def build(self): + path = os.path.join(self.generators_folder, "conan_toolchain.cmake") + assert os.path.exists(path) # sanity check + # This should not raise anything!! Notice the strict=True + replace_in_file(self, path, 'set(CMAKE_C_COMPILER "clang")', "#Hey", strict=True) + replace_in_file(self, path, 'set(CMAKE_CXX_COMPILER "clang++")', "#clang", strict=True) + """) + client = TestClient() + client.save({ + "host": host, + "build": build, + "conanfile.py": conanfile + }) + client.run("build . -pr:h host -pr:b build") diff --git a/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py b/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py index 0702627fd09..2135633a61f 100644 --- a/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py +++ b/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py @@ -195,3 +195,61 @@ def test_unknown_compiler(): # this used to crash, because of build_type_flags in AutotoolsToolchain returning empty string client.run("install . -s compiler=xlc") assert "conanfile.py: Generator 'AutotoolsToolchain' calling 'generate()'" in client.out + + + +def test_toolchain_and_compilers_build_context(): + """ + Tests how CMakeToolchain manages the build context profile if the build profile is + specifying another compiler path (using conf) + + Issue related: https://github.com/conan-io/conan/issues/15878 + """ + host = textwrap.dedent(""" + [settings] + arch=armv8 + build_type=Release + compiler=gcc + compiler.cppstd=gnu17 + compiler.libcxx=libstdc++11 + compiler.version=11 + os=Linux + """) + build = textwrap.dedent(""" + [settings] + os=Linux + arch=x86_64 + compiler=clang + compiler.version=12 + compiler.libcxx=libc++ + compiler.cppstd=11 + + [conf] + tools.build:compiler_executables={"asm": "clang", "c": "clang", "cpp": "clang++"} + """) + conanfile = textwrap.dedent(""" + import os + from conan import ConanFile + from conan.tools.files import replace_in_file + class helloRecipe(ConanFile): + name = "hello" + version = "1.0.0" + package_type = "application" + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + generators = "AutotoolsToolchain" + + def build(self): + path = os.path.join(self.generators_folder, "conanautotoolstoolchain.sh") + assert os.path.exists(path) # sanity check + # This should not raise anything!! Notice the strict=True + replace_in_file(self, path, 'export CC="clang"', "#Hey", strict=True) + replace_in_file(self, path, 'export CXX="clang++', "#Hey", strict=True) + """) + client = TestClient() + client.save({ + "host": host, + "build": build, + "conanfile.py": conanfile + }) + client.run("build . -pr:h host -pr:b build") diff --git a/conans/test/integration/toolchains/meson/test_mesontoolchain.py b/conans/test/integration/toolchains/meson/test_mesontoolchain.py index df43eb29259..55570383abf 100644 --- a/conans/test/integration/toolchains/meson/test_mesontoolchain.py +++ b/conans/test/integration/toolchains/meson/test_mesontoolchain.py @@ -309,3 +309,67 @@ def generate(self): base_folder = t.current_folder assert f"pkg_config_path = '{base_folder}'" in content assert f"build.pkg_config_path = '{os.path.join(base_folder, 'build')}'" in content + + + +def test_toolchain_and_compilers_build_context(): + """ + Tests how MesonToolchain manages the build context profile if the build profile is + specifying another compiler path (using conf). + + It should create both native and cross files. + + Issue related: https://github.com/conan-io/conan/issues/15878 + """ + host = textwrap.dedent(""" + [settings] + arch=armv8 + build_type=Release + compiler=gcc + compiler.cppstd=gnu17 + compiler.libcxx=libstdc++11 + compiler.version=11 + os=Linux + """) + build = textwrap.dedent(""" + [settings] + os=Linux + arch=x86_64 + compiler=clang + compiler.version=12 + compiler.libcxx=libc++ + compiler.cppstd=11 + + [conf] + tools.build:compiler_executables={"asm": "clang", "c": "clang", "cpp": "clang++"} + """) + conanfile = textwrap.dedent(""" + import os + from conan import ConanFile + from conan.tools.files import replace_in_file + class helloRecipe(ConanFile): + name = "hello" + version = "1.0.0" + package_type = "application" + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + generators = "MesonToolchain" + + def build(self): + native_path = os.path.join(self.generators_folder, "conan_meson_native.ini") + cross_path = os.path.join(self.generators_folder, "conan_meson_cross.ini") + assert os.path.exists(cross_path) # sanity check + assert os.path.exists(native_path) # sanity check + # This should not raise anything!! Notice the strict=True + replace_in_file(self, cross_path, 'c = gcc', "#Hey", strict=True) + replace_in_file(self, cross_path, 'cpp = g++', "#Hey", strict=True) + replace_in_file(self, native_path, 'c = clang', "#Hey", strict=True) + replace_in_file(self, native_path, 'cpp = clang++', "#Hey", strict=True) + """) + client = TestClient() + client.save({ + "host": host, + "build": build, + "conanfile.py": conanfile + }) + client.run("build . -pr:h host -pr:b build") From 12345b77e5c27fe758fc034fc918cde38d616329 Mon Sep 17 00:00:00 2001 From: Francisco Ramirez de Anton Date: Wed, 20 Mar 2024 09:44:30 +0100 Subject: [PATCH 2/8] Added test for CMake --- .../toolchains/cmake/test_cmake_toolchain.py | 90 +++++++++++++++++++ .../toolchains/cmake/test_cmaketoolchain.py | 57 ------------ 2 files changed, 90 insertions(+), 57 deletions(-) diff --git a/conans/test/functional/toolchains/cmake/test_cmake_toolchain.py b/conans/test/functional/toolchains/cmake/test_cmake_toolchain.py index e61d9e45255..f1c2e9792e8 100644 --- a/conans/test/functional/toolchains/cmake/test_cmake_toolchain.py +++ b/conans/test/functional/toolchains/cmake/test_cmake_toolchain.py @@ -1908,3 +1908,93 @@ def build(self): c.run_command(r"build\Debug\example.exe") assert 'answer=123' in c.out assert "CPLUSPLUS: __cplusplus19" in c.out + + +@pytest.mark.tool("cmake") +@pytest.mark.skipif(platform.system() != "Darwin", reason="need clang and gcc (clang)") +def test_toolchain_and_compilers_build_context(): + """ + Tests how CMakeToolchain manages the build context profile if the build profile is + specifying another compiler path (using conf) + + Issue related: https://github.com/conan-io/conan/issues/15878 + """ + host = textwrap.dedent(""" + [settings] + arch=armv8 + build_type=Release + compiler=gcc + compiler.cppstd=gnu17 + compiler.libcxx=libstdc++11 + compiler.version=11 + os=Macos + + [conf] + tools.build:compiler_executables={"c": "gcc", "cpp": "g++"} + """) + build = textwrap.dedent(""" + [settings] + os=Macos + arch=x86_64 + compiler=clang + compiler.version=12 + compiler.libcxx=libc++ + compiler.cppstd=11 + + [conf] + tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} + """) + tool = textwrap.dedent(""" + import os + from conan import ConanFile + from conan.tools.files import replace_in_file + from conan.tools.cmake import CMake + + class toolRecipe(ConanFile): + name = "tool" + version = "1.0" + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + generators = "CMakeToolchain" + exports_sources = "*" + + def build(self): + b = CMake(self) + b.configure() + """) + consumer = textwrap.dedent(""" + import os + from conan import ConanFile + from conan.tools.files import replace_in_file + from conan.tools.cmake import CMake + + class consumerRecipe(ConanFile): + name = "consumer" + version = "1.0" + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + generators = "CMakeToolchain" + exports_sources = "*" + tool_requires = "tool/1.0" + + def build(self): + b = CMake(self) + b.configure() + """) + client = TestClient() + client.save({ + "host": host, + "build": build, + "tool/conanfile.py": tool, + "tool/CMakeLists.txt": "project(tool)\n", + "consumer/conanfile.py": consumer, + "consumer/CMakeLists.txt": "project(consumer)\n", + }) + client.run("export tool") + client.run("create consumer -pr:h host -pr:b build --build=missing") + assert "-- Check for working C compiler: /usr/bin/clang - skipped" in str(client.out) + assert "-- Check for working CXX compiler: /usr/bin/clang++ - skipped" in str(client.out) + assert "-- Check for working C compiler: /usr/bin/gcc - skipped" in str(client.out) + assert "-- Check for working CXX compiler: /usr/bin/g++ - skipped" in str(client.out) + assert "consumer/1.0: Created package revision" in str(client.out) + assert "tool/1.0: Created package revision" in str(client.out) diff --git a/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py b/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py index 73427512bb5..2f36c4b3ff9 100644 --- a/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py +++ b/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py @@ -1334,60 +1334,3 @@ def test_toolchain_ends_newline(): client.run("install . -g CMakeToolchain") toolchain = client.load("conan_toolchain.cmake") assert toolchain[-1] == "\n" - - -def test_toolchain_and_compilers_build_context(): - """ - Tests how CMakeToolchain manages the build context profile if the build profile is - specifying another compiler path (using conf) - - Issue related: https://github.com/conan-io/conan/issues/15878 - """ - host = textwrap.dedent(""" - [settings] - arch=armv8 - build_type=Release - compiler=gcc - compiler.cppstd=gnu17 - compiler.libcxx=libstdc++11 - compiler.version=11 - os=Linux - """) - build = textwrap.dedent(""" - [settings] - os=Linux - arch=x86_64 - compiler=clang - compiler.version=12 - compiler.libcxx=libc++ - compiler.cppstd=11 - - [conf] - tools.build:compiler_executables={"asm": "clang", "c": "clang", "cpp": "clang++"} - """) - conanfile = textwrap.dedent(""" - import os - from conan import ConanFile - from conan.tools.files import replace_in_file - class helloRecipe(ConanFile): - name = "hello" - version = "1.0.0" - package_type = "application" - # Binary configuration - settings = "os", "compiler", "build_type", "arch" - generators = "CMakeToolchain" - - def build(self): - path = os.path.join(self.generators_folder, "conan_toolchain.cmake") - assert os.path.exists(path) # sanity check - # This should not raise anything!! Notice the strict=True - replace_in_file(self, path, 'set(CMAKE_C_COMPILER "clang")', "#Hey", strict=True) - replace_in_file(self, path, 'set(CMAKE_CXX_COMPILER "clang++")', "#clang", strict=True) - """) - client = TestClient() - client.save({ - "host": host, - "build": build, - "conanfile.py": conanfile - }) - client.run("build . -pr:h host -pr:b build") From 680b90b59f77a99146c4fb4b0ad355250d019ee7 Mon Sep 17 00:00:00 2001 From: Francisco Ramirez de Anton Date: Wed, 20 Mar 2024 10:52:46 +0100 Subject: [PATCH 3/8] Final cmake test --- .../toolchains/cmake/test_cmake_toolchain.py | 92 +------------------ .../toolchains/cmake/test_cmaketoolchain.py | 83 +++++++++++++++++ 2 files changed, 84 insertions(+), 91 deletions(-) diff --git a/conans/test/functional/toolchains/cmake/test_cmake_toolchain.py b/conans/test/functional/toolchains/cmake/test_cmake_toolchain.py index f1c2e9792e8..497cfe0180b 100644 --- a/conans/test/functional/toolchains/cmake/test_cmake_toolchain.py +++ b/conans/test/functional/toolchains/cmake/test_cmake_toolchain.py @@ -7,8 +7,8 @@ import pytest from conan.tools.cmake.presets import load_cmake_presets -from conans.model.recipe_ref import RecipeReference from conan.tools.microsoft.visual import vcvars_command +from conans.model.recipe_ref import RecipeReference from conans.test.assets.cmake import gen_cmakelists from conans.test.assets.genconanfile import GenConanfile from conans.test.utils.test_files import temp_folder @@ -1908,93 +1908,3 @@ def build(self): c.run_command(r"build\Debug\example.exe") assert 'answer=123' in c.out assert "CPLUSPLUS: __cplusplus19" in c.out - - -@pytest.mark.tool("cmake") -@pytest.mark.skipif(platform.system() != "Darwin", reason="need clang and gcc (clang)") -def test_toolchain_and_compilers_build_context(): - """ - Tests how CMakeToolchain manages the build context profile if the build profile is - specifying another compiler path (using conf) - - Issue related: https://github.com/conan-io/conan/issues/15878 - """ - host = textwrap.dedent(""" - [settings] - arch=armv8 - build_type=Release - compiler=gcc - compiler.cppstd=gnu17 - compiler.libcxx=libstdc++11 - compiler.version=11 - os=Macos - - [conf] - tools.build:compiler_executables={"c": "gcc", "cpp": "g++"} - """) - build = textwrap.dedent(""" - [settings] - os=Macos - arch=x86_64 - compiler=clang - compiler.version=12 - compiler.libcxx=libc++ - compiler.cppstd=11 - - [conf] - tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} - """) - tool = textwrap.dedent(""" - import os - from conan import ConanFile - from conan.tools.files import replace_in_file - from conan.tools.cmake import CMake - - class toolRecipe(ConanFile): - name = "tool" - version = "1.0" - # Binary configuration - settings = "os", "compiler", "build_type", "arch" - generators = "CMakeToolchain" - exports_sources = "*" - - def build(self): - b = CMake(self) - b.configure() - """) - consumer = textwrap.dedent(""" - import os - from conan import ConanFile - from conan.tools.files import replace_in_file - from conan.tools.cmake import CMake - - class consumerRecipe(ConanFile): - name = "consumer" - version = "1.0" - # Binary configuration - settings = "os", "compiler", "build_type", "arch" - generators = "CMakeToolchain" - exports_sources = "*" - tool_requires = "tool/1.0" - - def build(self): - b = CMake(self) - b.configure() - """) - client = TestClient() - client.save({ - "host": host, - "build": build, - "tool/conanfile.py": tool, - "tool/CMakeLists.txt": "project(tool)\n", - "consumer/conanfile.py": consumer, - "consumer/CMakeLists.txt": "project(consumer)\n", - }) - client.run("export tool") - client.run("create consumer -pr:h host -pr:b build --build=missing") - assert "-- Check for working C compiler: /usr/bin/clang - skipped" in str(client.out) - assert "-- Check for working CXX compiler: /usr/bin/clang++ - skipped" in str(client.out) - assert "-- Check for working C compiler: /usr/bin/gcc - skipped" in str(client.out) - assert "-- Check for working CXX compiler: /usr/bin/g++ - skipped" in str(client.out) - assert "consumer/1.0: Created package revision" in str(client.out) - assert "tool/1.0: Created package revision" in str(client.out) diff --git a/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py b/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py index 2f36c4b3ff9..b5f4463bc45 100644 --- a/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py +++ b/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py @@ -7,6 +7,7 @@ from mock import mock from conan.tools.cmake.presets import load_cmake_presets +from conan.tools.files import load from conans.test.assets.genconanfile import GenConanfile from conans.test.utils.tools import TestClient from conans.util.files import rmdir, load @@ -1334,3 +1335,85 @@ def test_toolchain_ends_newline(): client.run("install . -g CMakeToolchain") toolchain = client.load("conan_toolchain.cmake") assert toolchain[-1] == "\n" + + +def test_toolchain_and_compilers_build_context(): + """ + Tests how CMakeToolchain manages the build context profile if the build profile is + specifying another compiler path (using conf) + + Issue related: https://github.com/conan-io/conan/issues/15878 + """ + host = textwrap.dedent(""" + [settings] + arch=armv8 + build_type=Release + compiler=gcc + compiler.cppstd=gnu17 + compiler.libcxx=libstdc++11 + compiler.version=11 + os=Macos + + [conf] + tools.build:compiler_executables={"c": "gcc", "cpp": "g++"} + """) + build = textwrap.dedent(""" + [settings] + os=Macos + arch=x86_64 + compiler=clang + compiler.version=12 + compiler.libcxx=libc++ + compiler.cppstd=11 + + [conf] + tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} + """) + tool = textwrap.dedent(""" + import os + from conan import ConanFile + from conan.tools.cmake import CMake + from conan.tools.files import load + + class toolRecipe(ConanFile): + name = "tool" + version = "1.0" + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + generators = "CMakeToolchain" + + def build(self): + toolchain = os.path.join(self.generators_folder, "conan_toolchain.cmake") + content = load(self, toolchain) + assert 'set(CMAKE_C_COMPILER "clang")' in content + assert 'set(CMAKE_CXX_COMPILER "clang++")' in content + """) + consumer = textwrap.dedent(""" + import os + from conan import ConanFile + from conan.tools.files import load + from conan.tools.cmake import CMake + + class consumerRecipe(ConanFile): + name = "consumer" + version = "1.0" + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + generators = "CMakeToolchain" + tool_requires = "tool/1.0" + + def build(self): + toolchain = os.path.join(self.generators_folder, "conan_toolchain.cmake") + content = load(self, toolchain) + assert 'set(CMAKE_C_COMPILER "gcc")' in content + assert 'set(CMAKE_CXX_COMPILER "g++")' in content + """) + client = TestClient() + client.save({ + "host": host, + "build": build, + "tool/conanfile.py": tool, + "consumer/conanfile.py": consumer + }) + client.run("export tool") + client.run("create consumer -pr:h host -pr:b build --build=missing") From d38ab60b9ff4ab9ccdc8e767bda10a2a75f4d383 Mon Sep 17 00:00:00 2001 From: Francisco Ramirez de Anton Date: Wed, 20 Mar 2024 11:09:02 +0100 Subject: [PATCH 4/8] tests --- .../toolchains/cmake/test_cmaketoolchain.py | 2 - .../toolchains/meson/test_mesontoolchain.py | 82 +++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py b/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py index b5f4463bc45..9257d62b3bf 100644 --- a/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py +++ b/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py @@ -1372,7 +1372,6 @@ def test_toolchain_and_compilers_build_context(): tool = textwrap.dedent(""" import os from conan import ConanFile - from conan.tools.cmake import CMake from conan.tools.files import load class toolRecipe(ConanFile): @@ -1392,7 +1391,6 @@ def build(self): import os from conan import ConanFile from conan.tools.files import load - from conan.tools.cmake import CMake class consumerRecipe(ConanFile): name = "consumer" diff --git a/conans/test/integration/toolchains/meson/test_mesontoolchain.py b/conans/test/integration/toolchains/meson/test_mesontoolchain.py index 55570383abf..d2a1695e766 100644 --- a/conans/test/integration/toolchains/meson/test_mesontoolchain.py +++ b/conans/test/integration/toolchains/meson/test_mesontoolchain.py @@ -373,3 +373,85 @@ def build(self): "conanfile.py": conanfile }) client.run("build . -pr:h host -pr:b build") + + +def test_toolchain_and_compilers_build_context(): + """ + Tests how MesonToolchain manages the build context profile if the build profile is + specifying another compiler path (using conf). + + It should create both native and cross files. + + Issue related: https://github.com/conan-io/conan/issues/15878 + """ + host = textwrap.dedent(""" + [settings] + arch=armv8 + build_type=Release + compiler=gcc + compiler.cppstd=gnu17 + compiler.libcxx=libstdc++11 + compiler.version=11 + os=Macos + + [conf] + tools.build:compiler_executables={"c": "gcc", "cpp": "g++"} + """) + build = textwrap.dedent(""" + [settings] + os=Macos + arch=x86_64 + compiler=clang + compiler.version=12 + compiler.libcxx=libc++ + compiler.cppstd=11 + + [conf] + tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} + """) + tool = textwrap.dedent(""" + import os + from conan import ConanFile + from conan.tools.files import load + + class toolRecipe(ConanFile): + name = "tool" + version = "1.0" + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + generators = "MesonToolchain" + + def build(self): + toolchain = os.path.join(self.generators_folder, "conan_meson_native.ini") + content = load(self, toolchain) + assert "c = 'clang'" in content + assert "cpp = 'clang++'" in content + """) + consumer = textwrap.dedent(""" + import os + from conan import ConanFile + from conan.tools.files import load + + class consumerRecipe(ConanFile): + name = "consumer" + version = "1.0" + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + generators = "MesonToolchain" + tool_requires = "tool/1.0" + + def build(self): + toolchain = os.path.join(self.generators_folder, "conan_meson_cross.ini") + content = load(self, toolchain) + assert "c = 'gcc'" in content + assert "cpp = 'g++'" in content + """) + client = TestClient() + client.save({ + "host": host, + "build": build, + "tool/conanfile.py": tool, + "consumer/conanfile.py": consumer + }) + client.run("export tool") + client.run("create consumer -pr:h host -pr:b build --build=missing") From 530fdb9524079d59131cf11952af8a44f2aae5ee Mon Sep 17 00:00:00 2001 From: Francisco Ramirez de Anton Date: Wed, 20 Mar 2024 11:12:45 +0100 Subject: [PATCH 5/8] Added last test --- .../toolchains/gnu/test_autotoolstoolchain.py | 58 +++++++++++++------ 1 file changed, 40 insertions(+), 18 deletions(-) diff --git a/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py b/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py index 2135633a61f..673516dd814 100644 --- a/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py +++ b/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py @@ -197,10 +197,9 @@ def test_unknown_compiler(): assert "conanfile.py: Generator 'AutotoolsToolchain' calling 'generate()'" in client.out - def test_toolchain_and_compilers_build_context(): """ - Tests how CMakeToolchain manages the build context profile if the build profile is + Tests how AutotoolsToolchain manages the build context profile if the build profile is specifying another compiler path (using conf) Issue related: https://github.com/conan-io/conan/issues/15878 @@ -213,11 +212,14 @@ def test_toolchain_and_compilers_build_context(): compiler.cppstd=gnu17 compiler.libcxx=libstdc++11 compiler.version=11 - os=Linux + os=Macos + + [conf] + tools.build:compiler_executables={"c": "gcc", "cpp": "g++"} """) build = textwrap.dedent(""" [settings] - os=Linux + os=Macos arch=x86_64 compiler=clang compiler.version=12 @@ -225,31 +227,51 @@ def test_toolchain_and_compilers_build_context(): compiler.cppstd=11 [conf] - tools.build:compiler_executables={"asm": "clang", "c": "clang", "cpp": "clang++"} + tools.build:compiler_executables={"c": "clang", "cpp": "clang++"} """) - conanfile = textwrap.dedent(""" + tool = textwrap.dedent(""" + import os + from conan import ConanFile + from conan.tools.files import load + + class toolRecipe(ConanFile): + name = "tool" + version = "1.0" + # Binary configuration + settings = "os", "compiler", "build_type", "arch" + generators = "AutotoolsToolchain" + + def build(self): + toolchain = os.path.join(self.generators_folder, "conanautotoolstoolchain.sh") + content = load(self, toolchain) + assert 'export CC="clang"' in content + assert 'export CXX="clang++"' in content + """) + consumer = textwrap.dedent(""" import os from conan import ConanFile - from conan.tools.files import replace_in_file - class helloRecipe(ConanFile): - name = "hello" - version = "1.0.0" - package_type = "application" + from conan.tools.files import load + + class consumerRecipe(ConanFile): + name = "consumer" + version = "1.0" # Binary configuration settings = "os", "compiler", "build_type", "arch" generators = "AutotoolsToolchain" + tool_requires = "tool/1.0" def build(self): - path = os.path.join(self.generators_folder, "conanautotoolstoolchain.sh") - assert os.path.exists(path) # sanity check - # This should not raise anything!! Notice the strict=True - replace_in_file(self, path, 'export CC="clang"', "#Hey", strict=True) - replace_in_file(self, path, 'export CXX="clang++', "#Hey", strict=True) + toolchain = os.path.join(self.generators_folder, "conanautotoolstoolchain.sh") + content = load(self, toolchain) + assert 'export CC="gcc"' in content + assert 'export CXX="g++"' in content """) client = TestClient() client.save({ "host": host, "build": build, - "conanfile.py": conanfile + "tool/conanfile.py": tool, + "consumer/conanfile.py": consumer }) - client.run("build . -pr:h host -pr:b build") + client.run("export tool") + client.run("create consumer -pr:h host -pr:b build --build=missing") From 3277c8a9b0e925684b5529f72ac26df0f12cc774 Mon Sep 17 00:00:00 2001 From: Francisco Ramirez de Anton Date: Wed, 20 Mar 2024 11:24:12 +0100 Subject: [PATCH 6/8] os linux --- .../test/integration/toolchains/cmake/test_cmaketoolchain.py | 4 ++-- .../integration/toolchains/gnu/test_autotoolstoolchain.py | 4 ++-- .../test/integration/toolchains/meson/test_mesontoolchain.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py b/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py index 9257d62b3bf..a38ab41acb8 100644 --- a/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py +++ b/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py @@ -1352,14 +1352,14 @@ def test_toolchain_and_compilers_build_context(): compiler.cppstd=gnu17 compiler.libcxx=libstdc++11 compiler.version=11 - os=Macos + os=Linux [conf] tools.build:compiler_executables={"c": "gcc", "cpp": "g++"} """) build = textwrap.dedent(""" [settings] - os=Macos + os=Linux arch=x86_64 compiler=clang compiler.version=12 diff --git a/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py b/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py index 673516dd814..b0774335c52 100644 --- a/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py +++ b/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py @@ -212,14 +212,14 @@ def test_toolchain_and_compilers_build_context(): compiler.cppstd=gnu17 compiler.libcxx=libstdc++11 compiler.version=11 - os=Macos + os=Linux [conf] tools.build:compiler_executables={"c": "gcc", "cpp": "g++"} """) build = textwrap.dedent(""" [settings] - os=Macos + os=Linux arch=x86_64 compiler=clang compiler.version=12 diff --git a/conans/test/integration/toolchains/meson/test_mesontoolchain.py b/conans/test/integration/toolchains/meson/test_mesontoolchain.py index d2a1695e766..80650b1d361 100644 --- a/conans/test/integration/toolchains/meson/test_mesontoolchain.py +++ b/conans/test/integration/toolchains/meson/test_mesontoolchain.py @@ -392,14 +392,14 @@ def test_toolchain_and_compilers_build_context(): compiler.cppstd=gnu17 compiler.libcxx=libstdc++11 compiler.version=11 - os=Macos + os=Linux [conf] tools.build:compiler_executables={"c": "gcc", "cpp": "g++"} """) build = textwrap.dedent(""" [settings] - os=Macos + os=Linux arch=x86_64 compiler=clang compiler.version=12 From 6191149e43f701a326f3e56d9e0a2b5636c7b631 Mon Sep 17 00:00:00 2001 From: Francisco Ramirez de Anton Date: Wed, 20 Mar 2024 11:28:35 +0100 Subject: [PATCH 7/8] Remove useless import --- conans/test/integration/toolchains/cmake/test_cmaketoolchain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py b/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py index a38ab41acb8..a3a58d66b81 100644 --- a/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py +++ b/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py @@ -10,7 +10,7 @@ from conan.tools.files import load from conans.test.assets.genconanfile import GenConanfile from conans.test.utils.tools import TestClient -from conans.util.files import rmdir, load +from conans.util.files import rmdir def test_cross_build(): From 2d3e87d7dda0d02655aced0199247faca77abee0 Mon Sep 17 00:00:00 2001 From: Francisco Ramirez de Anton Date: Wed, 20 Mar 2024 11:29:43 +0100 Subject: [PATCH 8/8] wip --- .../test/integration/toolchains/cmake/test_cmaketoolchain.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py b/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py index a3a58d66b81..ebaf4164929 100644 --- a/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py +++ b/conans/test/integration/toolchains/cmake/test_cmaketoolchain.py @@ -7,10 +7,9 @@ from mock import mock from conan.tools.cmake.presets import load_cmake_presets -from conan.tools.files import load from conans.test.assets.genconanfile import GenConanfile from conans.test.utils.tools import TestClient -from conans.util.files import rmdir +from conans.util.files import rmdir, load def test_cross_build():