Skip to content

Commit

Permalink
Add prefix argument to AutotoolsToolchain (#12620)
Browse files Browse the repository at this point in the history
* add prefix argument

* win compatible test
  • Loading branch information
czoido authored Nov 29, 2022
1 parent 7152642 commit 4c1363f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
5 changes: 3 additions & 2 deletions conan/tools/gnu/autotoolstoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"),
Expand Down
26 changes: 26 additions & 0 deletions conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import platform
import textwrap

Expand Down Expand Up @@ -67,3 +68,28 @@ 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 "--prefix=/somefolder" in conanbuild
assert conanbuild.count("--prefix") == 1

0 comments on commit 4c1363f

Please sign in to comment.