From patchwork Fri Apr 25 08:32:20 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Romain GARBAGE X-Patchwork-Id: 41998 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 392C927BC4B; Fri, 25 Apr 2025 09:33:25 +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=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, 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 4C96927BC49 for ; Fri, 25 Apr 2025 09:33:24 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u8EUf-0007T4-Md; Fri, 25 Apr 2025 04:33:09 -0400 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 1u8EUd-0007Sg-OG for guix-patches@gnu.org; Fri, 25 Apr 2025 04:33:08 -0400 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 1u8EUc-0001N2-HW; Fri, 25 Apr 2025 04:33:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:In-Reply-To:References:Subject; bh=mpRFqT7VWGBEgFEotVJkIpS8thM28ajsbzgU+Ut+v1U=; b=ciDLuIUsjdBmQghy58QGzaRIBhUbHGwZ9rrdrusNwSXolP1ebEOCj3OUhgbTRVGOB/b7SRpQDYGr9qJjiS+6ou1fYxRIV7YbOb2+l9jsjX2suhToSTryOKsfavRh1BgoQ3NRRJDTI3dEnpjiZxtQM4U9lmqZW5QcQbw3Pjed/pxCVqX8VWLrnc+6HNtxjfF+QoorCaSxjz6VSbpdzEhhklolhPieIEaaKgnVsIOdKMlA0hhFV10ha7bZGdD3/EfvnmSRPUu0MKju0vAOsU/ytgmupFj4pKemUHczLDYjksl8S1gMDBOJOZ/9z8Y/ErkF4O07s0fHS+NdbitqNBhgxA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1u8EUY-0004kN-EF; Fri, 25 Apr 2025 04:33:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#78034] [PATCH v2] guix: transformations: git source transformations honour RECURSIVE?. References: <8306eb0b4d96b233e62d87f13444f9c55354b34c.1745502758.git.romain.garbage@inria.fr> In-Reply-To: <8306eb0b4d96b233e62d87f13444f9c55354b34c.1745502758.git.romain.garbage@inria.fr> Resent-From: Romain GARBAGE 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, 25 Apr 2025 08:33:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 78034 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 78034@debbugs.gnu.org Cc: ludovic.courtes@inria.fr, Romain GARBAGE , 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 78034-submit@debbugs.gnu.org id=B78034.174556997318197 (code B ref 78034); Fri, 25 Apr 2025 08:33:02 +0000 Received: (at 78034) by debbugs.gnu.org; 25 Apr 2025 08:32:53 +0000 Received: from localhost ([127.0.0.1]:46955 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1u8EUO-0004jQ-G3 for submit@debbugs.gnu.org; Fri, 25 Apr 2025 04:32:53 -0400 Received: from mail2-relais-roc.national.inria.fr ([192.134.164.83]:43705) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1u8EUK-0004iv-69 for 78034@debbugs.gnu.org; Fri, 25 Apr 2025 04:32:50 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=mpRFqT7VWGBEgFEotVJkIpS8thM28ajsbzgU+Ut+v1U=; b=FKeo6PPTiD+ZwU+YkEHSBPvpDE7eKQ5V+M2AqB3u7ONQgFwPGNayyQTt iSQXRbSRN+T3pGby3AyWsk+iVl99+P/ARlO7VmXrfWfsI8ENwYoalmdGU wQrifrEDCqSbv2AgxQKePpTmDIIyc8CMhojEqN/bJ7jXOT4TWjcha/kLV s=; Authentication-Results: mail2-relais-roc.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=romain.garbage@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.15,238,1739833200"; d="scan'208";a="219405017" Received: from unknown (HELO guix-A102.bordeaux.inria.fr) ([193.50.110.224]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2025 10:32:41 +0200 From: Romain GARBAGE Date: Fri, 25 Apr 2025 10:32:20 +0200 Message-ID: X-Mailer: git-send-email 2.49.0 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-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/transformations.scm (package-git-url+recursive?): New variable. (package-git-url): Remove variable. (evaluate-git-replacement-specs): Use package-git-url+recursive?. (transform-package-source-branch, transform-package-source-commit, transform-package-source-git-url): Update according to changes above. * doc/guix.texi (Package Transformation Options): Update documentation. * tests/transformations.scm: Update tests. Add tests for RECURSIVE? inheritance with WITH-COMMIT and WITH-SOURCE. Change-Id: Id6a5e6957a9955c8173b06b3e14f2986c6dfc4bc --- doc/guix.texi | 8 +++--- guix/transformations.scm | 53 ++++++++++++++++++++++++++------------- tests/transformations.scm | 52 +++++++++++++++++++++++++++++++++++--- 3 files changed, 89 insertions(+), 24 deletions(-) base-commit: b12d44dd5e35ac236bf3fbb5619b9c8c2f42c902 diff --git a/doc/guix.texi b/doc/guix.texi index 32ef844f5c..3d5a1238a6 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -13584,9 +13584,11 @@ Package Transformation Options @item --with-git-url=@var{package}=@var{url} @cindex Git, using the latest commit @cindex latest commit, building -Build @var{package} from the latest commit of the @code{master} branch of the -Git repository at @var{url}. Git sub-modules of the repository are fetched, -recursively. +Build @var{package} from the latest commit of the @code{master} branch +of the Git repository at @var{url}. Git sub-modules of the repository +are fetched, recursively, if @var{package} @code{source} is not a Git +repository, otherwise it depends on the inherited value of +@code{recursive?}. For example, the following command builds the NumPy Python library against the latest commit of the master branch of Python itself: diff --git a/guix/transformations.scm b/guix/transformations.scm index 2887d91a34..19a1cba206 100644 --- a/guix/transformations.scm +++ b/guix/transformations.scm @@ -29,8 +29,13 @@ (define-module (guix transformations) #:use-module (guix profiles) #:use-module (guix diagnostics) #:autoload (guix download) (download-to-store) - #:autoload (guix git-download) (git-reference? git-reference-url) - #:autoload (guix git) (git-checkout git-checkout? git-checkout-url) + #:autoload (guix git-download) (git-reference? + git-reference-url + git-reference-recursive?) + #:autoload (guix git) (git-checkout + git-checkout? + git-checkout-url + git-checkout-recursive?) #:autoload (guix upstream) (upstream-source package-latest-release preferred-upstream-source @@ -234,15 +239,18 @@ (define (transform-package-inputs/graft replacement-specs) (define %not-equal (char-set-complement (char-set #\=))) -(define (package-git-url package) - "Return the URL of the Git repository for package, or raise an error if -the source of PACKAGE is not fetched from a Git repository." +(define (package-git-url+recursive? package) + "Return two values: the URL of the Git repository for package and a boolean +indicating if the repository has to be recursively cloned, or raise an error if the +source of PACKAGE is not fetched from a Git repository." (let ((source (package-source package))) (cond ((and (origin? source) (git-reference? (origin-uri source))) - (git-reference-url (origin-uri source))) + (values (git-reference-url (origin-uri source)) + (git-reference-recursive? (origin-uri source)))) ((git-checkout? source) - (git-checkout-url source)) + (values (git-checkout-url source) + (git-checkout-recursive? source))) (else (raise (formatted-message (G_ "the source of ~a is not a Git reference") @@ -257,9 +265,9 @@ (define (evaluate-git-replacement-specs specs proc) (match (string-tokenize spec %not-equal) ((spec branch-or-commit) (define (replace old) - (let* ((source (package-source old)) - (url (package-git-url old))) - (proc old url branch-or-commit))) + (let* ((source (package-source old)) + (url recursive? (package-git-url+recursive? old))) + (proc old url branch-or-commit recursive?))) (cons spec replace)) (_ @@ -273,7 +281,7 @@ (define (transform-package-source-branch replacement-specs) dependencies according to REPLACEMENT-SPECS. REPLACEMENT-SPECS is a list of strings like \"guile-next=stable-3.0\" meaning that packages are built using 'guile-next' from the latest commit on its 'stable-3.0' branch." - (define (replace old url branch) + (define (replace old url branch recursive?) (package (inherit old) (version (string-append "git." (string-map (match-lambda @@ -281,7 +289,7 @@ (define (transform-package-source-branch replacement-specs) (chr chr)) branch))) (source (git-checkout (url url) (branch branch) - (recursive? #t))))) + (recursive? recursive?))))) (let* ((replacements (evaluate-git-replacement-specs replacement-specs replace)) @@ -315,12 +323,12 @@ (define (transform-package-source-commit replacement-specs) dependencies according to REPLACEMENT-SPECS. REPLACEMENT-SPECS is a list of strings like \"guile-next=cabba9e\" meaning that packages are built using 'guile-next' from commit 'cabba9e'." - (define (replace old url commit) + (define (replace old url commit recursive?) (package (inherit old) (version (commit->version-string commit)) (source (git-checkout (url url) (commit commit) - (recursive? #t))))) + (recursive? recursive?))))) (let* ((replacements (evaluate-git-replacement-specs replacement-specs replace)) @@ -341,10 +349,19 @@ (define (transform-package-source-git-url replacement-specs) ((spec url) (cons spec (lambda (old) - (package - (inherit old) - (source (git-checkout (url url) - (recursive? #t))))))) + ;; Propagate RECURSIVE? from the package source when it is a + ;; git-checkout or a git-reference, keeping TRUE as default in + ;; other cases. + (let* ((uri (and (origin? (package-source old)) + (origin-uri (package-source old)))) + (recursive? (if (or (git-checkout? uri) + (git-reference? uri)) + (package-git-url+recursive? old) + #t))) + (package + (inherit old) + (source (git-checkout (url url) + (recursive? recursive?)))))))) (_ (raise (formatted-message diff --git a/tests/transformations.scm b/tests/transformations.scm index 5285d98f17..9f5aacc41b 100644 --- a/tests/transformations.scm +++ b/tests/transformations.scm @@ -217,8 +217,7 @@ (define-module (test-transformations) (test-equal "options->transformation, with-branch" (git-checkout (url "https://example.org") - (branch "devel") - (recursive? #t)) + (branch "devel")) (let* ((p (dummy-package "guix.scm" (inputs `(("foo" ,grep) ("bar" ,(dummy-package "chbouib" @@ -238,7 +237,53 @@ (define-module (test-transformations) (string=? (package-name dep2) "chbouib") (package-source dep2)))))))) +(test-equal "options->transformation, with-branch, recursive? inheritance" + (git-checkout (url "https://example.org") + (branch "devel") + (recursive? #t)) + (let* ((p (dummy-package "guix.scm" + (inputs `(("foo" ,grep) + ("bar" ,(dummy-package "chbouib" + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://example.org") + (commit "cabba9e") + (recursive? #t))) + (sha256 #f))))))))) + (t (options->transformation '((with-branch . "chbouib=devel"))))) + (let ((new (t p))) + (and (not (eq? new p)) + (match (package-inputs new) + ((("foo" dep1) ("bar" dep2)) + (and (string=? (package-full-name dep1) + (package-full-name grep)) + (string=? (package-name dep2) "chbouib") + (package-source dep2)))))))) + (test-equal "options->transformation, with-commit" + (git-checkout (url "https://example.org") + (commit "abcdef")) + (let* ((p (dummy-package "guix.scm" + (inputs `(("foo" ,grep) + ("bar" ,(dummy-package "chbouib" + (source (origin + (method git-fetch) + (uri (git-reference + (url "https://example.org") + (commit "cabba9e"))) + (sha256 #f))))))))) + (t (options->transformation '((with-commit . "chbouib=abcdef"))))) + (let ((new (t p))) + (and (not (eq? new p)) + (match (package-inputs new) + ((("foo" dep1) ("bar" dep2)) + (and (string=? (package-full-name dep1) + (package-full-name grep)) + (string=? (package-name dep2) "chbouib") + (package-source dep2)))))))) + +(test-equal "options->transformation, with-commit, recursive? inheritance" (git-checkout (url "https://example.org") (commit "abcdef") (recursive? #t)) @@ -249,7 +294,8 @@ (define-module (test-transformations) (method git-fetch) (uri (git-reference (url "https://example.org") - (commit "cabba9e"))) + (commit "cabba9e") + (recursive? #t))) (sha256 #f))))))))) (t (options->transformation '((with-commit . "chbouib=abcdef"))))) (let ((new (t p)))