Skip to content

Commit b4b1c5f

Browse files
authored
solver: catch invalid dependencies during concretization (#51176)
fixes #51146 fixes #51067 Improve error handling to detect and report cases where a caret in the input spec incorrectly references transitive build dependencies. Signed-off-by: Massimiliano Culpo <[email protected]>
1 parent d1cb70d commit b4b1c5f

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lib/spack/spack/solver/concretize.lp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ build_dependency_of_literal_node(LiteralNode, node(X, BuildDependency)) :-
193193
condition_set(node(min_dupe_id, Root), LiteralNode) :- literal_node(Root, LiteralNode).
194194
condition_set(LiteralNode, BuildNode) :- build_dependency_of_literal_node(LiteralNode, BuildNode).
195195

196+
% Generate a comprehensible error for cases like 'foo ^bar' where 'bar' is a build dependency
197+
% of a transitive dependency of 'foo'
198+
error(1, "{0} is not a direct 'build' or 'test' dependency, or transitive 'link' or 'run' dependency of any root", Literal)
199+
:- literal_node(RootPackage, node(X, Literal)),
200+
not depends_on(node(min_dupe_id, RootPackage), node(X, Literal)),
201+
not unification_set("root", node(X, Literal)).
202+
196203
:- build_dependency_of_literal_node(LiteralNode, BuildNode),
197204
not attr("depends_on", LiteralNode, BuildNode, "build").
198205

lib/spack/spack/test/concretization/core.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4052,3 +4052,12 @@ def test_selecting_externals_with_compilers_and_versions(
40524052
s = spack.concretize.concretize_one(spec_str)
40534053
assert s.external
40544054
assert s.prefix == "/path/mpich/gcc"
4055+
4056+
4057+
@pytest.mark.regression("51146,51067")
4058+
def test_caret_in_input_cannot_set_transitive_build_dependencies(default_mock_concretization):
4059+
"""Tests that a caret in the input spec does not set transitive build dependencies, and errors
4060+
with an appropriate message.
4061+
"""
4062+
with pytest.raises(spack.solver.asp.UnsatisfiableSpecError, match="transitive 'link' or"):
4063+
_ = default_mock_concretization("multivalue-variant ^gmake")

0 commit comments

Comments
 (0)