Repository: conan-io/conan
Pull request #17794 (2025-02-17 15:44:23)

exploring cli conf_build definition
Changelog: Fix: Allow build context information from ``conf`` in ``AutotoolsToolchain``
Docs: Omit

Close https://github.com/conan-io/conan/issues/17641



Patch:
diff --git a/conan/tools/gnu/autotoolstoolchain.py b/conan/tools/gnu/autotoolstoolchain.py
index fd5421cc8..e2daf568f 100644
--- a/conan/tools/gnu/autotoolstoolchain.py
+++ b/conan/tools/gnu/autotoolstoolchain.py
@@ -257,7 +257,7 @@ class AutotoolsToolchain:
         env.append("LDFLAGS", self.ldflags)
         env.prepend_path("PKG_CONFIG_PATH", self._conanfile.generators_folder)
         # Issue related: https://github.com/conan-io/conan/issues/15486
-        if self._is_cross_building and getattr(self._conanfile, 'conf_build', False):
+        if self._is_cross_building and self._conanfile.conf_build:
             compilers_build_mapping = (
                 self._conanfile.conf_build.get("tools.build:compiler_executables", default={},
                                                check_type=dict)
diff --git a/conan/tools/gnu/gnutoolchain.py b/conan/tools/gnu/gnutoolchain.py
index a23f4bf0b..1b22240e8 100644
--- a/conan/tools/gnu/gnutoolchain.py
+++ b/conan/tools/gnu/gnutoolchain.py
@@ -186,7 +186,7 @@ class GnuToolchain:
                     compiler = unix_path(self._conanfile, compiler)
                     ret[env_var] = compiler  # User/tools ones have precedence
         # Issue related: https://github.com/conan-io/conan/issues/15486
-        if self._is_cross_building and getattr(self._conanfile, 'conf_build', False):
+        if self._is_cross_building and self._conanfile.conf_build:
             compilers_build_mapping = (
                 self._conanfile.conf_build.get("tools.build:compiler_executables", default={},
                                                check_type=dict)
diff --git a/conans/client/graph/profile_node_definer.py b/conans/client/graph/profile_node_definer.py
index 748304d03..63bbed9a0 100644
--- a/conans/client/graph/profile_node_definer.py
+++ b/conans/client/graph/profile_node_definer.py
@@ -110,3 +110,4 @@ def consumer_definer(conanfile, profile_host, profile_build):
     conanfile._conan_buildenv = profile_host.buildenv
     conanfile._conan_runenv = profile_host.runenv
     conanfile.conf = profile_host.conf.get_conanfile_conf(None, is_consumer=True)
+    conanfile.conf_build = profile_build.conf.get_conanfile_conf(None, is_consumer=True)


Test patch:
diff --git a/test/integration/toolchains/gnu/test_autotoolstoolchain.py b/test/integration/toolchains/gnu/test_autotoolstoolchain.py
index c15908f98..64c9d8c9d 100644
--- a/test/integration/toolchains/gnu/test_autotoolstoolchain.py
+++ b/test/integration/toolchains/gnu/test_autotoolstoolchain.py
@@ -347,30 +347,23 @@ def test_conf_build_does_not_exist():
     host = textwrap.dedent("""
     [settings]
     arch=x86_64
-    build_type=Release
-    compiler=gcc
-    compiler.cppstd=gnu17
-    compiler.libcxx=libstdc++11
-    compiler.version=13
     os=Linux
     [conf]
-    tools.build:compiler_executables={'c': 'x86_64-linux-gnu-gcc', 'cpp': 'x86_64-linux-gnu-g++'}
+    tools.build:compiler_executables={'c': '/usr/bin/gcc', 'cpp': '/usr/bin/g++'}
     """)
     build = textwrap.dedent("""
     [settings]
     arch=armv8
-    build_type=Release
-    compiler=gcc
-    compiler.cppstd=gnu17
-    compiler.libcxx=libstdc++11
-    compiler.version=13
     os=Linux
+    [conf]
+    tools.build:compiler_executables={'c': 'x86_64-linux-gnu-gcc', 'cpp': 'x86_64-linux-gnu-g++'}
     """)
     c = TestClient()
-    c.save({
-        "conanfile.py": GenConanfile("pkg", "0.1"),
-        "host": host,
-        "build": build
-    })
+    c.save({"conanfile.py": GenConanfile("pkg", "0.1"),
+            "host": host,
+            "build": build})
     c.run("export .")
     c.run("install --requires=pkg/0.1 --build=pkg/0.1 -g AutotoolsToolchain -pr:h host -pr:b build")
+    tc = c.load("conanautotoolstoolchain.sh")
+    assert 'export CC_FOR_BUILD="x86_64-linux-gnu-gcc"' in tc
+    assert 'export CXX_FOR_BUILD="x86_64-linux-gnu-g++"' in tc
diff --git a/test/integration/toolchains/gnu/test_gnutoolchain.py b/test/integration/toolchains/gnu/test_gnutoolchain.py
index a5fe7f3f6..e47e30e05 100644
--- a/test/integration/toolchains/gnu/test_gnutoolchain.py
+++ b/test/integration/toolchains/gnu/test_gnutoolchain.py
@@ -436,30 +436,23 @@ def test_conf_build_does_not_exist():
     host = textwrap.dedent("""
     [settings]
     arch=x86_64
-    build_type=Release
-    compiler=gcc
-    compiler.cppstd=gnu17
-    compiler.libcxx=libstdc++11
-    compiler.version=13
     os=Linux
     [conf]
-    tools.build:compiler_executables={'c': 'x86_64-linux-gnu-gcc', 'cpp': 'x86_64-linux-gnu-g++'}
+    tools.build:compiler_executables={'c': '/usr/bin/gcc', 'cpp': '/usr/bin/g++'}
     """)
     build = textwrap.dedent("""
     [settings]
     arch=armv8
-    build_type=Release
-    compiler=gcc
-    compiler.cppstd=gnu17
-    compiler.libcxx=libstdc++11
-    compiler.version=13
     os=Linux
+    [conf]
+    tools.build:compiler_executables={'c': 'x86_64-linux-gnu-gcc', 'cpp': 'x86_64-linux-gnu-g++'}
     """)
     c = TestClient()
-    c.save({
-        "conanfile.py": GenConanfile("pkg", "0.1"),
-        "host": host,
-        "build": build
-    })
+    c.save({"conanfile.py": GenConanfile("pkg", "0.1"),
+            "host": host,
+            "build": build})
     c.run("export .")
     c.run("install --requires=pkg/0.1 --build=pkg/0.1 -g GnuToolchain -pr:h host -pr:b build")
+    tc = c.load("conangnutoolchain.sh")
+    assert 'export CC_FOR_BUILD="x86_64-linux-gnu-gcc"' in tc
+    assert 'export CXX_FOR_BUILD="x86_64-linux-gnu-g++"' in tc