Skip to content

Commit

Permalink
gcc: restore old detection (spack#45810)
Browse files Browse the repository at this point in the history
  • Loading branch information
alalazo authored Aug 21, 2024
1 parent e8a1364 commit 34df21b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 55 deletions.
43 changes: 22 additions & 21 deletions var/spack/repos/builtin/packages/gcc/detection_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,6 @@ paths:
cxx: ".*/bin/g[+][+]-5$"
fortran: ".*/bin/gfortran-5$"

# Multiple compilers present at the same time
- layout:
- executables:
- "bin/x86_64-linux-gnu-gcc-6"
script: 'echo 6.5.0'
- executables:
- "bin/x86_64-linux-gnu-gcc-10"
- "bin/x86_64-linux-gnu-g++-10"
script: "echo 10.1.0"
platforms: [darwin, linux]
results:
- spec: "gcc@6.5.0 languages=c"
extra_attributes:
compilers:
c: ".*/bin/x86_64-linux-gnu-gcc-6$"
- spec: "gcc@10.1.0 languages=c,c++"
extra_attributes:
compilers:
c: ".*/bin/x86_64-linux-gnu-gcc-10$"
cxx: ".*/bin/x86_64-linux-gnu-g[+][+]-10$"

# Apple clang under disguise as gcc should not be detected
- layout:
- executables:
Expand All @@ -94,3 +73,25 @@ paths:
fi
platforms: ["darwin"]
results: []

# Mingw cross compiler on linux should not be detected
- layout:
- executables:
- "bin/i686-w64-mingw32-gcc"
script: |
if [ "$1" = "-dumpversion" ] ; then
echo "9.3-win32"
elif [ "$1" = "-dumpfullversion" ] ; then
echo "9.3-win32" >&2
exit 1
elif [ "$1" = "--version" ] ; then
echo "i686-w64-mingw32-gcc (GCC) 9.3-win32 20200320"
echo "Copyright (C) 2019 Free Software Foundation, Inc."
echo "This is free software; see the source for copying conditions. There is NO"
echo "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
else
echo "mock executable got an unexpected flag: $1"
exit 1
fi
platforms: [linux]
results: []
49 changes: 15 additions & 34 deletions var/spack/repos/builtin/packages/gcc/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import os
import sys

from archspec.cpu import UnsupportedMicroarchitecture
import archspec.cpu

import llnl.util.tty as tty
from llnl.util.symlink import readlink
Expand Down Expand Up @@ -535,45 +535,26 @@ def supported_languages(self):
fortran_names = ["gfortran"]
d_names = ["gdc"]
go_names = ["gccgo"]
compiler_prefixes = [r"\w+-\w+-\w+-"]
compiler_suffixes = [r"-mp-\d+(?:\.\d+)?", r"-\d+(?:\.\d+)?", r"\d\d"]
compiler_version_regex = r"(?<!clang version)\s?([0-9.]+)"
compiler_version_argument = ("-dumpfullversion", "-dumpversion")

@classmethod
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.
if "Apple" in output:
return None

return super().determine_version(exe)

@classmethod
def filter_detected_exes(cls, prefix, exes_in_prefix):
result = []
for exe in exes_in_prefix:
# On systems like Ubuntu we might get multiple executables
# 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

result.append(exe)
# Apple's gcc is actually apple clang, so skip it.
if str(spack.platforms.host()) == "darwin":
not_apple_clang = []
for exe in exes_in_prefix:
try:
output = spack.compiler.get_compiler_version_output(exe, "--version")
except Exception:
output = ""
if "Apple" in output:
continue
not_apple_clang.append(exe)
return not_apple_clang

return result
return exes_in_prefix

@classmethod
def determine_variants(cls, exes, version_str):
Expand Down Expand Up @@ -702,7 +683,7 @@ def get_common_target_flags(self, spec):
for uarch in microarchitectures:
try:
return uarch.optimization_flags("gcc", str(spec.version))
except UnsupportedMicroarchitecture:
except archspec.cpu.UnsupportedMicroarchitecture:
pass
# no arch specific flags in common, unlikely to happen.
return ""
Expand Down

0 comments on commit 34df21b

Please sign in to comment.