@@ -591,32 +591,18 @@ def file_matches(f: IO[bytes], regex: llnl.util.lang.PatternBytes) -> bool:
591591 f .seek (0 )
592592
593593
594- def deps_to_relocate (spec ):
595- """Return the transitive link and direct run dependencies of the spec.
596-
597- This is a special traversal for dependencies we need to consider when relocating a package.
598-
599- Package binaries, scripts, and other files may refer to the prefixes of dependencies, so
600- we need to rewrite those locations when dependencies are in a different place at install time
601- than they were at build time.
602-
603- This traversal covers transitive link dependencies and direct run dependencies because:
604-
605- 1. Spack adds RPATHs for transitive link dependencies so that packages can find needed
606- dependency libraries.
607- 2. Packages may call any of their *direct* run dependencies (and may bake their paths into
608- binaries or scripts), so we also need to search for run dependency prefixes when relocating.
609-
610- This returns a deduplicated list of transitive link dependencies and direct run dependencies.
611- """
612- deps = [
594+ def specs_to_relocate (spec : spack .spec .Spec ) -> List [spack .spec .Spec ]:
595+ """Return the set of specs that may be referenced in the install prefix of the provided spec.
596+ We currently include non-external transitive link and direct run dependencies."""
597+ specs = [
613598 s
614599 for s in itertools .chain (
615- spec .traverse (root = True , deptype = "link" ), spec .dependencies (deptype = "run" )
600+ spec .traverse (root = True , deptype = "link" , order = "breadth" , key = traverse .by_dag_hash ),
601+ spec .dependencies (deptype = "run" ),
616602 )
617603 if not s .external
618604 ]
619- return llnl .util .lang .dedupe (deps , key = lambda s : s .dag_hash ())
605+ return list ( llnl .util .lang .dedupe (specs , key = lambda s : s .dag_hash () ))
620606
621607
622608def get_buildinfo_dict (spec ):
@@ -630,7 +616,7 @@ def get_buildinfo_dict(spec):
630616 # "relocate_binaries": [],
631617 # "relocate_links": [],
632618 "hardlinks_deduped" : True ,
633- "hash_to_prefix" : {d .dag_hash (): str (d .prefix ) for d in deps_to_relocate (spec )},
619+ "hash_to_prefix" : {d .dag_hash (): str (d .prefix ) for d in specs_to_relocate (spec )},
634620 }
635621
636622
@@ -1112,7 +1098,7 @@ def _exists_in_buildcache(spec: spack.spec.Spec, tmpdir: str, out_url: str) -> E
11121098
11131099
11141100def prefixes_to_relocate (spec ):
1115- prefixes = [s .prefix for s in deps_to_relocate (spec )]
1101+ prefixes = [s .prefix for s in specs_to_relocate (spec )]
11161102 prefixes .append (spack .hooks .sbang .sbang_install_path ())
11171103 prefixes .append (str (spack .store .STORE .layout .root ))
11181104 return prefixes
@@ -2234,7 +2220,7 @@ def relocate_package(spec):
22342220 # An analog in this algorithm is any spec that shares a name or provides the same virtuals
22352221 # in the context of the relevant root spec. This ensures that the analog for a spec s
22362222 # is the spec that s replaced when we spliced.
2237- relocation_specs = deps_to_relocate (spec )
2223+ relocation_specs = specs_to_relocate (spec )
22382224 build_spec_ids = set (id (s ) for s in spec .build_spec .traverse (deptype = dt .ALL & ~ dt .BUILD ))
22392225 for s in relocation_specs :
22402226 analog = s
0 commit comments