From 0663ac36336498bb3d99336f9e56e82fdd091d20 Mon Sep 17 00:00:00 2001 From: Tom Scogland Date: Mon, 6 Nov 2023 11:39:31 -0800 Subject: [PATCH] compilers set in run env shouldn't impact build Adds `drop` to EnvironmentModifications courtesy of @haampie, and uses it to clear modifications of CC, CXX, F77 and FC made by `setup_{,dependent_}run_environment` routines when producing an environment in BUILD context. --- lib/spack/spack/build_environment.py | 11 +++++++++-- lib/spack/spack/util/environment.py | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py index 3f6830ad334..76080185415 100644 --- a/lib/spack/spack/build_environment.py +++ b/lib/spack/spack/build_environment.py @@ -1016,10 +1016,17 @@ def get_env_modifications(self) -> EnvironmentModifications: self._make_runnable(dspec, env) if self.should_setup_run_env & flag: + run_env_mods = EnvironmentModifications() for spec in dspec.dependents(deptype=dt.LINK | dt.RUN): if id(spec) in self.nodes_in_subdag: - pkg.setup_dependent_run_environment(env, spec) - pkg.setup_run_environment(env) + pkg.setup_dependent_run_environment(run_env_mods, spec) + pkg.setup_run_environment(run_env_mods) + run_env_dict = run_env_mods.group_by_name() + if self.context == Context.BUILD: + run_env_mods.drop("CC", "CXX", "F77", "FC") + env.extend(run_env_mods) + + return env def _make_buildtime_detectable(self, dep: spack.spec.Spec, env: EnvironmentModifications): diff --git a/lib/spack/spack/util/environment.py b/lib/spack/spack/util/environment.py index 246df65cb88..d4c352b9935 100644 --- a/lib/spack/spack/util/environment.py +++ b/lib/spack/spack/util/environment.py @@ -596,6 +596,14 @@ def group_by_name(self) -> Dict[str, ModificationList]: modifications[item.name].append(item) return modifications + def drop(self, *name) -> bool: + """Drop all modifications to the variable with the given name.""" + old_mods = self.env_modifications + new_mods = [x for x in self.env_modifications if x.name not in name] + self.env_modifications = new_mods + + return len(old_mods) != len(new_mods) + def is_unset(self, variable_name: str) -> bool: """Returns True if the last modification to a variable is to unset it, False otherwise.""" modifications = self.group_by_name()