Skip to content

Commit fb37583

Browse files
uilianriesfranramirez688
authored andcommitted
Add support for extra configure arguments (conan-io#18333)
* Add support for extra configure arguments Signed-off-by: Uilian Ries <[email protected]> * Check configuration type Signed-off-by: Uilian Ries <[email protected]> * Validate type-check for list-like Signed-off-by: Uilian Ries <[email protected]> * Replace extra_configure_args by configure_args Signed-off-by: Uilian Ries <[email protected]> * Do not check type Co-authored-by: Francisco Ramírez <[email protected]> * Do not check type Co-authored-by: Francisco Ramírez <[email protected]> * Revert "Replace extra_configure_args by configure_args" This reverts commit 91ac324. * Simplify tests^ Signed-off-by: Uilian Ries <[email protected]> --------- Signed-off-by: Uilian Ries <[email protected]> Co-authored-by: Francisco Ramírez <[email protected]>
1 parent 851364a commit fb37583

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

conan/internal/model/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"tools.gnu:pkg_config": "Path to pkg-config executable used by PkgConfig build helper",
102102
"tools.gnu:build_triplet": "Custom build triplet to pass to Autotools scripts",
103103
"tools.gnu:host_triplet": "Custom host triplet to pass to Autotools scripts",
104+
"tools.gnu:extra_configure_args": "List of extra arguments to pass to configure when using AutotoolsToolchain and GnuToolchain",
104105
"tools.google.bazel:configs": "List of Bazel configurations to be used as 'bazel build --config=config1 ...'",
105106
"tools.google.bazel:bazelrc_path": "List of paths to bazelrc files to be used as 'bazel --bazelrc=rcpath1 ... build'",
106107
"tools.meson.mesontoolchain:backend": "Any Meson backend: ninja, vs, vs2010, vs2012, vs2013, vs2015, vs2017, vs2019, xcode",

conan/tools/gnu/autotoolstoolchain.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,14 @@ def __init__(self, conanfile, namespace=None, prefix="/"):
8383
sysroot = self._conanfile.conf.get("tools.build:sysroot")
8484
sysroot = sysroot.replace("\\", "/") if sysroot is not None else None
8585
self.sysroot_flag = "--sysroot {}".format(sysroot) if sysroot else None
86+
extra_configure_args = self._conanfile.conf.get("tools.gnu:extra_configure_args",
87+
check_type=list,
88+
default=[])
8689

8790
self.configure_args = (self._default_configure_shared_flags() +
8891
self._default_configure_install_flags() +
89-
self._get_triplets())
92+
self._get_triplets() +
93+
extra_configure_args)
9094
self.autoreconf_args = self._default_autoreconf_flags()
9195
self.make_args = []
9296
# Apple stuff

conan/tools/gnu/gnutoolchain.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ def __init__(self, conanfile, namespace=None, prefix="/"):
6262
self.fpic = self._conanfile.options.get_safe("fPIC")
6363
self.msvc_runtime_flag = self._get_msvc_runtime_flag()
6464
self.msvc_extra_flags = self._msvc_extra_flags()
65+
extra_configure_args = self._conanfile.conf.get("tools.gnu:extra_configure_args",
66+
check_type=list,
67+
default=[])
68+
extra_configure_args = {it: None for it in extra_configure_args}
6569

6670
# Host/Build triplets
6771
self.triplets_info = {
@@ -92,6 +96,7 @@ def __init__(self, conanfile, namespace=None, prefix="/"):
9296
self.configure_args.update(self._get_default_configure_shared_flags())
9397
self.configure_args.update(self._get_default_configure_install_flags())
9498
self.configure_args.update(self._get_default_triplets())
99+
self.configure_args.update(extra_configure_args)
95100
# Apple stuff
96101
is_cross_building_osx = (self._is_cross_building
97102
and conanfile.settings_build.get_safe('os') == "Macos"

test/unittests/client/toolchain/autotools/autotools_toolchain_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,3 +605,23 @@ def test_conf_compiler_executable():
605605
be = AutotoolsToolchain(conanfile)
606606
env = be.vars()
607607
assert "/c/my/path/myg++" == env["CXX"]
608+
609+
610+
def test_autotools_toolchain_conf_extra_configure_args():
611+
"""Validate that tools.gnu:extra_configure_args are passed to configure command only.
612+
613+
The configure args should be passed as list only.
614+
"""
615+
f = temp_folder()
616+
os.chdir(f)
617+
conanfile = ConanFileMock()
618+
conanfile.settings = MockSettings({"os": "Linux", "arch": "x86_64"})
619+
conanfile.conf = Conf()
620+
conanfile.conf.define("tools.gnu:extra_configure_args", ["--foo", "--bar"])
621+
622+
be = AutotoolsToolchain(conanfile)
623+
be.generate_args()
624+
obj = load_toolchain_args()
625+
assert "--foo --bar" in obj["configure_args"]
626+
# make sure it does not forward to make
627+
assert "--foo" not in obj["make_args"]

test/unittests/tools/gnu/test_gnutoolchain.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,18 @@ def test_crossbuild_to_android(build_env_mock):
235235
assert gnutc.triplets_info["host"]["triplet"] == "aarch64-linux-android"
236236
assert env_vars["LD"] == os.path.join(ndk_bin, "ld") # exists
237237
assert env_vars["STRIP"] == os.path.join(ndk_bin, "llvm-strip") # does not exist but appears
238+
239+
240+
def test_gnu_toolchain_conf_extra_configure_args():
241+
""" Validate that tools.gnu:extra_configure_args are passed to the configure_args when
242+
building with GnuToolchain.
243+
The configure args should be passed as a list-like object.
244+
"""
245+
conanfile = ConanFileMock()
246+
conanfile.settings = MockSettings({"os": "Linux", "arch": "x86_64"})
247+
conanfile.conf = Conf()
248+
conanfile.conf.define("tools.gnu:extra_configure_args", ["--foo", "--bar"])
249+
250+
tc = GnuToolchain(conanfile)
251+
assert tc.configure_args["--foo"] is None
252+
assert tc.configure_args["--bar"] is None

0 commit comments

Comments
 (0)