From patchwork Fri Sep 23 20:42:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 42897 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id CB12B27BBEA; Fri, 23 Sep 2022 21:43:17 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,SPF_HELO_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 2CB3E27BBE9 for ; Fri, 23 Sep 2022 21:43:17 +0100 (BST) Received: from localhost ([::1]:32990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1obpW0-0003CD-BD for patchwork@mira.cbaines.net; Fri, 23 Sep 2022 16:43:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40124) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obpVn-0003B8-7E for guix-patches@gnu.org; Fri, 23 Sep 2022 16:43:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:42768) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1obpVm-0000KK-HZ for guix-patches@gnu.org; Fri, 23 Sep 2022 16:43:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1obpVl-0007Nr-Us; Fri, 23 Sep 2022 16:43:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#58032] [PATCH] transformations: '--with-source' now operates in depth. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: philippe.swartvagher@inria.fr, 43193@debbugs.gnu.org, guix-patches@gnu.org Resent-Date: Fri, 23 Sep 2022 20:43:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 58032 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 58032@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= , philippe.swartvagher@inria.fr, 43193@debbugs.gnu.org X-Debbugs-Original-To: guix-patches@gnu.org X-Debbugs-Original-Xcc: philippe.swartvagher@inria.fr, 43193@debbugs.gnu.org Received: via spool by submit@debbugs.gnu.org id=B.166396574828341 (code B ref -1); Fri, 23 Sep 2022 20:43:01 +0000 Received: (at submit) by debbugs.gnu.org; 23 Sep 2022 20:42:28 +0000 Received: from localhost ([127.0.0.1]:41844 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1obpVD-0007N2-NC for submit@debbugs.gnu.org; Fri, 23 Sep 2022 16:42:28 -0400 Received: from lists.gnu.org ([209.51.188.17]:55414) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1obpVB-0007Mu-FR for submit@debbugs.gnu.org; Fri, 23 Sep 2022 16:42:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obpV9-0002Q4-S3 for guix-patches@gnu.org; Fri, 23 Sep 2022 16:42:25 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]:43792) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1obpV7-00009t-J1; Fri, 23 Sep 2022 16:42:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=CLZItMJxIOrI8pmYHm1ruwDwgA0pAQmTugXbnIyXA0Q=; b=gvGa1iHA1bbN5K Wzt8RBMElH3lN9yE7jx3INEb93XozpMoBXukVuPCwrqg9AXgFGMAQiyim2vSEbsS3imtDjc5a22/b +lQdg2gmqyrFaOT4SZ/ITrzL7SP1CeGMQNl9mEd55zxRIrLf5PGqSFTVCCEG0cDdLbBSsgh+kc/TY OXEp75v/BEBMKM62yqxj6+4zjMsVeOitgNQekABcGhNp9/N8V5xjopq3RyG7fd74C4hBAF1dT8jb6 +8DZBkoVcQrJv9tVF4snqxUBXQRxY4BXvD4kXY9P8sS5sxOhwPH+yFgtBML2zcZrpKGhXbx3BJNGN dUKjHwdfB/AlTCE1x1qw==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:62283 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1obpV6-00073I-Vc; Fri, 23 Sep 2022 16:42:21 -0400 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Fri, 23 Sep 2022 22:42:08 +0200 Message-Id: <20220923204208.31957-1-ludo@gnu.org> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 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+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches From: Ludovic Courtès The '--with-source' option is the first one that was implemented, and it's the only one that would operate only on leaf packages rather than traversing the dependency graph. This change makes it consistent with the rest of the transformation options. * guix/transformations.scm (evaluate-source-replacement-specs): New procedure. (transform-package-source): Rewrite using it. * tests/transformations.scm ("options->transformation, with-source, no matches"): Rewrite since we no longer get a warning. ("options->transformation, with-source, in depth"): New test. * doc/guix.texi (Package Transformation Options): Adjust examples. --- doc/guix.texi | 7 ++-- guix/transformations.scm | 74 +++++++++++++++++++++------------------ tests/transformations.scm | 32 +++++++++++++---- 3 files changed, 68 insertions(+), 45 deletions(-) Hi! That ‘--with-source’ doesn’t work recursively, unlike other transformations, has been a source of confusion. This change addresses that. (It could probably use a channel news entry.) Thoughts? Actually a similar attempt had been made by Jesse Gibbons at . Oh well… Ludo’. diff --git a/doc/guix.texi b/doc/guix.texi index eb12efa85e..7316b1c157 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -12348,14 +12348,15 @@ one provided by the distribution. The example below downloads the @code{ed} package: @example -guix build ed --with-source=mirror://gnu/ed/ed-1.7.tar.gz +guix build ed --with-source=mirror://gnu/ed/ed-1.4.tar.gz @end example As a developer, @option{--with-source} makes it easy to test release -candidates: +candidates, and even to test their impact on packages that depend on +them: @example -guix build guile --with-source=../guile-2.0.9.219-e1bb7.tar.xz +guix build elogind --with-source=@dots{}/shepherd-0.9.0rc1.tar.gz @end example @dots{} or to build from a checkout in a pristine environment: diff --git a/guix/transformations.scm b/guix/transformations.scm index 411c4014cb..be2d31b8c7 100644 --- a/guix/transformations.scm +++ b/guix/transformations.scm @@ -129,42 +129,46 @@ (define* (package-with-source p uri #:optional version) ;;; Transformations. ;;; -(define (transform-package-source sources) +(define (evaluate-source-replacement-specs specs) + "Parse SPECS, a list of strings like \"guile=/tmp/guile-4.2.tar.gz\" or just +\"/tmp/guile-4.2.tar.gz\" and return a list of package spec/procedure pairs as +expected by 'package-input-rewriting/spec'. Raise an error if an element of +SPECS uses invalid syntax." + (define not-equal + (char-set-complement (char-set #\=))) + + (map (lambda (spec) + (match (string-tokenize spec not-equal) + ((uri) + (let* ((base (tarball-base-name (basename uri))) + (name (hyphen-package-name->name+version base))) + (cons name + (lambda (old) + (package-with-source old uri))))) + ((spec uri) + (let-values (((name version) + (package-name->name+version spec))) + ;; Note: Here VERSION is used as the version string of the new + ;; package rather than as part of the spec of the package being + ;; targeted. + (cons name + (lambda (old) + (package-with-source old uri version))))) + (_ + (raise (formatted-message + (G_ "invalid source replacement specification: ~s") + spec))))) + specs)) + +(define (transform-package-source replacement-specs) "Return a transformation procedure that replaces package sources with the -matching URIs given in SOURCES." - (define new-sources - (map (lambda (uri) - (match (string-index uri #\=) - (#f - ;; Determine the package name and version from URI. - (call-with-values - (lambda () - (hyphen-package-name->name+version - (tarball-base-name (basename uri)))) - (lambda (name version) - (list name version uri)))) - (index - ;; What's before INDEX is a "PKG@VER" or "PKG" spec. - (call-with-values - (lambda () - (package-name->name+version (string-take uri index))) - (lambda (name version) - (list name version - (string-drop uri (+ 1 index)))))))) - sources)) - - (lambda (obj) - (let loop ((sources new-sources) - (result '())) - (match obj - ((? package? p) - (match (assoc-ref sources (package-name p)) - ((version source) - (package-with-source p source version)) - (#f - p))) - (_ - obj))))) +matching URIs given in REPLACEMENT-SPECS." + (let* ((replacements (evaluate-source-replacement-specs replacement-specs)) + (rewrite (package-input-rewriting/spec replacements))) + (lambda (obj) + (if (package? obj) + (rewrite obj) + obj)))) (define (evaluate-replacement-specs specs proc) "Parse SPECS, a list of strings like \"guile=guile@2.1\" and return a list diff --git a/tests/transformations.scm b/tests/transformations.scm index dbfe523518..47b1fc650d 100644 --- a/tests/transformations.scm +++ b/tests/transformations.scm @@ -103,16 +103,11 @@ (define-module (test-transformations) "sha256" f)))))))))) (test-assert "options->transformation, with-source, no matches" - ;; When a transformation in not applicable, a warning must be raised. (let* ((p (dummy-package "foobar")) (s (search-path %load-path "guix.scm")) (t (options->transformation `((with-source . ,s))))) - (let* ((port (open-output-string)) - (new (parameterize ((guix-warning-port port)) - (t p)))) - (and (eq? new p) - (string-contains (get-output-string port) - "had no effect"))))) + (eq? (package-source (t p)) + (package-source p)))) (test-assert "options->transformation, with-source, PKG=URI" (let* ((p (dummy-package "foo")) @@ -147,6 +142,29 @@ (define-module (test-transformations) (add-to-store store (basename s) #t "sha256" s))))))) +(test-assert "options->transformation, with-source, in depth" + (let* ((p0 (dummy-package "foo" (version "0.0"))) + (s (search-path %load-path "guix.scm")) + (f (string-append "foo@42.0=" s)) + (t (options->transformation `((with-source . ,f)))) + (p1 (dummy-package "bar" (inputs (list p0)))) + (p2 (dummy-package "baz" (inputs (list p1))))) + (with-store store + (let ((new (t p2))) + (and (not (eq? new p2)) + (match (package-inputs new) + ((("bar" p1*)) + (match (package-inputs p1*) + ((("foo" p0*)) + (and (not (eq? p0* p0)) + (string=? (package-name p0*) (package-name p0)) + (string=? (package-version p0*) "42.0") + (string=? (add-to-store store (basename s) #t + "sha256" s) + (run-with-store store + (lower-object + (package-source p0*)))))))))))))) + (test-assert "options->transformation, with-input" (let* ((p (dummy-package "guix.scm" (inputs `(("foo" ,(specification->package "coreutils"))