Skip to content

Commit

Permalink
Merge remote-tracking branch 'alire/master' into feat/archive-downloa…
Browse files Browse the repository at this point in the history
…d-command
  • Loading branch information
mosteo committed Jan 9, 2025
2 parents fba20ae + 9d27d1d commit f43a0f7
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 18 deletions.
32 changes: 32 additions & 0 deletions doc/user-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,38 @@ file found in the user's home directory).

The default behavior is unchanged.

### Abbreviated `--tree` output for repeating dependencies

PR [#1814](https://github.com/alire-project/alire/pull/1814)

By default, repeated dependencies are now omitted by `--tree` output, e.g.:

```
$ alr show --tree libgpr2
...
Dependencies (tree):
gnat=14.1.3 (gnat_native) (>=14)
gnatcoll=25.0.0 (~25.0.0)
├── gnat=14.1.3 (gnat_native) (>=13)
└── libgpr=25.0.0 (~25.0.0)
├── gnat=14.1.3 (gnat_native) (/=2020)
└── xmlada=25.0.0 (~25.0.0)
└── gnat=14.1.3 (gnat_native) (>=11)
gnatcoll_gmp=25.0.0 (~25.0.0)
├── gnatcoll=25.0.0 (~25.0.0)
│ └── ...
└── libgmp=6.3.0 (*)
gnatcoll_iconv=25.0.0 (~25.0.0)
└── gnatcoll=25.0.0 (~25.0.0)
└── ...
```

Whenever '...' appears, it means that the preceding release has its
dependencies already printed somewhere in the preceding tree lines.

The old behavior can be obtained by increasing verbosity with the global `-v`
switch.

### Faster `alr search` without resolving dependencies

PR [#1799](https://github.com/alire-project/alire/pull/1799)
Expand Down
91 changes: 74 additions & 17 deletions src/alire/alire-solutions.adb
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,8 @@ package body Alire.Solutions is
procedure Print_Tree (This : Solution;
Root : Alire.Releases.Release;
Prefix : String := "";
Print_Root : Boolean := True)
Print_Root : Boolean := True;
Concise : Boolean := not Detailed)
is

Mid_Node : constant String :=
Expand All @@ -926,16 +927,62 @@ package body Alire.Solutions is
Branch : constant String :=
(if TTY.Color_Enabled then U ("") else "| ");
No_Branch : constant String := " ";
More_Deps : constant String := (Last_Node & "...");

Printed : AAA.Strings.Sets.Set;
-- Dependencies already printed, to avoid reprinting in Concise mode

-----------
-- Label --
-----------
-- The dependency Milestone or State
function Label (Dep : Dependencies.Dependency) return String
is (if This.State (Dep.Crate).Has_Release
then This.State (Dep.Crate).Milestone_Image
else This.State (Dep.Crate).TTY_Image);

---------------------
-- Already_Printed --
---------------------

function Already_Printed (Dep : Dependencies.Dependency) return Boolean
is (Printed.Contains (Label (Dep)));

-----------
-- Print --
-----------

procedure Print (Deps : Dependencies.Containers.Set;
Prefix : String := "";
Omit : Boolean := False)
-- Omit is used to remove the top-level connectors, for when the tree
-- is printed without the root release.
is

----------------------
-- Has_Dependencies --
----------------------

function Has_Dependencies (Dep : Dependencies.Dependency)
return Boolean
is (This.State (Dep.Crate).Has_Release
and then not Conditional.Enumerate
(This.State (Dep.Crate).Release.Dependencies).Is_Empty);

Last : UString;
-- Used to store the last dependency name in a subtree, to be able to
-- use the proper ASCII connector. See just below.

----------------------
-- Parent_Connector --
----------------------

function Parent_Connector (Dep : Dependencies.Dependency)
return String
is (if +Dep.Crate = +Last
then No_Branch -- End of this connector
else Branch); -- Continuation

begin

-- Find last printable dependency. This is related to OR trees, that
Expand Down Expand Up @@ -966,27 +1013,37 @@ package body Alire.Solutions is

-- For a dependency solved by a release, print exact
-- version. Otherwise print the state of the dependency.
& (if This.State (Dep.Crate).Has_Release
then This.State (Dep.Crate).Milestone_Image
else This.State (Dep.Crate).TTY_Image)
& Label (Dep)

-- And dependency that introduces the crate in the solution
& " (" & TTY.Emph (Dep.Versions.Image) & ")");

-- Recurse for further releases

if This.State (Dep.Crate).Has_Release then
Print (Conditional.Enumerate
(This.State (Dep.Crate).Release.Dependencies).To_Set,
Prefix =>
Prefix
-- Indent adding the proper running connector
& (if Omit
then ""
else (if +Dep.Crate = +Last
then No_Branch -- End of this connector
else Branch))); -- "│" over the subtree
-- Recurse for further releases, or print the concise marker

if
Concise
and then Already_Printed (Dep)
and then Has_Dependencies (Dep)
then
Trace.Always (Prefix
& Parent_Connector (Dep)
& More_Deps);
elsif
(not Concise or else not Printed.Contains (Label (Dep)))
and then Has_Dependencies (Dep)
then
Print
(Conditional.Enumerate
(This.State (Dep.Crate).Release.Dependencies).To_Set,
Prefix =>
Prefix
-- Indent adding the proper running connector
& (if Omit
then ""
else Parent_Connector (Dep)));
end if;

Printed.Include (Label (Dep));
end if;
end loop;
end Print;
Expand Down
4 changes: 3 additions & 1 deletion src/alire/alire-solutions.ads
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,11 @@ package Alire.Solutions is
procedure Print_Tree (This : Solution;
Root : Alire.Releases.Release;
Prefix : String := "";
Print_Root : Boolean := True);
Print_Root : Boolean := True;
Concise : Boolean := not Detailed);
-- Print the solution in tree form. If Print_Root, Root is printed too;
-- otherwise the tree is a forest starting at Root direct dependencies.
-- If Concise, print each unique dependency only once.

procedure Print_Versions (This : Solution;
Root : Roots.Root);
Expand Down
43 changes: 43 additions & 0 deletions testsuite/tests/with/tree-concise/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""
Test the concise mode of the --tree switch. Repeating dependencies are
substituted by a "..." ellipsis.
"""

import os
import re
from drivers.alr import run_alr, alr_with, init_local_crate
from drivers.asserts import assert_eq, assert_match

# Prepare a crate in which dependencies appear twice, so their dependencies in
# turn can be elided.

init_local_crate("yyy")
alr_with("hello")
os.chdir("..")
init_local_crate("xxx")
alr_with("hello")
alr_with("yyy", path="../yyy")

# Check the concise tree
assert_eq("""\
xxx=0.1.0-dev
+-- hello=1.0.1 (*)
| +-- libhello=1.0.0 (^1.0)
+-- yyy=0.1.0-dev (*)
+-- hello=1.0.1 (*)
+-- ...\
""",
run_alr("with", "--tree").out.strip())

# Check the regular tree
assert_match(".*" + re.escape("""\
xxx=0.1.0-dev
+-- hello=1.0.1 (*)
| +-- libhello=1.0.0 (^1.0)
+-- yyy=0.1.0-dev (*)
+-- hello=1.0.1 (*)
+-- libhello=1.0.0 (^1.0)\
"""),
run_alr("-v", "with", "--tree", quiet=False).out.strip())

print("SUCCESS")
5 changes: 5 additions & 0 deletions testsuite/tests/with/tree-concise/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: python-script
build_mode: both
indexes:
basic_index:
in_fixtures: true

0 comments on commit f43a0f7

Please sign in to comment.