Skip to content

Commit

Permalink
Fix AutotoolsToolchain extraflags priority (#15005)
Browse files Browse the repository at this point in the history
set new order
  • Loading branch information
czoido authored Oct 24, 2023
1 parent a58a49f commit 6326947
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
8 changes: 4 additions & 4 deletions conan/tools/gnu/autotoolstoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def cxxflags(self):
self.sysroot_flag]
apple_flags = [self.apple_isysroot_flag, self.apple_arch_flag, self.apple_min_version_flag]
conf_flags = self._conanfile.conf.get("tools.build:cxxflags", default=[], check_type=list)
ret = ret + self.build_type_flags + apple_flags + conf_flags + self.extra_cxxflags
ret = ret + self.build_type_flags + apple_flags + self.extra_cxxflags + conf_flags
return self._filter_list_empty_fields(ret)

@property
Expand All @@ -123,7 +123,7 @@ def cflags(self):
ret = [self.arch_flag, fpic, self.msvc_runtime_flag, self.sysroot_flag]
apple_flags = [self.apple_isysroot_flag, self.apple_arch_flag, self.apple_min_version_flag]
conf_flags = self._conanfile.conf.get("tools.build:cflags", default=[], check_type=list)
ret = ret + self.build_type_flags + apple_flags + conf_flags + self.extra_cflags
ret = ret + self.build_type_flags + apple_flags + self.extra_cflags + conf_flags
return self._filter_list_empty_fields(ret)

@property
Expand All @@ -136,13 +136,13 @@ def ldflags(self):
check_type=list))
linker_scripts = self._conanfile.conf.get("tools.build:linker_scripts", default=[], check_type=list)
conf_flags.extend(["-T'" + linker_script + "'" for linker_script in linker_scripts])
ret = ret + apple_flags + conf_flags + self.build_type_link_flags + self.extra_ldflags
ret = ret + self.build_type_link_flags + apple_flags + self.extra_ldflags + conf_flags
return self._filter_list_empty_fields(ret)

@property
def defines(self):
conf_flags = self._conanfile.conf.get("tools.build:defines", default=[], check_type=list)
ret = [self.ndebug, self.gcc_cxx11_abi] + conf_flags + self.extra_defines
ret = [self.ndebug, self.gcc_cxx11_abi] + self.extra_defines + conf_flags
return self._filter_list_empty_fields(ret)

def environment(self):
Expand Down
37 changes: 37 additions & 0 deletions conans/test/integration/toolchains/gnu/test_autotoolstoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,43 @@ def test_extra_flags_via_conf():
assert 'export LDFLAGS="$LDFLAGS --flag5 --flag6"' in toolchain


def test_extra_flags_order():
client = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.gnu import AutotoolsToolchain
class Conan(ConanFile):
name = "pkg"
version = "0.1"
settings = "os", "arch", "build_type"
def generate(self):
at = AutotoolsToolchain(self)
at.extra_cxxflags = ["extra_cxxflags"]
at.extra_cflags = ["extra_cflags"]
at.extra_ldflags = ["extra_ldflags"]
at.extra_defines = ["extra_defines"]
at.generate()
""")
profile = textwrap.dedent("""
include(default)
[conf]
tools.build:cxxflags+=['cxxflags']
tools.build:cflags+=['cflags']
tools.build:sharedlinkflags+=['sharedlinkflags']
tools.build:exelinkflags+=['exelinkflags']
tools.build:defines+=['defines']
""")
client.save({"conanfile.py": conanfile, "profile": profile})
client.run('install . -pr=./profile')
toolchain = client.load("conanautotoolstoolchain{}".format('.bat' if platform.system() == "Windows" else '.sh'))

assert '-Dextra_defines -Ddefines' in toolchain
assert 'extra_cxxflags cxxflags' in toolchain
assert 'extra_cflags cflags' in toolchain
assert 'extra_ldflags sharedlinkflags exelinkflags' in toolchain


def test_autotools_custom_environment():
client = TestClient()
conanfile = textwrap.dedent("""
Expand Down

0 comments on commit 6326947

Please sign in to comment.