diff options
author | Harmen Stoppels <harmenstoppels@gmail.com> | 2022-10-12 01:45:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-11 17:45:51 -0600 |
commit | 926dca9e5fa159201989ebef464984aab92716d2 (patch) | |
tree | 778431d8db8b633740e85222fff435feb27ae7f3 /lib | |
parent | 4b866e8ffc69d89064cf011675f63de12684ef76 (diff) | |
download | spack-926dca9e5fa159201989ebef464984aab92716d2.tar.gz spack-926dca9e5fa159201989ebef464984aab92716d2.tar.bz2 spack-926dca9e5fa159201989ebef464984aab92716d2.tar.xz spack-926dca9e5fa159201989ebef464984aab92716d2.zip |
Specify GCC prefix in LLVM-based compilers (#33146)
* spack.compiler.Compiler: introduce prefix property
We currently don't really have something that gives the GCC install
path, which is used by many LLVM-based compilers (llvm, llvm-amdgpu,
nvhpc, ...) to fix the GCC toolchain once and for all.
This `prefix` property is dynamic in the sense that it queries the
compiler itself. This is necessary because it's not easy to deduce the
install path from the `cc` property (might be a symlink, might be a
filename like `gcc` which works by having the compiler load a module
that sets the PATH variable, might be a generic compiler wrapper based
on environment variables like on cray...).
With this property introduced, we can clean up some recipes that have
the logic repeated for GCC.
* intel-oneapi-compilers: set --gcc-sysroot to %gcc prefix
Diffstat (limited to 'lib')
-rw-r--r-- | lib/spack/spack/compiler.py | 8 | ||||
-rw-r--r-- | lib/spack/spack/compilers/gcc.py | 21 |
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/spack/spack/compiler.py b/lib/spack/spack/compiler.py index 1e50749730..2e86309699 100644 --- a/lib/spack/spack/compiler.py +++ b/lib/spack/spack/compiler.py @@ -537,6 +537,14 @@ class Compiler(object): ) return self.extract_version_from_output(output) + @property + def prefix(self): + """Query the compiler for its install prefix. This is the install + path as reported by the compiler. Note that paths for cc, cxx, etc + are not enough to find the install prefix of the compiler, since + the can be symlinks, wrappers, or filenames instead of absolute paths.""" + raise NotImplementedError("prefix is not implemented for this compiler") + # # Compiler classes have methods for querying the version of # specific compiler executables. This is used when discovering compilers. diff --git a/lib/spack/spack/compilers/gcc.py b/lib/spack/spack/compilers/gcc.py index 011646c408..1b6eeaaa10 100644 --- a/lib/spack/spack/compilers/gcc.py +++ b/lib/spack/spack/compilers/gcc.py @@ -6,8 +6,11 @@ import os import re +from llnl.util.filesystem import ancestor + import spack.compiler import spack.compilers.apple_clang as apple_clang +import spack.util.executable from spack.version import ver @@ -196,3 +199,21 @@ class Gcc(spack.compiler.Compiler): @property def stdcxx_libs(self): return ("-lstdc++",) + + @property + def prefix(self): + # GCC reports its install prefix when running ``-print-search-dirs`` + # on the first line ``install: <prefix>``. + cc = spack.util.executable.Executable(self.cc) + with self.compiler_environment(): + gcc_output = cc("-print-search-dirs", output=str, error=str) + + for line in gcc_output.splitlines(): + if line.startswith("install:"): + gcc_prefix = line.split(":")[1].strip() + # Go from <prefix>/lib/gcc/<triplet>/<version>/ to <prefix> + return ancestor(gcc_prefix, 4) + + raise RuntimeError( + "could not find install prefix of GCC from output:\n\t{}".format(gcc_output) + ) |