From a4a35e123b7caac76271c9267ca19ae82ec1d028 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 13 Jan 2023 23:31:16 +0100 Subject: guix graph: 'guix graph --path' correctly handles multiple outputs. Previously, "guix graph -t references --path guix guile" would fail with: error: '--path' option requires exactly two nodes (given 2) This is because '_' in the 'match' clause wouldn't match the placeholder and would instead be interested as a variable name, thereby meaning NODES is expected to have two lists with the same tail. * guix/scripts/graph.scm (guix-graph): Rename '_' in 'mlet' to '_g' so that the literal '_' used in 'match' below matches. --- guix/scripts/graph.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'guix/scripts/graph.scm') diff --git a/guix/scripts/graph.scm b/guix/scripts/graph.scm index 2f102180c9..b31cc0014d 100644 --- a/guix/scripts/graph.scm +++ b/guix/scripts/graph.scm @@ -598,7 +598,7 @@ Emit a representation of the dependency graph of PACKAGE...\n")) (run-with-store store ;; XXX: Since grafting can trigger unsolicited builds, disable it. - (mlet %store-monad ((_ (set-grafting #f)) + (mlet %store-monad ((_g (set-grafting #f)) (nodes (mapm %store-monad (node-type-convert type) (reverse items)))) -- cgit v1.2.3 From 99e255d04ba154cea19ab7b3c8dc3014fd03b007 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 13 Jan 2023 23:38:18 +0100 Subject: guix graph: '--path' defaults to "out" in the case of multiple outputs. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, "guix graph -t references --graph guix guile" would fail with: no path from '/gnu/store/…-guix-1.4.0-1.9fe5b49' to '/gnu/store/…-guile-3.0.8-debug' simply because the "debug" happened to be the first one, getting bound to NODE2. With this change it will instead pick the "out" output of each. * guix/scripts/graph.scm (guix-graph)[shorter?, length-sorted]: New procedures. In the 'path?' case, use the latter to store node lists. --- guix/scripts/graph.scm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'guix/scripts/graph.scm') diff --git a/guix/scripts/graph.scm b/guix/scripts/graph.scm index b31cc0014d..6847dd1962 100644 --- a/guix/scripts/graph.scm +++ b/guix/scripts/graph.scm @@ -569,6 +569,12 @@ Emit a representation of the dependency graph of PACKAGE...\n")) (category packaging) (synopsis "view and query package dependency graphs") + (define (shorter? str1 str2) + (< (string-length str1) (string-length str2))) + + (define length-sorted + (cut sort <> shorter?)) + (with-error-handling (define opts (parse-command-line args %options @@ -603,8 +609,12 @@ Emit a representation of the dependency graph of PACKAGE...\n")) (node-type-convert type) (reverse items)))) (if (assoc-ref opts 'path?) + ;; Sort by string length such that, in case of multiple + ;; outputs, the shortest one (which corresponds to "out") is + ;; picked (yup, a hack). (match nodes - (((node1 _ ...) (node2 _ ...)) + (((= length-sorted (node1 _ ...)) + (= length-sorted (node2 _ ...))) (display-path node1 node2 type)) (_ (leave (G_ "'--path' option requires exactly two \ -- cgit v1.2.3