diff --git a/conan/tools/gnu/autotoolstoolchain.py b/conan/tools/gnu/autotoolstoolchain.py index e4c008553ce..e24105b37b7 100644 --- a/conan/tools/gnu/autotoolstoolchain.py +++ b/conan/tools/gnu/autotoolstoolchain.py @@ -86,8 +86,13 @@ def __init__(self, conanfile, namespace=None, prefix="/"): self._build = _get_gnu_triplet(os_build, arch_build, compiler=compiler)["triplet"] sysroot = self._conanfile.conf.get("tools.build:sysroot") - sysroot = sysroot.replace("\\", "/") if sysroot is not None else None - self.sysroot_flag = "--sysroot {}".format(sysroot) if sysroot else None + if sysroot: + root = sysroot.replace("\\", "/") + compiler = self._conanfile.settings.get_safe("compiler") + self.sysroot_flag = f"--sysroot {root}" if compiler != "qcc" else f"-Wc,-isysroot,{root}" + else: + self.sysroot_flag = None + extra_configure_args = self._conanfile.conf.get("tools.gnu:extra_configure_args", check_type=list, default=[]) diff --git a/conan/tools/gnu/gnutoolchain.py b/conan/tools/gnu/gnutoolchain.py index 421be382a47..542ffacf5ff 100644 --- a/conan/tools/gnu/gnutoolchain.py +++ b/conan/tools/gnu/gnutoolchain.py @@ -91,8 +91,13 @@ def __init__(self, conanfile, namespace=None, prefix="/"): self.triplets_info["build"] = _get_gnu_triplet(os_build, arch_build, compiler=compiler) sysroot = self._conanfile.conf.get("tools.build:sysroot") - sysroot = sysroot.replace("\\", "/") if sysroot is not None else None - self.sysroot_flag = "--sysroot {}".format(sysroot) if sysroot else None + if sysroot: + root = sysroot.replace("\\", "/") + compiler = self._conanfile.settings.get_safe("compiler") + self.sysroot_flag = f"--sysroot {root}" if compiler != "qcc" else f"-Wc,-isysroot,{root}" + else: + self.sysroot_flag = None + self.configure_args = {} self.autoreconf_args = {"--force": None, "--install": None} self.make_args = {} diff --git a/test/unittests/client/toolchain/__init__.py b/test/unittests/client/toolchain/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/unittests/client/toolchain/autotools/__init__.py b/test/unittests/client/toolchain/autotools/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/unittests/client/tools/apple/test_xcodebuild.py b/test/unittests/tools/apple/test_xcodebuild.py similarity index 100% rename from test/unittests/client/tools/apple/test_xcodebuild.py rename to test/unittests/tools/apple/test_xcodebuild.py diff --git a/test/unittests/client/toolchain/autotools/autotools_test.py b/test/unittests/tools/gnu/autotools_test_old.py similarity index 100% rename from test/unittests/client/toolchain/autotools/autotools_test.py rename to test/unittests/tools/gnu/autotools_test_old.py diff --git a/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py b/test/unittests/tools/gnu/autotools_toolchain_test.py similarity index 97% rename from test/unittests/client/toolchain/autotools/autotools_toolchain_test.py rename to test/unittests/tools/gnu/autotools_toolchain_test.py index 5e06e9ad0af..b6536e91588 100644 --- a/test/unittests/client/toolchain/autotools/autotools_toolchain_test.py +++ b/test/unittests/tools/gnu/autotools_toolchain_test.py @@ -485,6 +485,21 @@ def test_sysrootflag(): assert expected in env["LDFLAGS"] +def test_sysrootflag_qnx(): + """Even when no cross building it is adjusted because it could target a Mac version""" + conanfile = ConanFileMock() + conanfile.conf.define("tools.build:sysroot", "/path/to/sysroot") + conanfile.settings = MockSettings( + {"compiler": "qcc", + "build_type": "Debug", + "os": "Linux", + "arch": "x86_64"}) + conanfile.settings_build = conanfile.settings + be = AutotoolsToolchain(conanfile) + expected = "-Wc,-isysroot,/path/to/sysroot" + assert be.sysroot_flag == expected + + def test_custom_defines(): conanfile = ConanFileMock() conanfile.conf.define("tools.apple:sdk_path", "/path/to/sdk") diff --git a/test/unittests/tools/gnu/test_gnutoolchain.py b/test/unittests/tools/gnu/test_gnutoolchain.py index badab8a7b7e..4b19e261fdd 100644 --- a/test/unittests/tools/gnu/test_gnutoolchain.py +++ b/test/unittests/tools/gnu/test_gnutoolchain.py @@ -166,6 +166,21 @@ def test_linker_scripts(): assert "-T'path_to_second_linker_script'" in env["LDFLAGS"] +def test_sysrootflag_qnx(): + """Even when no cross building it is adjusted because it could target a Mac version""" + conanfile = ConanFileMock() + conanfile.conf.define("tools.build:sysroot", "/path/to/sysroot") + conanfile.settings = MockSettings( + {"compiler": "qcc", + "build_type": "Debug", + "os": "Linux", + "arch": "x86_64"}) + conanfile.settings_build = conanfile.settings + be = GnuToolchain(conanfile) + expected = "-Wc,-isysroot,/path/to/sysroot" + assert be.sysroot_flag == expected + + def test_update_or_prune_any_args(cross_building_conanfile): # Issue: https://github.com/conan-io/conan/issues/12642 at = GnuToolchain(cross_building_conanfile)