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

2231 conan compiler detection #2487

Merged
merged 14 commits into from
Feb 26, 2018
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
15 changes: 14 additions & 1 deletion conans/client/conf/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ def _execute(command):


def _gcc_compiler(output, compiler_exe="gcc"):

try:
if platform.system() == "Darwin":
# In Mac OS X check if gcc is a fronted using apple-clang
_, out = _execute("%s --version" % compiler_exe)
out = out.lower()
if "clang" in out:
return None

_, out = _execute('%s -dumpversion' % compiler_exe)
compiler = "gcc"
installed_version = re.search("([0-9](\.[0-9])?)", out).group()
Expand Down Expand Up @@ -147,7 +155,12 @@ def _get_default_compiler(output):
output.info("CC and CXX: %s, %s " % (cc or "None", cxx or "None"))
command = cc or cxx
if "gcc" in command:
return _gcc_compiler(output, command)
gcc = _gcc_compiler(output, command)
if platform.system() == "Darwin" and gcc is None:
output.error(
"%s detected as a frontend using apple-clang. Compiler not supported" % command
)
return gcc
if "clang" in command.lower():
return _clang_compiler(output, command)
if platform.system() == "SunOS" and command.lower() == "cc":
Expand Down
52 changes: 45 additions & 7 deletions conans/test/util/detect_test.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
import platform
import subprocess
import unittest
from conans.test.utils.tools import TestBufferConanOutput

from conans import tools
from conans.client.conf.detect import detect_defaults_settings
import platform
from conans.test.utils.tools import TestBufferConanOutput


class DetectTest(unittest.TestCase):

def detect_test(self):
def detect_default_compilers_test(self):
platform_default_compilers = {
"Linux": "gcc",
"Darwin": "apple-clang",
"Windows": "Visual Studio"
}
output = TestBufferConanOutput()
result = detect_defaults_settings(output)
if platform.system() == "Linux":
for (name, value) in result:
if name == "compiler":
self.assertEquals(value, "gcc")
# result is a list of tuples (name, value) so converting it to dict
result = dict(result)
platform_compiler = platform_default_compilers.get(platform.system(), None)
if platform_compiler is not None:
self.assertEquals(result.get("compiler", None), platform_compiler)

def detect_default_in_mac_os_using_gcc_as_default_test(self):
"""
Test if gcc in Mac OS X is using apple-clang as frontend
"""
# See: https://github.com/conan-io/conan/issues/2231
if platform.system() != "Darwin":
return

try:
output = subprocess.check_output(["gcc", "--version"], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError:
# gcc is not installed or there is any error (no test scenario)
return

if b"clang" not in output:
# Not test scenario gcc should display clang in output
# see: https://stackoverflow.com/questions/19535422/os-x-10-9-gcc-links-to-clang
raise Exception("Apple gcc doesn't point to clang with gcc frontend anymore! please check")

output = TestBufferConanOutput()
with tools.environment_append({"CC": "gcc"}):
result = detect_defaults_settings(output)
# result is a list of tuples (name, value) so converting it to dict
result = dict(result)
# No compiler should be detected
self.assertIsNone(result.get("compiler", None))
self.assertIn("gcc detected as a frontend using apple-clang", output)
self.assertIsNotNone(output.error)