audit: detect self-referential depends_on (#42456)
This commit is contained in:
parent
2a01e9679a
commit
cb3c014a43
@ -796,13 +796,33 @@ def check_virtual_with_variants(spec, msg):
|
|||||||
except spack.repo.UnknownPackageError:
|
except spack.repo.UnknownPackageError:
|
||||||
# This dependency is completely missing, so report
|
# This dependency is completely missing, so report
|
||||||
# and continue the analysis
|
# and continue the analysis
|
||||||
summary = (
|
summary = f"{pkg_name}: unknown package '{dep_name}' in 'depends_on' directive"
|
||||||
f"{pkg_name}: unknown package '{dep_name}' in " "'depends_on' directive"
|
|
||||||
)
|
|
||||||
details = [f" in {filename}"]
|
details = [f" in {filename}"]
|
||||||
errors.append(error_cls(summary=summary, details=details))
|
errors.append(error_cls(summary=summary, details=details))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
# Check for self-referential specs similar to:
|
||||||
|
#
|
||||||
|
# depends_on("foo@X.Y", when="^foo+bar")
|
||||||
|
#
|
||||||
|
# That would allow clingo to choose whether to have foo@X.Y+bar in the graph.
|
||||||
|
problematic_edges = [
|
||||||
|
x for x in when.edges_to_dependencies(dep_name) if not x.virtuals
|
||||||
|
]
|
||||||
|
if problematic_edges and not dep.patches:
|
||||||
|
summary = (
|
||||||
|
f"{pkg_name}: dependency on '{dep.spec}' when '{when}' is self-referential"
|
||||||
|
)
|
||||||
|
details = [
|
||||||
|
(
|
||||||
|
f" please specify better using '^[virtuals=...] {dep_name}', or "
|
||||||
|
f"substitute with an equivalent condition on '{pkg_name}'"
|
||||||
|
),
|
||||||
|
f" in {filename}",
|
||||||
|
]
|
||||||
|
errors.append(error_cls(summary=summary, details=details))
|
||||||
|
continue
|
||||||
|
|
||||||
# check variants
|
# check variants
|
||||||
dependency_variants = dep.spec.variants
|
dependency_variants = dep.spec.variants
|
||||||
for name, value in dependency_variants.items():
|
for name, value in dependency_variants.items():
|
||||||
|
Loading…
Reference in New Issue
Block a user