Skip to content

Commit

Permalink
AutotoolsToolchain passing always the compiler to _get_gnu_triplet fu…
Browse files Browse the repository at this point in the history
…cntion
  • Loading branch information
franramirez688 committed Dec 7, 2021
1 parent 21617e5 commit d6fa4d4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
6 changes: 4 additions & 2 deletions conan/tools/gnu/autotoolstoolchain.py
Expand Up @@ -12,6 +12,7 @@
class AutotoolsToolchain:
def __init__(self, conanfile, namespace=None):
self._conanfile = conanfile

self._namespace = namespace
build_type = self._conanfile.settings.get_safe("build_type")

Expand Down Expand Up @@ -49,8 +50,9 @@ def __init__(self, conanfile, namespace=None):
self.apple_min_version_flag = apple_min_version_flag(self._conanfile)
if cross_building(self._conanfile):
os_build, arch_build, os_host, arch_host = get_cross_building_settings(self._conanfile)
self._host = _get_gnu_triplet(os_host, arch_host)
self._build = _get_gnu_triplet(os_build, arch_build)
compiler = self._conanfile.settings.get_safe("compiler")
self._host = _get_gnu_triplet(os_host, arch_host, compiler=compiler)
self._build = _get_gnu_triplet(os_build, arch_build, compiler=compiler)

# Apple Stuff
if os_build == "Macos":
Expand Down
1 change: 0 additions & 1 deletion conans/test/unittests/tools/gnu/autotools_test.py
@@ -1,5 +1,4 @@
import os
import textwrap

from conan.tools.files import save_toolchain_args
from conan.tools.gnu import Autotools
Expand Down
43 changes: 43 additions & 0 deletions conans/test/unittests/tools/gnu/autotoolschain_test.py
@@ -0,0 +1,43 @@
import pytest

from conan.tools.gnu import AutotoolsToolchain
from conans.errors import ConanException
from conans.test.utils.mocks import ConanFileMock, MockSettings


def test_get_gnu_triplet_for_cross_building():
"""
Testing AutotoolsToolchain and _get_gnu_triplet() function in case of
having os=Windows and cross compiling
"""
# Issue: https://github.com/conan-io/conan/issues/10139
settings = MockSettings({"build_type": "Release",
"compiler": "gcc",
"compiler.version": "10.2",
"os": "Windows",
"arch": "x86_64"})
conanfile = ConanFileMock()
conanfile.settings = settings
conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"})
autotoolschain = AutotoolsToolchain(conanfile)
assert autotoolschain._host == "x86_64-w64-mingw32"
assert autotoolschain._build == "i686-solaris"


def test_get_gnu_triplet_for_cross_building_raise_error():
"""
Testing AutotoolsToolchain and _get_gnu_triplet() function raises an error in case of
having os=Windows, cross compiling and not defined any compiler
"""
# Issue: https://github.com/conan-io/conan/issues/10139
settings = MockSettings({"build_type": "Release",
"os": "Windows",
"arch": "x86_64"})
conanfile = ConanFileMock()
conanfile.settings = settings
conanfile.settings_build = MockSettings({"os": "Solaris", "arch": "x86"})
with pytest.raises(ConanException) as conan_error:
AutotoolsToolchain(conanfile)
msg = "'compiler' parameter for 'get_gnu_triplet()' is not specified and " \
"needed for os=Windows"
assert msg == str(conan_error.value)

0 comments on commit d6fa4d4

Please sign in to comment.