summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/build_environment.py11
-rw-r--r--lib/spack/spack/test/build_environment.py15
-rw-r--r--lib/spack/spack/util/environment.py8
3 files changed, 32 insertions, 2 deletions
diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py
index 3f6830ad33..4c4eca6567 100644
--- a/lib/spack/spack/build_environment.py
+++ b/lib/spack/spack/build_environment.py
@@ -1016,10 +1016,17 @@ class SetupContext:
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)
+ if self.context == Context.BUILD:
+ # Don't let the runtime environment of comiler like dependencies leak into the
+ # build env
+ 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/test/build_environment.py b/lib/spack/spack/test/build_environment.py
index f2bf740272..cbccbc429e 100644
--- a/lib/spack/spack/test/build_environment.py
+++ b/lib/spack/spack/test/build_environment.py
@@ -652,3 +652,18 @@ def test_monkey_patching_works_across_virtual(default_mock_concretization):
s["mpich"].foo = "foo"
assert s["mpich"].foo == "foo"
assert s["mpi"].foo == "foo"
+
+
+def test_clear_compiler_related_runtime_variables_of_build_deps(default_mock_concretization):
+ """Verify that Spack drops CC, CXX, FC and F77 from the dependencies related build environment
+ variable changes if they are set in setup_run_environment. Spack manages those variables
+ elsewhere."""
+ s = default_mock_concretization("build-env-compiler-var-a")
+ ctx = spack.build_environment.SetupContext(s, context=Context.BUILD)
+ result = {}
+ ctx.get_env_modifications().apply_modifications(result)
+ assert "CC" not in result
+ assert "CXX" not in result
+ assert "FC" not in result
+ assert "F77" not in result
+ assert result["ANOTHER_VAR"] == "this-should-be-present"
diff --git a/lib/spack/spack/util/environment.py b/lib/spack/spack/util/environment.py
index 246df65cb8..d4c352b993 100644
--- a/lib/spack/spack/util/environment.py
+++ b/lib/spack/spack/util/environment.py
@@ -596,6 +596,14 @@ class EnvironmentModifications:
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()