From bb8e5491f2bee1e2bf9af8464d0d1bcb5987a41e Mon Sep 17 00:00:00 2001 From: czoido Date: Mon, 28 Nov 2022 17:43:14 +0100 Subject: [PATCH 1/2] add prefix argument --- conan/tools/gnu/autotoolstoolchain.py | 5 ++-- .../toolchains/gnu/test_autotoolstoolchain.py | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/conan/tools/gnu/autotoolstoolchain.py b/conan/tools/gnu/autotoolstoolchain.py index df84c6c2d83..58115a6072b 100644 --- a/conan/tools/gnu/autotoolstoolchain.py +++ b/conan/tools/gnu/autotoolstoolchain.py @@ -13,9 +13,10 @@ class AutotoolsToolchain: - def __init__(self, conanfile, namespace=None): + def __init__(self, conanfile, namespace=None, prefix="/"): self._conanfile = conanfile self._namespace = namespace + self._prefix = prefix self.configure_args = self._default_configure_shared_flags() + self._default_configure_install_flags() self.autoreconf_args = self._default_autoreconf_flags() @@ -168,7 +169,7 @@ def _get_argument(argument_name, cppinfo_name): return "--{}=${{prefix}}/{}".format(argument_name, elements[0]) if elements else "" # If someone want arguments but not the defaults can pass them in args manually - configure_install_flags.extend(["--prefix=/", + configure_install_flags.extend([f"--prefix={self._prefix}", _get_argument("bindir", "bindirs"), _get_argument("sbindir", "bindirs"), _get_argument("libdir", "libdirs"), diff --git a/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py b/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py index 1b9b3269abe..16992860209 100644 --- a/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py +++ b/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py @@ -1,3 +1,4 @@ +import os import platform import textwrap @@ -67,3 +68,27 @@ def generate(self): client.save({"conanfile.py": conanfile}) client.run("install .") + +def test_set_prefix(): + + conanfile = textwrap.dedent(""" + from conan import ConanFile + from conan.tools.gnu import AutotoolsToolchain + from conan.tools.layout import basic_layout + + + class Foo(ConanFile): + name = "foo" + version = "1.0" + def layout(self): + basic_layout(self) + def generate(self): + at_toolchain = AutotoolsToolchain(self, prefix="/somefolder") + at_toolchain.generate() + """) + + client = TestClient() + client.save({"conanfile.py": conanfile}) + client.run("install .") + conanbuild = client.load(os.path.join(client.current_folder, "build", "conan", "conanbuild.conf")) + assert "configure_args = '--prefix=/somefolder'" in conanbuild From c635a7807b3562fc258557e3e62a28bfa05e02d2 Mon Sep 17 00:00:00 2001 From: czoido Date: Tue, 29 Nov 2022 09:50:33 +0100 Subject: [PATCH 2/2] win compatible test --- .../test/integration/toolchains/gnu/test_autotoolstoolchain.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py b/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py index 16992860209..9c91d3c8ef1 100644 --- a/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py +++ b/conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py @@ -91,4 +91,5 @@ def generate(self): client.save({"conanfile.py": conanfile}) client.run("install .") conanbuild = client.load(os.path.join(client.current_folder, "build", "conan", "conanbuild.conf")) - assert "configure_args = '--prefix=/somefolder'" in conanbuild + assert "--prefix=/somefolder" in conanbuild + assert conanbuild.count("--prefix") == 1