From fe171a560b4f7b55a4e40feaebaf5c0bc9ff8193 Mon Sep 17 00:00:00 2001 From: Kyle Knoepfel Date: Thu, 27 Feb 2025 12:11:22 -0600 Subject: [PATCH] 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 --- lib/spack/spack/build_environment.py | 4 ++++ lib/spack/spack/test/cmd/load.py | 5 +++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/spack/spack/build_environment.py b/lib/spack/spack/build_environment.py index 3e1663131c0..e44cc40d553 100644 --- a/lib/spack/spack/build_environment.py +++ b/lib/spack/spack/build_environment.py @@ -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", diff --git a/lib/spack/spack/test/cmd/load.py b/lib/spack/spack/test/cmd/load.py index 125a8ed0325..58fc8a2b4c1 100644 --- a/lib/spack/spack/test/cmd/load.py +++ b/lib/spack/spack/test/cmd/load.py @@ -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]]