From 9e6e478ccf6a41eb6a4c26e46adbf1c007e6fb85 Mon Sep 17 00:00:00 2001 From: Massimiliano Culpo Date: Tue, 8 Apr 2025 09:12:34 +0200 Subject: [PATCH] llvm: don't detect +flang multiple times (#49876) fixes #49831 Signed-off-by: Massimiliano Culpo --- .../builtin/packages/llvm/detection_test.yaml | 28 +++++++++++++++++++ .../repos/builtin/packages/llvm/package.py | 12 ++++---- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/var/spack/repos/builtin/packages/llvm/detection_test.yaml b/var/spack/repos/builtin/packages/llvm/detection_test.yaml index a189b585680..482c0941d16 100644 --- a/var/spack/repos/builtin/packages/llvm/detection_test.yaml +++ b/var/spack/repos/builtin/packages/llvm/detection_test.yaml @@ -68,6 +68,34 @@ paths: cxx: ".*/bin/clang[+][+]" fortran: ".*/bin/flang" +# flang and flang-new in the same directory +- layout: + - executables: + - "bin/clang" + - "bin/clang++" + script: | + echo "clang version 20.1.0-rc1 (https://github.com/llvm/llvm-project af7f483a9d801252247b6c72e3763c1f55c5a506)" + echo "Target: x86_64-unknown-linux-gnu" + echo "Thread model: posix" + echo "InstalledDir: /tmp/clang/LLVM-20.1.0-rc1-Linux-X64/bin" + - executables: + - "bin/flang" + - "bin/flang-new" + script: | + echo "flang version 20.1.0-rc1 (https://github.com/llvm/llvm-project af7f483a9d801252247b6c72e3763c1f55c5a506)" + echo "Target: x86_64-unknown-linux-gnu" + echo "Thread model: posix" + echo "InstalledDir: /tmp/clang/LLVM-20.1.0-rc1-Linux-X64/bin" + platforms: ["darwin", "linux"] + results: + - spec: 'llvm@20.1.0 +flang+clang~lld~lldb' + extra_attributes: + compilers: + c: ".*/bin/clang" + cxx: ".*/bin/clang[+][+]" + fortran: ".*/bin/flang" + + # `~` and other weird characters in the version string - layout: - executables: diff --git a/var/spack/repos/builtin/packages/llvm/package.py b/var/spack/repos/builtin/packages/llvm/package.py index 4ee27a5d1f8..394dd852af8 100644 --- a/var/spack/repos/builtin/packages/llvm/package.py +++ b/var/spack/repos/builtin/packages/llvm/package.py @@ -801,7 +801,7 @@ def determine_version(cls, exe): def determine_variants(cls, exes, version_str): # Do not need to reuse more general logic from CompilerPackage # because LLVM has kindly named compilers - variants, compilers = ["+clang"], {} + variants, compilers = {"+clang"}, {} lld_found, lldb_found = False, False for exe in sorted(exes, key=len): name = os.path.basename(exe) @@ -809,18 +809,18 @@ def determine_variants(cls, exes, version_str): compilers.setdefault("cxx", exe) elif "clang" in name: compilers.setdefault("c", exe) - elif "flang" in name: - variants.append("+flang") + elif "flang" in name and "fortran" not in compilers: + variants.add("+flang") compilers.setdefault("fortran", exe) elif "ld.lld" in name: lld_found = True elif "lldb" in name: lldb_found = True - variants.append("+lld" if lld_found else "~lld") - variants.append("+lldb" if lldb_found else "~lldb") + variants.add("+lld" if lld_found else "~lld") + variants.add("+lldb" if lldb_found else "~lldb") - return "".join(variants), {"compilers": compilers} + return "".join(sorted(variants)), {"compilers": compilers} @classmethod def validate_detected_spec(cls, spec, extra_attributes):