summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHarmen Stoppels <me@harmenstoppels.nl>2024-07-08 18:25:57 +0200
committerGitHub <noreply@github.com>2024-07-08 18:25:57 +0200
commita04b12a3ef1ba0e31c6a43332920a596b8b0660e (patch)
treea0cce39f49f26aabc8cee3eee5def93b10c60834 /lib
parentcbf8f2326d6aaae89d6769df3f3f7627cf80e18c (diff)
downloadspack-a04b12a3ef1ba0e31c6a43332920a596b8b0660e.tar.gz
spack-a04b12a3ef1ba0e31c6a43332920a596b8b0660e.tar.bz2
spack-a04b12a3ef1ba0e31c6a43332920a596b8b0660e.tar.xz
spack-a04b12a3ef1ba0e31c6a43332920a596b8b0660e.zip
spec.py: print right deptype in tree (#45091)
Fix a bug where Spec.tree with cover=nodes reduces deptypes from all in-edges, including from nodes not reachable from the root, which almost always happens for concrete specs
Diffstat (limited to 'lib')
-rw-r--r--lib/spack/spack/spec.py12
-rw-r--r--lib/spack/spack/test/spec_dag.py25
2 files changed, 32 insertions, 5 deletions
diff --git a/lib/spack/spack/spec.py b/lib/spack/spack/spec.py
index 0e00e03e98..78477a8894 100644
--- a/lib/spack/spack/spec.py
+++ b/lib/spack/spack/spec.py
@@ -1332,6 +1332,12 @@ def tree(
if color is None:
color = clr.get_color_when()
+ # reduce deptypes over all in-edges when covering nodes
+ if show_types and cover == "nodes":
+ deptype_lookup: Dict[str, dt.DepFlag] = collections.defaultdict(dt.DepFlag)
+ for edge in traverse.traverse_edges(specs, cover="edges", deptype=deptypes, root=False):
+ deptype_lookup[edge.spec.dag_hash()] |= edge.depflag
+
for d, dep_spec in traverse.traverse_tree(
sorted(specs), cover=cover, deptype=deptypes, depth_first=depth_first, key=key
):
@@ -1358,11 +1364,7 @@ def tree(
if show_types:
if cover == "nodes":
- # when only covering nodes, we merge dependency types
- # from all dependents before showing them.
- depflag = 0
- for ds in node.edges_from_dependents():
- depflag |= ds.depflag
+ depflag = deptype_lookup[dep_spec.spec.dag_hash()]
else:
# when covering edges or paths, we show dependency
# types only for the edge through which we visited
diff --git a/lib/spack/spack/test/spec_dag.py b/lib/spack/spack/test/spec_dag.py
index 39e9ff66a1..c3126d3c29 100644
--- a/lib/spack/spack/test/spec_dag.py
+++ b/lib/spack/spack/test/spec_dag.py
@@ -978,6 +978,31 @@ class TestSpecDag:
assert "version-test-pkg" not in out
+def test_tree_cover_nodes_reduce_deptype():
+ """Test that tree output with deptypes sticks to the sub-dag of interest, instead of looking
+ at in-edges from nodes not reachable from the root."""
+ a, b, c, d = Spec("a"), Spec("b"), Spec("c"), Spec("d")
+ a.add_dependency_edge(d, depflag=dt.BUILD, virtuals=())
+ a.add_dependency_edge(b, depflag=dt.LINK, virtuals=())
+ b.add_dependency_edge(d, depflag=dt.LINK, virtuals=())
+ c.add_dependency_edge(d, depflag=dt.RUN | dt.TEST, virtuals=())
+ assert (
+ a.tree(cover="nodes", show_types=True)
+ == """\
+[ ] a
+[ l ] ^b
+[bl ] ^d
+"""
+ )
+ assert (
+ c.tree(cover="nodes", show_types=True)
+ == """\
+[ ] c
+[ rt] ^d
+"""
+ )
+
+
def test_synthetic_construction_of_split_dependencies_from_same_package(mock_packages, config):
# Construct in a synthetic way (i.e. without using the solver)
# the following spec: