Skip to content

Commit 91d4d4d

Browse files
committed
Implement tools.build:install_strip for Autotools
Make Autotools strip libraries if requested, consistent with CMake and Meson, by using the 'install-strip' target instead of 'install'.
1 parent 025cd9c commit 91d4d4d

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

conan/tools/gnu/autotools.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ def make(self, target=None, args=None, makefile=None):
8484
command = join_arguments([make_program, str_makefile, target, str_args, str_extra_args, jobs])
8585
self._conanfile.run(command)
8686

87-
def install(self, args=None, target="install", makefile=None):
87+
def install(self, args=None, target=None, makefile=None):
8888
"""
89-
This is just an "alias" of ``self.make(target="install")``
89+
This is just an "alias" of ``self.make(target="install")`` or ``self.make(target="install-strip")``
9090
9191
:param args: (Optional, Defaulted to ``None``): List of arguments to use for the
9292
``make`` call. By default an argument ``DESTDIR=unix_path(self.package_folder)``
@@ -95,6 +95,11 @@ def install(self, args=None, target="install", makefile=None):
9595
:param target: (Optional, Defaulted to ``None``): Choose which target to install.
9696
:param makefile: (Optional, Defaulted to ``None``): Allow specifying a custom makefile to use instead of default "Makefile"
9797
"""
98+
if target is None:
99+
target = "install"
100+
do_strip = self._conanfile.conf.get("tools.build:install_strip", check_type=bool)
101+
if do_strip:
102+
target += "-strip"
98103
args = args if args else []
99104
str_args = " ".join(args)
100105
if "DESTDIR=" not in str_args:

test/unittests/tools/gnu/autotools_test.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import pytest
12
import os
23
from mock import patch
34

45
from conan.tools.build import save_toolchain_args
56
from conan.tools.gnu import Autotools
6-
from conan.test.utils.mocks import ConanFileMock
7+
from conan.test.utils.mocks import ConanFileMock, MockSettings
78
from conan.test.utils.test_files import temp_folder
89

910

@@ -33,3 +34,27 @@ def test_source_folder_works(chdir_mock):
3334
autotools.autoreconf()
3435
chdir_mock.assert_called_with(autotools, os.path.normpath("/path/to/sources"))
3536
assert conanfile.command == 'autoreconf -bar foo'
37+
38+
@pytest.mark.parametrize("install_strip", [False, True])
39+
def test_install_strip(install_strip):
40+
"""
41+
When the configuration `tools.build:install_strip` is set to True,
42+
the Autotools install command should invoke the `install-strip` target.
43+
"""
44+
45+
settings = MockSettings({"build_type": "Release",
46+
"compiler": "gcc",
47+
"compiler.version": "7",
48+
"os": "Linux",
49+
"arch": "x86_64"})
50+
conanfile = ConanFileMock()
51+
conanfile.settings = settings
52+
conanfile.conf.define("tools.build:install_strip", install_strip)
53+
conanfile.folders.generators = "."
54+
conanfile.folders.set_base_generators(temp_folder())
55+
conanfile.folders.set_base_package(temp_folder())
56+
57+
autotools = Autotools(conanfile)
58+
autotools.install()
59+
60+
assert ('install-strip' in str(conanfile.command)) == install_strip

0 commit comments

Comments
 (0)