Honor cmake_prefix_paths property if available (#42569)

* Honor package-specified cmake_prefix_paths at runtime

* Add paths in the correct order and prune duplicates

* Normalize paths for windows' sake
This commit is contained in:
Kyle Knoepfel 2025-02-27 12:11:22 -06:00 committed by GitHub
parent 24abc3294a
commit fe171a560b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 7 additions and 2 deletions

View File

@ -1234,6 +1234,10 @@ def _make_runnable(self, dep: spack.spec.Spec, env: EnvironmentModifications):
if os.path.isdir(bin_dir):
env.prepend_path("PATH", bin_dir)
for cp_dir in spack.build_systems.cmake.get_cmake_prefix_path(dep.package):
env.append_path("CMAKE_PREFIX_PATH", cp_dir)
env.prune_duplicate_paths("CMAKE_PREFIX_PATH")
def _setup_pkg_and_run(
serialized_pkg: "spack.subprocess_context.PackageInstallContext",

View File

@ -52,7 +52,8 @@ def test_load_shell(shell, set_command):
mpileaks_spec = spack.concretize.concretize_one("mpileaks")
# Ensure our reference variable is clean.
os.environ["CMAKE_PREFIX_PATH"] = "/hello" + os.pathsep + "/world"
hello_world_paths = [os.path.normpath(p) for p in ("/hello", "/world")]
os.environ["CMAKE_PREFIX_PATH"] = os.pathsep.join(hello_world_paths)
shell_out = load(shell, "mpileaks")
@ -69,7 +70,7 @@ def extract_value(output, variable):
paths_shell = extract_value(shell_out, "CMAKE_PREFIX_PATH")
# We should've prepended new paths, and keep old ones.
assert paths_shell[-2:] == ["/hello", "/world"]
assert paths_shell[-2:] == hello_world_paths
# All but the last two paths are added by spack load; lookup what packages they're from.
pkgs = [prefix_to_pkg(p) for p in paths_shell[:-2]]