gcc: simplify setup_run_environment (#46505)

If the spec is external, it has extra attributes. If not, we know
which names are used. In both cases we don't need to search again
for executables.

Signed-off-by: Massimiliano Culpo <massimiliano.culpo@gmail.com>
This commit is contained in:
Massimiliano Culpo 2024-09-20 18:30:43 +02:00 committed by GitHub
parent 97961555dc
commit 14e8902854
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,7 +3,6 @@
# #
# SPDX-License-Identifier: (Apache-2.0 OR MIT) # SPDX-License-Identifier: (Apache-2.0 OR MIT)
import glob import glob
import itertools
import os import os
import sys import sys
@ -979,33 +978,15 @@ def write_specs_file(self):
tty.info(f"Wrote new spec file to {specs_file}") tty.info(f"Wrote new spec file to {specs_file}")
def setup_run_environment(self, env): def setup_run_environment(self, env):
# Search prefix directory for possibly modified compiler names if self.spec.satisfies("languages=c"):
from spack.compilers.gcc import Gcc as Compiler env.set("CC", self.cc)
# Get the contents of the installed binary directory if self.spec.satisfies("languages=cxx"):
bin_path = self.spec.prefix.bin env.set("CXX", self.cxx)
if not os.path.isdir(bin_path): if self.spec.satisfies("languages=fortran"):
return env.set("FC", self.fortran)
env.set("F77", self.fortran)
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)
# Skip broken symlinks (https://github.com/spack/spack/issues/41327)
if not os.path.exists(abspath):
continue
# Set the proper environment variable
env.set(lang.upper(), abspath)
# Stop searching filename/regex combos for this language
break
def detect_gdc(self): def detect_gdc(self):
"""Detect and return the path to GDC that belongs to the same instance of GCC that is used """Detect and return the path to GDC that belongs to the same instance of GCC that is used