Skip to content

Commit e9ee9ea

Browse files
scheibelptgamblin
authored andcommitted
patching: do strict version range checking (#13989)
* apply strict constraint checks for patches, otherwise Spack may incorrectly treat a version range constraint as satisfied when mixing x.y and x.y.z versions * add mixed version checks to version comparison tests
1 parent 55ee2ae commit e9ee9ea

5 files changed

Lines changed: 23 additions & 2 deletions

File tree

lib/spack/spack/spec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,7 @@ def concretize(self, tests=False):
21822182
# Add any patches from the package to the spec.
21832183
patches = []
21842184
for cond, patch_list in s.package_class.patches.items():
2185-
if s.satisfies(cond):
2185+
if s.satisfies(cond, strict=True):
21862186
for patch in patch_list:
21872187
patches.append(patch)
21882188
if patches:
@@ -2201,7 +2201,7 @@ def concretize(self, tests=False):
22012201

22022202
patches = []
22032203
for cond, dependency in pkg_deps[dspec.spec.name].items():
2204-
if dspec.parent.satisfies(cond):
2204+
if dspec.parent.satisfies(cond, strict=True):
22052205
for pcond, patch_list in dependency.patches.items():
22062206
if dspec.spec.satisfies(pcond):
22072207
for patch in patch_list:

lib/spack/spack/test/patch.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
foo_sha256 = 'b5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c'
2525
bar_sha256 = '7d865e959b2466918c9863afca942d0fb89d7c9ac0c99bafc3749504ded97730'
2626
baz_sha256 = 'bf07a7fbb825fc0aae7bf4a1177b2b31fcf8a3feeaf7092761e18c859ee52a9c'
27+
biz_sha256 = 'a69b288d7393261e613c276c6d38a01461028291f6e381623acc58139d01f54d'
2728

2829
# url patches
2930
url1_sha256 = 'abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234abcd1234'
@@ -105,6 +106,20 @@ def test_patch_in_spec(mock_packages, config):
105106
tuple(spec.variants['patches']._patches_in_order_of_appearance))
106107

107108

109+
def test_patch_mixed_versions_subset_constraint(mock_packages, config):
110+
"""If we have a package with mixed x.y and x.y.z versions, make sure that
111+
a patch applied to a version range of x.y.z versions is not applied to
112+
an x.y version.
113+
"""
114+
spec1 = Spec('patch@1.0.1')
115+
spec1.concretize()
116+
assert biz_sha256 in spec1.variants['patches'].value
117+
118+
spec2 = Spec('patch@1.0')
119+
spec2.concretize()
120+
assert biz_sha256 not in spec2.variants['patches'].value
121+
122+
108123
def test_patch_order(mock_packages, config):
109124
spec = Spec('dep-diamond-patch-top')
110125
spec.concretize()

lib/spack/spack/test/versions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ def test_contains():
266266
assert_in('1.3.5-7', '1.2:1.4')
267267
assert_not_in('1.1', '1.2:1.4')
268268
assert_not_in('1.5', '1.2:1.4')
269+
assert_not_in('1.5', '1.5.1:1.6')
270+
assert_not_in('1.5', '1.5.1:')
269271

270272
assert_in('1.4.2', '1.2:1.4')
271273
assert_not_in('1.4.2', '1.2:1.4.0')
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this patch is never applied, it is used to check spec semantics on when the concretizer chooses to include a patch

var/spack/repos/builtin.mock/packages/patch/package.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@ class Patch(Package):
1313
url = "http://www.example.com/patch-1.0.tar.gz"
1414

1515
version('1.0', '0123456789abcdef0123456789abcdef')
16+
version('1.0.1')
17+
version('1.0.2')
1618
version('2.0', '0123456789abcdef0123456789abcdef')
1719

1820
patch('foo.patch')
1921
patch('bar.patch', when='@2:')
2022
patch('baz.patch')
23+
patch('biz.patch', when='@1.0.1:1.0.2')
2124

2225
def install(self, spec, prefix):
2326
pass

0 commit comments

Comments
 (0)