From 34df21b62ccf023e672ca6cb9f8fcda4586df627 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Wed, 21 Aug 2024 11:31:52 +0200 Subject: gcc: restore old detection (#45810) --- .../repos/builtin/packages/gcc/detection_test.yaml | 43 +++++++++---------- var/spack/repos/builtin/packages/gcc/package.py | 49 +++++++--------------- 2 files changed, 37 insertions(+), 55 deletions(-) diff --git a/var/spack/repos/builtin/packages/gcc/detection_test.yaml b/var/spack/repos/builtin/packages/gcc/detection_test.yaml index 7269c0301c..ced4af1590 100644 --- a/var/spack/repos/builtin/packages/gcc/detection_test.yaml +++ b/var/spack/repos/builtin/packages/gcc/detection_test.yaml @@ -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: @@ -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: [] diff --git a/var/spack/repos/builtin/packages/gcc/package.py b/var/spack/repos/builtin/packages/gcc/package.py index d28209f04f..b4ca189159 100644 --- a/var/spack/repos/builtin/packages/gcc/package.py +++ b/var/spack/repos/builtin/packages/gcc/package.py @@ -7,7 +7,7 @@ import itertools import os import sys -from archspec.cpu import UnsupportedMicroarchitecture +import archspec.cpu import llnl.util.tty as tty from llnl.util.symlink import readlink @@ -535,45 +535,26 @@ class Gcc(AutotoolsPackage, GNUMirrorPackage, CompilerPackage): 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"(? 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): @@ -702,7 +683,7 @@ class Gcc(AutotoolsPackage, GNUMirrorPackage, CompilerPackage): 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 "" -- cgit v1.2.3-70-g09d2