summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/contributing.texi4
-rw-r--r--doc/guix.texi27
-rw-r--r--guix/scripts/build.scm56
-rw-r--r--tests/guix-build.sh6
4 files changed, 90 insertions, 3 deletions
diff --git a/doc/contributing.texi b/doc/contributing.texi
index e7465fc259a..6be879fa669 100644
--- a/doc/contributing.texi
+++ b/doc/contributing.texi
@@ -1915,7 +1915,9 @@ according to the project's conventions (@pxref{Invoking guix style}).
1915 1915
1916@item 1916@item
1917Make sure the package builds on your platform, using @command{guix build 1917Make sure the package builds on your platform, using @command{guix build
1918@var{package}}. 1918@var{package}}. Also build at least its direct dependents with
1919@command{guix build --dependents=1 @var{package}}
1920(@pxref{build-dependents, @command{guix build}}).
1919 1921
1920@item 1922@item
1921We recommend you also try building the package on other supported 1923We recommend you also try building the package on other supported
diff --git a/doc/guix.texi b/doc/guix.texi
index f8eefa365b2..ba9b75f3705 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -13639,6 +13639,31 @@ cross-compile all the dependencies of the given package when it is built
13639natively. 13639natively.
13640@end quotation 13640@end quotation
13641 13641
13642@cindex dependents of a package, building them
13643@cindex building the dependents of a package
13644@anchor{build-dependents}
13645@item --dependents[=@var{depth}]
13646@itemx -P [@var{depth}]
13647Build the dependents of the following package. By default, build all
13648the direct and indirect dependents; when @var{depth} is provided, limit
13649to dependents at that distance: 1 for direct dependents, 2 for
13650dependents of dependents, and so on.
13651
13652For example, the command below builds @emph{all} the dependents of libgit2:
13653
13654@example
13655guix build --dependents libgit2
13656@end example
13657
13658To build all the packages that directly depend on NumPy, run:
13659
13660@example
13661guix build -P1 python-numpy
13662@end example
13663
13664The list of dependents is computed in the same way as with @command{guix
13665refresh --list-dependent} (@pxref{Invoking guix refresh}).
13666
13642@item --source 13667@item --source
13643@itemx -S 13668@itemx -S
13644Build the source derivations of the packages, rather than the packages 13669Build the source derivations of the packages, rather than the packages
@@ -15142,6 +15167,8 @@ result of upgrading one or more packages.
15142@command{guix graph}}, for information on how to visualize the list of 15167@command{guix graph}}, for information on how to visualize the list of
15143dependents of a package. 15168dependents of a package.
15144 15169
15170@xref{build-dependents, @command{guix build --dependents}}, for a
15171convenient way to build all the dependents of a package.
15145@end table 15172@end table
15146 15173
15147Be aware that the @option{--list-dependent} option only 15174Be aware that the @option{--list-dependent} option only
diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
index e8384c8d2d8..5c93dc78f89 100644
--- a/guix/scripts/build.scm
+++ b/guix/scripts/build.scm
@@ -33,6 +33,9 @@
33 #:use-module (guix profiles) 33 #:use-module (guix profiles)
34 #:use-module (guix diagnostics) 34 #:use-module (guix diagnostics)
35 #:autoload (guix http-client) (http-fetch http-get-error?) 35 #:autoload (guix http-client) (http-fetch http-get-error?)
36 #:autoload (guix scripts graph) (%bag-node-type)
37 #:autoload (guix graph) (node-back-edges)
38 #:autoload (guix sets) (setq set-contains? set-insert)
36 #:use-module (ice-9 format) 39 #:use-module (ice-9 format)
37 #:use-module (ice-9 match) 40 #:use-module (ice-9 match)
38 #:use-module (srfi srfi-1) 41 #:use-module (srfi srfi-1)
@@ -440,6 +443,9 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n"))
440 (display (G_ " 443 (display (G_ "
441 -D, --development build the inputs of the following package")) 444 -D, --development build the inputs of the following package"))
442 (display (G_ " 445 (display (G_ "
446 -P, --dependents[=N] build dependents of the following package, up to
447 depth N"))
448 (display (G_ "
443 -S, --source build the packages' source derivations")) 449 -S, --source build the packages' source derivations"))
444 (display (G_ " 450 (display (G_ "
445 --sources[=TYPE] build source derivations; TYPE may optionally be one 451 --sources[=TYPE] build source derivations; TYPE may optionally be one
@@ -527,6 +533,11 @@ must be one of 'package', 'all', or 'transitive'~%")
527 (option '(#\D "development") #f #f 533 (option '(#\D "development") #f #f
528 (lambda (opt name arg result) 534 (lambda (opt name arg result)
529 (alist-cons 'development? #t result))) 535 (alist-cons 'development? #t result)))
536 (option '(#\P "dependents") #f #t
537 (lambda (opt name arg result)
538 (alist-cons 'dependents
539 (or (and=> arg string->number*) +inf.0)
540 result)))
530 (option '(#\n "dry-run") #f #f 541 (option '(#\n "dry-run") #f #f
531 (lambda (opt name arg result) 542 (lambda (opt name arg result)
532 (alist-cons 'dry-run? #t result))) 543 (alist-cons 'dry-run? #t result)))
@@ -551,7 +562,39 @@ must be one of 'package', 'all', or 'transitive'~%")
551 %standard-cross-build-options 562 %standard-cross-build-options
552 %standard-native-build-options))) 563 %standard-native-build-options)))
553 564
554(define (options->things-to-build opts) 565(define (dependents store packages max-depth)
566 "List all the things that would need to be rebuilt if PACKAGES are changed."
567 ;; Using %BAG-NODE-TYPE is more accurate than using %PACKAGE-NODE-TYPE
568 ;; because it includes implicit dependencies.
569 (define (get-dependents packages edges)
570 (let loop ((packages packages)
571 (result '())
572 (depth 0)
573 (visited (setq)))
574 (if (> depth max-depth)
575 (values result visited)
576 (match packages
577 (()
578 (values result visited))
579 ((head . tail)
580 (if (set-contains? visited head)
581 (loop tail result depth visited)
582 (let ((next (edges head)))
583 (call-with-values
584 (lambda ()
585 (loop next
586 (cons head result)
587 (+ depth 1)
588 (set-insert head visited)))
589 (lambda (result visited)
590 (loop tail result depth visited))))))))))
591
592 (with-store store
593 (run-with-store store
594 (mlet %store-monad ((edges (node-back-edges %bag-node-type (all-packages))))
595 (return (get-dependents packages edges))))))
596
597(define (options->things-to-build store opts)
555 "Read the arguments from OPTS and return a list of high-level objects to 598 "Read the arguments from OPTS and return a list of high-level objects to
556build---packages, gexps, derivations, and so on." 599build---packages, gexps, derivations, and so on."
557 (define (validate-type x) 600 (define (validate-type x)
@@ -600,6 +643,13 @@ values.")))))))))
600 (match type 643 (match type
601 ('regular 644 ('regular
602 (list obj)) 645 (list obj))
646 (('dependents . depth)
647 (if (package? obj)
648 (begin
649 (info (G_ "computing dependents of package ~a...~%")
650 (package-full-name obj))
651 (dependents store (list obj) depth))
652 (list obj)))
603 ('development 653 ('development
604 (if (package? obj) 654 (if (package? obj)
605 (map manifest-entry-item 655 (map manifest-entry-item
@@ -661,6 +711,8 @@ values.")))))))))
661 result))) 711 result)))
662 (('development? . #t) 712 (('development? . #t)
663 (loop tail 'development result)) 713 (loop tail 'development result))
714 (('dependents . depth)
715 (loop tail `(dependents . ,depth) result))
664 (_ 716 (_
665 (loop tail type result))))))) 717 (loop tail type result)))))))
666 718
@@ -687,7 +739,7 @@ build."
687 (systems systems))) 739 (systems systems)))
688 740
689 (define things-to-build 741 (define things-to-build
690 (map transform (options->things-to-build opts))) 742 (map transform (options->things-to-build store opts)))
691 743
692 (define warn-if-unsupported 744 (define warn-if-unsupported
693 (let ((target (assoc-ref opts 'target))) 745 (let ((target (assoc-ref opts 'target)))
diff --git a/tests/guix-build.sh b/tests/guix-build.sh
index 3637bcdeb36..8707ed32c03 100644
--- a/tests/guix-build.sh
+++ b/tests/guix-build.sh
@@ -196,6 +196,12 @@ test `guix build -D hello -d \
196 | grep -e 'glibc.*\.drv$' -e 'gcc.*\.drv$' -e 'binutils.*\.drv$' \ 196 | grep -e 'glibc.*\.drv$' -e 'gcc.*\.drv$' -e 'binutils.*\.drv$' \
197 | wc -l` -ge 3 197 | wc -l` -ge 3
198 198
199# Building the dependents.
200test `guix build -P1 libgit2 -P1 libssh -d \
201 | grep -e 'guile-git.*\.drv$' -e 'guile-ssh.*\.drv$' \
202 -e 'libgit2.*\.drv$' -e 'libssh.*\.drv$' \
203 | wc -l` -eq 4
204
199# Unbound variable in thunked field. 205# Unbound variable in thunked field.
200cat > "$module_dir/foo.scm" <<EOF 206cat > "$module_dir/foo.scm" <<EOF
201(define-module (foo) 207(define-module (foo)