From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id 8JPEKrONSWcBLAAAe85BDQ:P1 (envelope-from ) for ; Fri, 29 Nov 2024 09:47:31 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id 8JPEKrONSWcBLAAAe85BDQ (envelope-from ) for ; Fri, 29 Nov 2024 10:47:31 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=pass header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=Twr2GL1S; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=TAUZuPjB; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 72E3A766EA for ; Fri, 29 Nov 2024 10:43:22 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tGxWO-0000qi-0W; Fri, 29 Nov 2024 04:42:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGxVn-0000fM-LY for guix-patches@gnu.org; Fri, 29 Nov 2024 04:42:07 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tGxVn-0004Zh-BD; Fri, 29 Nov 2024 04:42:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=wpkNwIGCGGWoAeqRETs3oOnv5KSmbUnOmdNRr9ed9r0=; b=Twr2GL1SsHFWGE1AA/PYLUWs/9eEM6PjTbJu1c6qLcQmsORHC+BOIqHgtYu8MU6J0eMigTXYepnVeF6ewMufRh9JkmuIKGKQgqRQFCyt7NvEsXmxkVx1VPqpMk6OEYvmkM+LYTvRlOxePyWszVkvaydlVuHAf+WmpQcyRV/yMuGCrIYnhXzcgw4gE6O9UmN5JRg3RLsrEENQibtXKHdd2olEZGziC2HRGGusMheMVcHlvWeTtVS9n8E8bLiHdM2BWr+MhSLOVyfq/AA8OWAnHqtULh03ez1AM+DuoXsKtjnX8RnoNkZBcugynF8Kac42q1OcnyjSmJs2yTiY/Zl75A==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tGxVl-0005wn-69; Fri, 29 Nov 2024 04:42:05 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#74542] [PATCH v2 06/16] guix build: Add =?UTF-8?Q?=E2=80=98--dependents=E2=80=99.?= Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, maxim.cournoyer@gmail.com, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Fri, 29 Nov 2024 09:42:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74542 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 74542@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= , Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Maxim Cournoyer , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Maxim Cournoyer , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 74542-submit@debbugs.gnu.org id=B74542.173287328322673 (code B ref 74542); Fri, 29 Nov 2024 09:42:05 +0000 Received: (at 74542) by debbugs.gnu.org; 29 Nov 2024 09:41:23 +0000 Received: from localhost ([127.0.0.1]:41061 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tGxV5-0005tb-0X for submit@debbugs.gnu.org; Fri, 29 Nov 2024 04:41:23 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39618) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tGxUd-0005pg-CO for 74542@debbugs.gnu.org; Fri, 29 Nov 2024 04:40:59 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tGxUX-0003ng-O8; Fri, 29 Nov 2024 04:40:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=wpkNwIGCGGWoAeqRETs3oOnv5KSmbUnOmdNRr9ed9r0=; b=TAUZuPjB9+tyExbQoOp/ u1pxfuqEQMUDF8N89Cl9oTOcC/kvAr/VSlX7AwOjURrYCtnjV9Mw+KZ1wbm+6F6zqT33JzjNF5XUF 4GoYP26DgvQDuQVrVzmMqLs/1BhoGsS/j1W3QRhXgoqdpPg2EBVEQr2Tgpcy8WzS7Qe1erqjhCeI2 gaQNNLl7DixgapKNEXS36tdO+vfGn0NIlG5uUjaRbQ2awWPCdYM9HrbwrLJuDbMIau5ecAOWK2tpz kdm0DaXhHNqSnLObQ8aOe0AXsIVny1ifzF2e7No38+Jy1aEXxP5jUkIpxnFEy5wrHa8BJO3II2DBU bcDz2a4ffPcsKg==; From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Fri, 29 Nov 2024 10:40:09 +0100 Message-ID: <24a98350fd3f836dae11621065fa4040cbd4b227.1732872498.git.ludo@gnu.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -4.81 X-Spam-Score: -4.81 X-Migadu-Queue-Id: 72E3A766EA X-Migadu-Scanner: mx10.migadu.com X-TUID: p/XmiretozNd * guix/scripts/build.scm (show-help, %options): Add ‘--dependents’. (dependents): New procedure. (options->things-to-build): Add ‘store’ parameter; honor ‘dependents’ option. [for-type]: Handle ‘dependents’ type. (options->derivations): Update call to ‘options->things-to-build’. * tests/guix-build.sh: Add test. * doc/guix.texi (Additional Build Options): Document ‘--dependents’. (Invoking guix refresh): Cross-reference it. * doc/contributing.texi (Submitting Patches): Mention it. Change-Id: I00b6d5831e1f1d35dc8b84a82605391d5a8f417c --- doc/contributing.texi | 4 ++- doc/guix.texi | 27 ++++++++++++++++++++ guix/scripts/build.scm | 56 ++++++++++++++++++++++++++++++++++++++++-- tests/guix-build.sh | 6 +++++ 4 files changed, 90 insertions(+), 3 deletions(-) diff --git a/doc/contributing.texi b/doc/contributing.texi index b063169189..5a778466d7 100644 --- a/doc/contributing.texi +++ b/doc/contributing.texi @@ -1914,7 +1914,9 @@ Submitting Patches @item Make sure the package builds on your platform, using @command{guix build -@var{package}}. +@var{package}}. Also build at least its direct dependents with +@command{guix build --dependents=1 @var{package}} +(@pxref{build-dependents, @command{guix build}}). @item We recommend you also try building the package on other supported diff --git a/doc/guix.texi b/doc/guix.texi index a9d0d044ae..219f19f2d6 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -13639,6 +13639,31 @@ Additional Build Options natively. @end quotation +@cindex dependents of a package, building them +@cindex building the dependents of a package +@anchor{build-dependents} +@item --dependents[=@var{depth}] +@itemx -P [@var{depth}] +Build the dependents of the following package. By default, build all +the direct and indirect dependents; when @var{depth} is provided, limit +to dependents at that distance: 1 for direct dependents, 2 for +dependents of dependents, and so on. + +For example, the command below builds @emph{all} the dependents of libgit2: + +@example +guix build --dependents libgit2 +@end example + +To build all the packages that directly depend on NumPy, run: + +@example +guix build -P1 python-numpy +@end example + +The list of dependents is computed in the same way as with @command{guix +refresh --list-dependent} (@pxref{Invoking guix refresh}). + @item --source @itemx -S Build the source derivations of the packages, rather than the packages @@ -15142,6 +15167,8 @@ Invoking guix refresh @command{guix graph}}, for information on how to visualize the list of dependents of a package. +@xref{build-dependents, @command{guix build --dependents}}, for a +convenient way to build all the dependents of a package. @end table Be aware that the @option{--list-dependent} option only diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm index e8384c8d2d..5c93dc78f8 100644 --- a/guix/scripts/build.scm +++ b/guix/scripts/build.scm @@ -33,6 +33,9 @@ (define-module (guix scripts build) #:use-module (guix profiles) #:use-module (guix diagnostics) #:autoload (guix http-client) (http-fetch http-get-error?) + #:autoload (guix scripts graph) (%bag-node-type) + #:autoload (guix graph) (node-back-edges) + #:autoload (guix sets) (setq set-contains? set-insert) #:use-module (ice-9 format) #:use-module (ice-9 match) #:use-module (srfi srfi-1) @@ -440,6 +443,9 @@ (define (show-help) (display (G_ " -D, --development build the inputs of the following package")) (display (G_ " + -P, --dependents[=N] build dependents of the following package, up to + depth N")) + (display (G_ " -S, --source build the packages' source derivations")) (display (G_ " --sources[=TYPE] build source derivations; TYPE may optionally be one @@ -527,6 +533,11 @@ (define %options (option '(#\D "development") #f #f (lambda (opt name arg result) (alist-cons 'development? #t result))) + (option '(#\P "dependents") #f #t + (lambda (opt name arg result) + (alist-cons 'dependents + (or (and=> arg string->number*) +inf.0) + result))) (option '(#\n "dry-run") #f #f (lambda (opt name arg result) (alist-cons 'dry-run? #t result))) @@ -551,7 +562,39 @@ (define %options %standard-cross-build-options %standard-native-build-options))) -(define (options->things-to-build opts) +(define (dependents store packages max-depth) + "List all the things that would need to be rebuilt if PACKAGES are changed." + ;; Using %BAG-NODE-TYPE is more accurate than using %PACKAGE-NODE-TYPE + ;; because it includes implicit dependencies. + (define (get-dependents packages edges) + (let loop ((packages packages) + (result '()) + (depth 0) + (visited (setq))) + (if (> depth max-depth) + (values result visited) + (match packages + (() + (values result visited)) + ((head . tail) + (if (set-contains? visited head) + (loop tail result depth visited) + (let ((next (edges head))) + (call-with-values + (lambda () + (loop next + (cons head result) + (+ depth 1) + (set-insert head visited))) + (lambda (result visited) + (loop tail result depth visited)))))))))) + + (with-store store + (run-with-store store + (mlet %store-monad ((edges (node-back-edges %bag-node-type (all-packages)))) + (return (get-dependents packages edges)))))) + +(define (options->things-to-build store opts) "Read the arguments from OPTS and return a list of high-level objects to build---packages, gexps, derivations, and so on." (define (validate-type x) @@ -600,6 +643,13 @@ (define-public my-package (match type ('regular (list obj)) + (('dependents . depth) + (if (package? obj) + (begin + (info (G_ "computing dependents of package ~a...~%") + (package-full-name obj)) + (dependents store (list obj) depth)) + (list obj))) ('development (if (package? obj) (map manifest-entry-item @@ -661,6 +711,8 @@ (define-public my-package result))) (('development? . #t) (loop tail 'development result)) + (('dependents . depth) + (loop tail `(dependents . ,depth) result)) (_ (loop tail type result))))))) @@ -687,7 +739,7 @@ (define (options->derivations store opts) (systems systems))) (define things-to-build - (map transform (options->things-to-build opts))) + (map transform (options->things-to-build store opts))) (define warn-if-unsupported (let ((target (assoc-ref opts 'target))) diff --git a/tests/guix-build.sh b/tests/guix-build.sh index 3637bcdeb3..8707ed32c0 100644 --- a/tests/guix-build.sh +++ b/tests/guix-build.sh @@ -196,6 +196,12 @@ test `guix build -D hello -d \ | grep -e 'glibc.*\.drv$' -e 'gcc.*\.drv$' -e 'binutils.*\.drv$' \ | wc -l` -ge 3 +# Building the dependents. +test `guix build -P1 libgit2 -P1 libssh -d \ + | grep -e 'guile-git.*\.drv$' -e 'guile-ssh.*\.drv$' \ + -e 'libgit2.*\.drv$' -e 'libssh.*\.drv$' \ + | wc -l` -eq 4 + # Unbound variable in thunked field. cat > "$module_dir/foo.scm" <