Skip to content
Snippets Groups Projects
Unverified Commit 4a213667 authored by Massimiliano Culpo's avatar Massimiliano Culpo Committed by GitHub
Browse files

gcc: improve detection functions (#17988)

* Don't detect Apple's clang as gcc@4.2.1
* Avoid inspecting links except for Cray platforms
* Always return string paths from compiler properties
* Improved name-based filtering (apt-based packages)
parent f61b1410
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
import sys import sys
import llnl.util.tty as tty import llnl.util.tty as tty
import spack.architecture
import spack.util.executable import spack.util.executable
from spack.operating_systems.mac_os import macos_version, macos_sdk_path from spack.operating_systems.mac_os import macos_version, macos_sdk_path
...@@ -280,17 +281,43 @@ def executables(self): ...@@ -280,17 +281,43 @@ def executables(self):
def filter_detected_exes(cls, prefix, exes_in_prefix): def filter_detected_exes(cls, prefix, exes_in_prefix):
result = [] result = []
for exe in exes_in_prefix: for exe in exes_in_prefix:
# clang++ matches g++ -> clan[g++] # On systems like Ubuntu we might get multiple executables
if any(x in exe for x in ('clang', 'ranlib')): # with the string "gcc" in them. See:
# https://helpmanual.io/packages/apt/gcc/
basename = os.path.basename(exe)
substring_to_be_filtered = [
'c99-gcc',
'c89-gcc',
'-nm',
'-ar',
'ranlib',
'clang' # clang++ matches g++ -> clan[g++]
]
if any(x in basename for x in substring_to_be_filtered):
continue continue
# Filter out links in favor of real executables # Filter out links in favor of real executables on
if os.path.islink(exe): # all systems but Cray
host_platform = str(spack.architecture.platform())
if os.path.islink(exe) and host_platform != 'cray':
continue continue
result.append(exe) result.append(exe)
return result return result
@classmethod @classmethod
def determine_version(cls, exe): def determine_version(cls, exe):
try:
output = spack.compiler.get_compiler_version_output(
exe, '--version'
)
except Exception:
output = ''
# Apple's gcc is actually apple clang, so skip it.
# Users can add it manually to compilers.yaml at their own risk.
if 'Apple' in output:
return None
version_regex = re.compile(r'([\d\.]+)') version_regex = re.compile(r'([\d\.]+)')
for vargs in ('-dumpfullversion', '-dumpversion'): for vargs in ('-dumpfullversion', '-dumpversion'):
try: try:
...@@ -310,15 +337,15 @@ def determine_variants(cls, exes, version_str): ...@@ -310,15 +337,15 @@ def determine_variants(cls, exes, version_str):
languages, compilers = set(), {} languages, compilers = set(), {}
for exe in exes: for exe in exes:
basename = os.path.basename(exe) basename = os.path.basename(exe)
if 'gcc' in basename: if 'g++' in basename:
languages.add('c')
compilers['c'] = exe
elif 'g++' in basename:
languages.add('c++') languages.add('c++')
compilers['cxx'] = exe compilers['cxx'] = exe
elif 'gfortran' in basename: elif 'gfortran' in basename:
languages.add('fortran') languages.add('fortran')
compilers['fortran'] = exe compilers['fortran'] = exe
elif 'gcc' in basename:
languages.add('c')
compilers['c'] = exe
variant_str = 'languages={0}'.format(','.join(languages)) variant_str = 'languages={0}'.format(','.join(languages))
return variant_str, {'compilers': compilers} return variant_str, {'compilers': compilers}
...@@ -345,7 +372,10 @@ def cc(self): ...@@ -345,7 +372,10 @@ def cc(self):
assert self.spec.concrete, msg assert self.spec.concrete, msg
if self.spec.external: if self.spec.external:
return self.spec.extra_attributes['compilers'].get('c', None) return self.spec.extra_attributes['compilers'].get('c', None)
return self.spec.prefix.bin.gcc if 'languages=c' in self.spec else None result = None
if 'languages=c' in self.spec:
result = str(self.spec.prefix.bin.gcc)
return result
@property @property
def cxx(self): def cxx(self):
...@@ -366,7 +396,7 @@ def fortran(self): ...@@ -366,7 +396,7 @@ def fortran(self):
return self.spec.extra_attributes['compilers'].get('fortran', None) return self.spec.extra_attributes['compilers'].get('fortran', None)
result = None result = None
if 'languages=fortran' in self.spec: if 'languages=fortran' in self.spec:
result = self.spec.prefix.bin.gfortran result = str(self.spec.prefix.bin.gfortran)
return result return result
def url_for_version(self, version): def url_for_version(self, version):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment