Skip to content

Commit 3a5b534

Browse files
committed
Fix flags semantic
1 parent 3b89375 commit 3a5b534

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

lib/spack/spack/spec.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -775,19 +775,22 @@ def __init__(self, spec):
775775
self.spec = spec
776776

777777
def satisfies(self, other):
778-
return all(f in self and set(self[f]) == set(other[f]) for f in other)
778+
return all(f in self and self[f] == other[f] for f in other)
779779

780780
def intersects(self, other):
781-
if not all(set(self[f]) == set(other[f]) for f in other if (other[f] != [] and f in self)):
782-
return False
781+
common_types = set(self) & set(other)
782+
for flag_type in common_types:
783+
if not self[flag_type] or not other[flag_type]:
784+
# At least one of the two is empty
785+
continue
786+
787+
if self[flag_type] != other[flag_type]:
788+
return False
783789

784-
# Check that the propagation values match
785-
for flag_type in other:
786790
if not all(
787-
other[flag_type][i].propagate == self[flag_type][i].propagate
788-
for i in range(len(other[flag_type]))
789-
if flag_type in self
791+
f1.propagate == f2.propagate for f1, f2 in zip(self[flag_type], other[flag_type])
790792
):
793+
# At least one propagation flag didn't match
791794
return False
792795
return True
793796

lib/spack/spack/test/spec_semantics.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,9 @@ def test_constraining_abstract_specs_with_empty_intersection(self, lhs, rhs):
328328
("mpich", "mpich~~foo", True),
329329
("mpich", "mpich foo==1", True),
330330
# Flags semantics is currently different from other variant
331-
# ("mpich", 'mpich cppflags="-O3"', False),
331+
("mpich", 'mpich cflags="-O3"', True),
332+
("mpich cflags=-O3", 'mpich cflags="-O3 -Ofast"', False),
333+
("mpich cflags=-O2", 'mpich cflags="-O3"', False),
332334
("multivalue-variant foo=bar", "multivalue-variant +foo", False),
333335
("multivalue-variant foo=bar", "multivalue-variant ~foo", False),
334336
("multivalue-variant fee=bar", "multivalue-variant fee=baz", False),
@@ -457,22 +459,18 @@ def test_copy_satisfies_transitive(self):
457459
assert s.satisfies(copy[s.name])
458460
assert copy[s.name].satisfies(s)
459461

460-
def test_satisfies_virtual(self):
461-
# Don't use check_satisfies: it checks constrain() too, and
462-
# you can't constrain a non-virtual by a virtual.
462+
def test_intersects_virtual(self):
463463
assert Spec("mpich").intersects(Spec("mpi"))
464464
assert Spec("mpich2").intersects(Spec("mpi"))
465465
assert Spec("zmpi").intersects(Spec("mpi"))
466466

467-
def test_satisfies_virtual_dep_with_virtual_constraint(self):
468-
"""Ensure we can satisfy virtual constraints when there are multiple
469-
vdep providers in the specs."""
467+
def test_intersects_virtual_dep_with_virtual_constraint(self):
470468
assert Spec("netlib-lapack ^openblas").intersects("netlib-lapack ^openblas")
471469
assert not Spec("netlib-lapack ^netlib-blas").intersects("netlib-lapack ^openblas")
472470
assert not Spec("netlib-lapack ^openblas").intersects("netlib-lapack ^netlib-blas")
473471
assert Spec("netlib-lapack ^netlib-blas").intersects("netlib-lapack ^netlib-blas")
474472

475-
def test_satisfies_same_spec_with_different_hash(self):
473+
def test_intersectable_concrete_specs_must_have_the_same_hash(self):
476474
"""Ensure that concrete specs are matched *exactly* by hash."""
477475
s1 = Spec("mpileaks").concretized()
478476
s2 = s1.copy()
@@ -1195,15 +1193,15 @@ def test_package_hash_affects_dunder_and_dag_hash(mock_packages, default_mock_co
11951193
assert a1.process_hash() != a2.process_hash()
11961194

11971195

1198-
def test_satisfies_is_commutative_with_concrete_specs(default_mock_concretization):
1196+
def test_intersects_and_satisfies_on_concretized_spec(default_mock_concretization):
1197+
"""Test that a spec obtained by concretizing an abstract spec, satisfies the abstract spec
1198+
but not vice-versa.
1199+
"""
11991200
a1 = default_mock_concretization("[email protected]")
12001201
a2 = Spec("[email protected]")
12011202

1202-
# Spec.intersects is commutative.
12031203
assert a1.intersects(a2)
12041204
assert a2.intersects(a1)
1205-
1206-
# Spec.satisfies means set inclusion, which is not commutative.
12071205
assert a1.satisfies(a2)
12081206
assert not a2.satisfies(a1)
12091207

0 commit comments

Comments
 (0)