Skip to content

Commit 20a2306

Browse files
authored
package hash: resolve package by namespace (spack#52777)
The package hash of a spec is supposed to describe the package.py it is concretized with, but both lookups that produce it went by name instead of fullname. Signed-off-by: Harmen Stoppels <me@harmenstoppels.nl>
1 parent 6c80165 commit 20a2306

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

lib/spack/spack/hash_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __repr__(self) -> str:
5656

5757

5858
def _content_hash_override(spec: "spack.spec.Spec") -> str:
59-
pkg_cls = spack.repo.PATH.get_pkg_class(spec.name)
59+
pkg_cls = spack.repo.PATH.get_pkg_class(spec.fullname)
6060
pkg = pkg_cls(spec)
6161
return pkg.content_hash()
6262

lib/spack/spack/test/util/package_hash.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import spack.concretize
1111
import spack.directives_meta
1212
import spack.paths
13+
import spack.repo
1314
import spack.util.package_hash as ph
1415
from spack.repo import RepoPath
1516
from spack.spec import Spec
@@ -116,6 +117,17 @@ def test_content_hash_not_concretized(mock_packages: RepoPath, config):
116117
compare_hash_sans_name(mock_packages, False, spec1, spec2)
117118

118119

120+
def test_package_hash_of_shadowed_package(mock_packages: RepoPath, config, repo_builder):
121+
"""The package hash must describe the package.py of the repository the spec names, also when
122+
a repository of higher precedence has a package of the same name."""
123+
repo_builder.add_package("pkg-c")
124+
with spack.repo.use_repositories(repo_builder.root, override=False):
125+
shadowing = Spec(f"{repo_builder.namespace}.pkg-c")
126+
shadowed = Spec("builtin_mock.pkg-c")
127+
128+
assert ph.package_hash(shadowing) != ph.package_hash(shadowed)
129+
130+
119131
def test_content_hash_different_variants(mock_packages: RepoPath, config):
120132
spec1 = spack.concretize.concretize_one("hash-test1@1.2 +variantx")
121133
spec2 = spack.concretize.concretize_one("hash-test2@1.2 ~variantx")

lib/spack/spack/util/package_hash.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def package_ast(
372372
source: Optionally provide a string to read python code from.
373373
"""
374374
if source is None:
375-
filename = spack.repo.PATH.filename_for_package_name(spec.name)
375+
filename = spack.repo.PATH.filename_for_package_name(spec.fullname)
376376
with open(filename, "rb") as f:
377377
source = f.read()
378378

0 commit comments

Comments
 (0)