From patchwork Tue Oct 31 20:25:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 55753 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 598A727BBE9; Tue, 31 Oct 2023 20:26:56 +0000 (GMT) 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_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI, SPF_HELO_PASS 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 92B9027BBE2 for ; Tue, 31 Oct 2023 20:26:54 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qxvJp-000292-5G; Tue, 31 Oct 2023 16:26:33 -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 1qxvJn-00028X-Ax for guix-patches@gnu.org; Tue, 31 Oct 2023 16:26:31 -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 1qxvJm-0004q2-9n; Tue, 31 Oct 2023 16:26:30 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qxvKI-0007Jf-5e; Tue, 31 Oct 2023 16:27:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#66475] [PATCH v2 1/4] git-download: Add support for Git Large File Storage (LFS). References: In-Reply-To: Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, rekado@elephly.net, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Tue, 31 Oct 2023 20:27:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 66475 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 66475@debbugs.gnu.org Cc: Maxim Cournoyer , Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic =?utf-8?q?Court=C3=A8s?= , Mathieu Othacehe , Ricardo Wurmus , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 66475-submit@debbugs.gnu.org id=B66475.169878400228062 (code B ref 66475); Tue, 31 Oct 2023 20:27:02 +0000 Received: (at 66475) by debbugs.gnu.org; 31 Oct 2023 20:26:42 +0000 Received: from localhost ([127.0.0.1]:49307 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxvJy-0007IX-1S for submit@debbugs.gnu.org; Tue, 31 Oct 2023 16:26:42 -0400 Received: from mail-oi1-x233.google.com ([2607:f8b0:4864:20::233]:58633) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qxvJv-0007II-7s for 66475@debbugs.gnu.org; Tue, 31 Oct 2023 16:26:40 -0400 Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-3b2e22f1937so3307123b6e.1 for <66475@debbugs.gnu.org>; Tue, 31 Oct 2023 13:26:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1698783959; x=1699388759; darn=debbugs.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=r/TGzEYAnZxkUJPCsPtS6QLIfhVilun8ebhGQY5ilGE=; b=XwmZXk67fReqQaKYSiDK8Jb5z6Z4X2ZfJ7IyOLNFN5pv1lNTuhh7oYqb7tl5VEiAHO E5JMKgVtMgCTcKw0eJKyu0fKjyrVk//T6R5aqDnmXlu2qxo/hu9SKZ7OljNX1SaPcad/ 1Ntm1HgiYYHY6JWJzYLrb19g+5/+uDfyV7tH1edP0JCYJ9I8sg3ctEtyvTv8RFCVaV0z UfteAmHzY2bSTkpmEvFD3OQc2rvvg2xzipHigf1EPGZdFJWXLqwmAvDIRULkRrEFW99I QmeImk9oyt3PPWPO5PkWOy83d3Az6rAnU54UCEd9orbQ1rmKK/92Pmptmo3vBsVkrWsv H24g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698783959; x=1699388759; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=r/TGzEYAnZxkUJPCsPtS6QLIfhVilun8ebhGQY5ilGE=; b=rJvb5jAoBC7piNc6jek+V4SaX3Vw+k31r3mVKIB/85GaM2kFIGcZv3jtJ1GwcYBHxG OC0MH/QiLNRe9+ehEgPDPFuaPnvqzj7mxEnn6tEl5SsJLFDVxgl9ZfpFTFpe2e+4GJEw PavB3bZaVkxxBALc7kVsjbtEGFnfN65+b8+eoXuko2Up/mBKRhh56+SbzmmOZabWIN8r 7qKLd5aQW+u6i+wohy6PcgOKNVE6rG/NXJUy2Mf/93lgBJlh2dSDE9ojpxP5z6o8vIcV YI9eR5VcX+/I41nAMWgk3V2sHLMHJzX+tJdwNHOPTfx1Bb0NvPmi40/2BthlL66zb1G/ SrYg== X-Gm-Message-State: AOJu0Yze39KlfJ3NiYfvq+R6nAK7s6dWP0Wt+MQr3Hfm/L/Vo1EzSpXx ogg7ualyxdbTyxRXCxo7ba8h9Ollr0o8/g== X-Google-Smtp-Source: AGHT+IHM4SQYGRVbmUHtjQNUfxYCrl3D9u6prQIByG0oIEQNqF9ixrM6AlXj0+MhlOg19prCD1ujXA== X-Received: by 2002:a54:411a:0:b0:3a0:41d4:b144 with SMTP id l26-20020a54411a000000b003a041d4b144mr14256818oic.1.1698783959065; Tue, 31 Oct 2023 13:25:59 -0700 (PDT) Received: from localhost.localdomain (dsl-10-128-239.b2b2c.ca. [72.10.128.239]) by smtp.gmail.com with ESMTPSA id z6-20020ae9c106000000b00774350813ccsm806463qki.118.2023.10.31.13.25.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 31 Oct 2023 13:25:58 -0700 (PDT) From: Maxim Cournoyer Date: Tue, 31 Oct 2023 16:25:14 -0400 Message-ID: X-Mailer: git-send-email 2.41.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/build/git.scm (git-fetch) [lfs?]: New argument, doc and setup code. (git-fetch-with-fallback) [lfs?]: New argument. Pass it to git-fetch. * guix/git-download.scm (git-lfs-package): New procedure. (git-fetch/in-band*): New procedure, made of the logic of git-fetch/in-band, with new git-lfs specifics, with the following changes: New #:git-lfs argument. : Remove labels. Conditionally add git-lfs. : Read "git lfs?" environment variable and pass its value to the #:lfs? argument of git-fetch-with-fallback. Use INPUTS directly; update comment. derivation>: Add "git lfs?" to #:env-vars. (git-fetch/in-band): Express in terms of git-fetch/in-band*. (git-fetch/lfs): New procedure. * doc/guix.texi (origin Reference): Document it. Change-Id: I5b233b8642a7bdb8737b9d9b740e7254a89ccb25 --- Changes in v2: - Do not add lfs? to ; instead add a git-fetch/lfs procedure. doc/guix.texi | 7 ++++ guix/build/git.scm | 19 +++++++-- guix/git-download.scm | 97 ++++++++++++++++++++++++++++++------------- 3 files changed, 91 insertions(+), 32 deletions(-) base-commit: d96a9c7473a6d07747f59eeda7d4085173c25383 diff --git a/doc/guix.texi b/doc/guix.texi index b90078be06..0076e27939 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -8375,6 +8375,13 @@ origin Reference the file name, or a generic name if @code{#f}. @end deffn +@deffn {Procedure} git-fetch/lfs ref hash-algo hash +This is a variant of the @code{git-fetch} procedure that supports the +Git @acronym{LFS, Large File Storage} extension. This may be useful to +pull some binary test data to run the test suite of a package, for +example. +@end deffn + @deftp {Data Type} git-reference This data type represents a Git reference for @code{git-fetch} to retrieve. diff --git a/guix/build/git.scm b/guix/build/git.scm index 0ff263c81b..867cade2c4 100644 --- a/guix/build/git.scm +++ b/guix/build/git.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2014, 2016, 2019, 2023 Ludovic Courtès +;;; Copyright © 2023 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -33,10 +34,13 @@ (define-module (guix build git) ;;; Code: (define* (git-fetch url commit directory - #:key (git-command "git") recursive?) + #:key (git-command "git") + lfs? recursive?) "Fetch COMMIT from URL into DIRECTORY. COMMIT must be a valid Git commit -identifier. When RECURSIVE? is true, all the sub-modules of URL are fetched, -recursively. Return #t on success, #f otherwise." +identifier. When LFS? is true, configure Git to also fetch Large File +Storage (LFS) files; it assumes that the @code{git-lfs} extension is available +in the environment. When RECURSIVE? is true, all the sub-modules of URL are +fetched, recursively. Return #t on success, #f otherwise." ;; Disable TLS certificate verification. The hash of the checkout is known ;; in advance anyway. @@ -57,6 +61,11 @@ (define* (git-fetch url commit directory (with-directory-excursion directory (invoke git-command "init" "--initial-branch=main") (invoke git-command "remote" "add" "origin" url) + + (when lfs? + (setenv "HOME" "/tmp") + (invoke git-command "lfs" "install")) + (if (zero? (system* git-command "fetch" "--depth" "1" "origin" commit)) (invoke git-command "checkout" "FETCH_HEAD") (begin @@ -81,11 +90,13 @@ (define* (git-fetch url commit directory (define* (git-fetch-with-fallback url commit directory - #:key (git-command "git") recursive?) + #:key (git-command "git") + lfs? recursive?) "Like 'git-fetch', fetch COMMIT from URL into DIRECTORY, but fall back to alternative methods when fetching from URL fails: attempt to download a nar, and if that also fails, download from the Software Heritage archive." (or (git-fetch url commit directory + #:lfs? lfs? #:recursive? recursive? #:git-command git-command) (download-nar directory) diff --git a/guix/git-download.scm b/guix/git-download.scm index 5d5d73dc6b..3de6ae970d 100644 --- a/guix/git-download.scm +++ b/guix/git-download.scm @@ -4,6 +4,7 @@ ;;; Copyright © 2017 Christopher Baines ;;; Copyright © 2020 Jakub Kądziołka ;;; Copyright © 2023 Simon Tournier +;;; Copyright © 2023 Maxim Cournoyer ;;; ;;; This file is part of GNU Guix. ;;; @@ -54,6 +55,7 @@ (define-module (guix git-download) git-reference-recursive? git-fetch + git-fetch/lfs git-version git-file-name git-predicate)) @@ -79,30 +81,36 @@ (define (git-package) (let ((distro (resolve-interface '(gnu packages version-control)))) (module-ref distro 'git-minimal))) -(define* (git-fetch/in-band ref hash-algo hash - #:optional name - #:key (system (%current-system)) - (guile (default-guile)) - (git (git-package))) - "Return a fixed-output derivation that performs a Git checkout of REF, using -GIT and GUILE (thus, said derivation depends on GIT and GUILE). +(define (git-lfs-package) + "Return the default 'git-lfs' package." + (let ((distro (resolve-interface '(gnu packages version-control)))) + (module-ref distro 'git-lfs))) -This method is deprecated in favor of the \"builtin:git-download\" builder. -It will be removed when versions of guix-daemon implementing -\"builtin:git-download\" will be sufficiently widespread." +(define* (git-fetch/in-band* ref hash-algo hash + #:optional name + #:key (system (%current-system)) + (guile (default-guile)) + (git (git-package)) + git-lfs) + "Shared implementation code for git-fetch/in-band & friends. Refer to their +respective documentation." (define inputs - `(("git" ,(or git (git-package))) - - ;; When doing 'git clone --recursive', we need sed, grep, etc. to be - ;; available so that 'git submodule' works. + `(,(or git (git-package)) + ,@(if git-lfs + (list git-lfs) + '()) ,@(if (git-reference-recursive? ref) - (standard-packages) + ;; TODO: remove (standard-packages) after + ;; 48e528a26f9c019eeaccf5e3de3126aa02c98d3b is merged into master; + ;; currently when doing 'git clone --recursive', we need sed, grep, + ;; etc. to be available so that 'git submodule' works. + (map second (standard-packages)) ;; The 'swh-download' procedure requires tar and gzip. - `(("gzip" ,(module-ref (resolve-interface '(gnu packages compression)) - 'gzip)) - ("tar" ,(module-ref (resolve-interface '(gnu packages base)) - 'tar)))))) + (list (module-ref (resolve-interface '(gnu packages compression)) + 'gzip) + (module-ref (resolve-interface '(gnu packages base)) + 'tar))))) (define guile-json (module-ref (resolve-interface '(gnu packages guile)) 'guile-json-4)) @@ -126,7 +134,7 @@ (define* (git-fetch/in-band ref hash-algo hash (define build (with-imported-modules modules - (with-extensions (list guile-json gnutls ;for (guix swh) + (with-extensions (list guile-json gnutls ;for (guix swh) guile-lzlib) #~(begin (use-modules (guix build git) @@ -134,6 +142,9 @@ (define* (git-fetch/in-band ref hash-algo hash #:select (set-path-environment-variable)) (ice-9 match)) + (define lfs? + (call-with-input-string (getenv "git lfs?") read)) + (define recursive? (call-with-input-string (getenv "git recursive?") read)) @@ -144,18 +155,17 @@ (define* (git-fetch/in-band ref hash-algo hash #+(file-append glibc-locales "/lib/locale")) (setlocale LC_ALL "en_US.utf8") - ;; The 'git submodule' commands expects Coreutils, sed, - ;; grep, etc. to be in $PATH. - (set-path-environment-variable "PATH" '("bin") - (match '#+inputs - (((names dirs outputs ...) ...) - dirs))) + ;; The 'git submodule' commands expects Coreutils, sed, grep, + ;; etc. to be in $PATH. This also ensures that git extensions are + ;; found. + (set-path-environment-variable "PATH" '("bin") '#+inputs) (setvbuf (current-output-port) 'line) (setvbuf (current-error-port) 'line) (git-fetch-with-fallback (getenv "git url") (getenv "git commit") #$output + #:lfs? lfs? #:recursive? recursive? #:git-command "git"))))) @@ -175,18 +185,49 @@ (define* (git-fetch/in-band ref hash-algo hash (git-reference-url ref)))) ("git commit" . ,(git-reference-commit ref)) ("git recursive?" . ,(object->string - (git-reference-recursive? ref)))) + (git-reference-recursive? ref))) + ("git lfs?" . ,(if git-lfs "#t" "#f"))) #:leaked-env-vars '("http_proxy" "https_proxy" "LC_ALL" "LC_MESSAGES" "LANG" "COLUMNS") #:system system - #:local-build? #t ;don't offload repo cloning + #:local-build? #t ;don't offload repo cloning #:hash-algo hash-algo #:hash hash #:recursive? #t #:guile-for-build guile))) +(define* (git-fetch/in-band ref hash-algo hash + #:optional name + #:key (system (%current-system)) + (guile (default-guile)) + (git (git-package))) + "Return a fixed-output derivation that performs a Git checkout of REF, using +GIT and GUILE (thus, said derivation depends on GIT and GUILE). + +This method is deprecated in favor of the \"builtin:git-download\" builder. +It will be removed when versions of guix-daemon implementing +\"builtin:git-download\" will be sufficiently widespread." + (git-fetch/in-band* ref hash-algo hash name + #:system system + #:guile guile + #:git git)) + +(define* (git-fetch/lfs ref hash-algo hash + #:optional name + #:key (system (%current-system)) + (guile (default-guile)) + (git (git-package)) + (git-lfs (git-lfs-package))) + "Like git-fetch/in-band, but with support for the Git Large File +Storage (LFS) extension." + (git-fetch/in-band* ref hash-algo hash name + #:system system + #:guile guile + #:git git + #:git-lfs git-lfs)) + (define* (git-fetch/built-in ref hash-algo hash #:optional name #:key (system (%current-system)))