Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add prefix argument to AutotoolsToolchain #12620

Merged
merged 2 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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