From dbd6857d32ba8774cf8ab9c6e7b9bfe0b34838c6 Mon Sep 17 00:00:00 2001 From: Peter Scheibel Date: Mon, 10 Feb 2025 22:34:28 -0800 Subject: [PATCH] spack compiler find: detect `flang-new` and `flang` in newer LLVM versions (#48914) --- .../builtin/packages/llvm/detection_test.yaml | 52 +++++++++++++++++++ .../repos/builtin/packages/llvm/package.py | 10 ++-- 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/var/spack/repos/builtin/packages/llvm/detection_test.yaml b/var/spack/repos/builtin/packages/llvm/detection_test.yaml index 860b3061d26..a189b585680 100644 --- a/var/spack/repos/builtin/packages/llvm/detection_test.yaml +++ b/var/spack/repos/builtin/packages/llvm/detection_test.yaml @@ -16,6 +16,58 @@ paths: c: ".*/bin/clang-3.9$" cxx: ".*/bin/clang[+][+]-3.9$" +# flang-new detection: flang-new generates slightly-different output than clang +- layout: + - executables: + - "bin/clang" + - "bin/clang++" + script: | + echo "clang version 19.1.6 (https://github.com/spack/spack.git 8d3a733b7798b6e33c371518b6dec298c3ebd8b1)" + echo "Target: x86_64-unknown-linux-gnu" + echo "Thread model: posix" + echo "InstalledDir: /path/to/spack/install/llvm/bin" + - executables: + - "bin/flang-new" + script: | + echo "flang-new version 19.1.6 (https://github.com/spack/spack.git 8d3a733b7798b6e33c371518b6dec298c3ebd8b1)" + echo "Target: x86_64-unknown-linux-gnu" + echo "Thread model: posix" + echo "InstalledDir: /path/to/spack/install/llvm/bin" + platforms: ["darwin", "linux"] + results: + - spec: 'llvm@19.1.6 +flang+clang~lld~lldb' + extra_attributes: + compilers: + c: ".*/bin/clang" + cxx: ".*/bin/clang[+][+]" + fortran: ".*/bin/flang-new" + +# flang: like previous test, but the fortran compiler is called "flang" vs. "flang-new" +- 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" + 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 135d5fd7aed..4d58c462377 100644 --- a/var/spack/repos/builtin/packages/llvm/package.py +++ b/var/spack/repos/builtin/packages/llvm/package.py @@ -753,19 +753,21 @@ def patch(self): string=True, ) + clang_and_friends = "(?:clang|flang|flang-new)" + compiler_version_regex = ( # Normal clang compiler versions are left as-is - r"clang version ([^ )\n]+)-svn[~.\w\d-]*|" + rf"{clang_and_friends} version ([^ )\n]+)-svn[~.\w\d-]*|" # Don't include hyphenated patch numbers in the version # (see https://github.com/spack/spack/pull/14365 for details) - r"clang version ([^ )\n]+?)-[~.\w\d-]*|" - r"clang version ([^ )\n]+)|" + rf"{clang_and_friends} version ([^ )\n]+?)-[~.\w\d-]*|" + rf"{clang_and_friends} version ([^ )\n]+)|" # LLDB r"lldb version ([^ )\n]+)|" # LLD r"LLD ([^ )\n]+) \(compatible with GNU linkers\)" ) - fortran_names = ["flang"] + fortran_names = ["flang", "flang-new"] @property def supported_languages(self):