Skip to content
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
9 changes: 7 additions & 2 deletions conan/tools/gnu/autotools.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ def make(self, target=None, args=None, makefile=None):
command = join_arguments([make_program, str_makefile, target, str_args, str_extra_args, jobs])
self._conanfile.run(command)

def install(self, args=None, target="install", makefile=None):
def install(self, args=None, target=None, makefile=None):
"""
This is just an "alias" of ``self.make(target="install")``
This is just an "alias" of ``self.make(target="install")`` or ``self.make(target="install-strip")``

:param args: (Optional, Defaulted to ``None``): List of arguments to use for the
``make`` call. By default an argument ``DESTDIR=unix_path(self.package_folder)``
Expand All @@ -95,6 +95,11 @@ def install(self, args=None, target="install", makefile=None):
:param target: (Optional, Defaulted to ``None``): Choose which target to install.
:param makefile: (Optional, Defaulted to ``None``): Allow specifying a custom makefile to use instead of default "Makefile"
"""
if target is None:
target = "install"
do_strip = self._conanfile.conf.get("tools.build:install_strip", check_type=bool)
if do_strip:
target += "-strip"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that there are projects/packages out there that do not define a install-strip target at all?
And then this would break for those projects/packages?
Or it is expected that every autotools project that calls autotools.install() must have this install-strip target?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to this automake manual the install-strip target always exists,

Automake also generates rules for targets uninstall, installdirs, and install-strip.

though I'm no expert with autotools, so I could have somehow misinterpreted this documentation.

args = args if args else []
str_args = " ".join(args)
if "DESTDIR=" not in str_args:
Expand Down
31 changes: 29 additions & 2 deletions test/unittests/tools/gnu/autotools_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pytest
import os
from mock import patch

from conan.tools.build import save_toolchain_args
from conan.tools.gnu import Autotools
from conan.test.utils.mocks import ConanFileMock
from conan.test.utils.mocks import ConanFileMock, MockSettings
from conan.test.utils.test_files import temp_folder


Expand All @@ -28,8 +29,34 @@ def test_source_folder_works(chdir_mock):
assert conanfile.command.replace("\\", "/") == '"/path/to/sources/configure" -foo bar '

autotools.autoreconf(build_script_folder="subfolder")
chdir_mock.assert_called_with(autotools, os.path.normpath(os.path.join("/path/to/sources", "subfolder")))
chdir_mock.assert_called_with(autotools,
os.path.normpath(os.path.join("/path/to/sources", "subfolder")))

autotools.autoreconf()
chdir_mock.assert_called_with(autotools, os.path.normpath("/path/to/sources"))
assert conanfile.command == 'autoreconf -bar foo'


@pytest.mark.parametrize("install_strip", [False, True])
def test_install_strip(install_strip):
"""
When the configuration `tools.build:install_strip` is set to True,
the Autotools install command should invoke the `install-strip` target.
"""
folder = temp_folder()
os.chdir(folder)
save_toolchain_args({})
settings = MockSettings({"build_type": "Release",
"compiler": "gcc",
"compiler.version": "7",
"os": "Linux",
"arch": "x86_64"})
conanfile = ConanFileMock()
conanfile.settings = settings
conanfile.conf.define("tools.build:install_strip", install_strip)
conanfile.folders.generators = "."

autotools = Autotools(conanfile)
autotools.install()

assert ('install-strip' in str(conanfile.command)) == install_strip
Loading