Fix GCC environment variables for external installations (#12454)
Unlike the compiler binary name search logic, the `setup_environment` in GCC's package assumes the compiler names are *exactly* `gcc`, `g++`, etc. In many external installations (Homebrew, Macports) the installation includes only *suffixed* versions such as `gcc-9`. This patch uses the GCC compiler search suffixes to actually locate the correct filenames for the installed compilers, allowing the Spack-generated module file to have useful definitions of CC, CXX, etc. It also allows for the possibility that the user's external installation of GCC is compiled without Fortran support, in which case the `FC` environment variables are not defined.
This commit is contained in:
parent
139eaa1306
commit
7bcb306d4a
1 changed files with 25 additions and 5 deletions
|
@ -8,6 +8,7 @@
|
||||||
from llnl.util import tty
|
from llnl.util import tty
|
||||||
|
|
||||||
import glob
|
import glob
|
||||||
|
import itertools
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -420,8 +421,27 @@ def write_rpath_specs(self):
|
||||||
set_install_permissions(specs_file)
|
set_install_permissions(specs_file)
|
||||||
|
|
||||||
def setup_environment(self, spack_env, run_env):
|
def setup_environment(self, spack_env, run_env):
|
||||||
run_env.set('CC', join_path(self.spec.prefix.bin, 'gcc'))
|
# Search prefix directory for possibly modified compiler names
|
||||||
run_env.set('CXX', join_path(self.spec.prefix.bin, 'g++'))
|
from spack.compilers.gcc import Gcc as Compiler
|
||||||
run_env.set('FC', join_path(self.spec.prefix.bin, 'gfortran'))
|
|
||||||
run_env.set('F77', join_path(self.spec.prefix.bin, 'gfortran'))
|
# Get the contents of the installed binary directory
|
||||||
run_env.set('F90', join_path(self.spec.prefix.bin, 'gfortran'))
|
bin_path = self.spec.prefix.bin
|
||||||
|
bin_contents = os.listdir(bin_path)
|
||||||
|
|
||||||
|
# Find the first non-symlink compiler binary present for each language
|
||||||
|
for lang in ['cc', 'cxx', 'fc', 'f77']:
|
||||||
|
for filename, regexp in itertools.product(
|
||||||
|
bin_contents,
|
||||||
|
Compiler.search_regexps(lang)
|
||||||
|
):
|
||||||
|
if not regexp.match(filename):
|
||||||
|
continue
|
||||||
|
|
||||||
|
abspath = os.path.join(bin_path, filename)
|
||||||
|
if os.path.islink(abspath):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Set the proper environment variable
|
||||||
|
run_env.set(lang.upper(), abspath)
|
||||||
|
# Stop searching filename/regex combos for this language
|
||||||
|
break
|
||||||
|
|
Loading…
Reference in a new issue