diff options
| -rw-r--r-- | guix/git-download.scm | 72 | ||||
| -rw-r--r-- | tests/builders.scm | 29 |
2 files changed, 91 insertions, 10 deletions
diff --git a/guix/git-download.scm b/guix/git-download.scm index f1f19397c6f..5d5d73dc6b0 100644 --- a/guix/git-download.scm +++ b/guix/git-download.scm | |||
| @@ -27,6 +27,7 @@ | |||
| 27 | #:use-module (guix records) | 27 | #:use-module (guix records) |
| 28 | #:use-module (guix packages) | 28 | #:use-module (guix packages) |
| 29 | #:use-module (guix modules) | 29 | #:use-module (guix modules) |
| 30 | #:use-module ((guix derivations) #:select (raw-derivation)) | ||
| 30 | #:autoload (guix build-system gnu) (standard-packages) | 31 | #:autoload (guix build-system gnu) (standard-packages) |
| 31 | #:autoload (guix download) (%download-fallback-test) | 32 | #:autoload (guix download) (%download-fallback-test) |
| 32 | #:autoload (git bindings) (libgit2-init!) | 33 | #:autoload (git bindings) (libgit2-init!) |
| @@ -78,15 +79,19 @@ | |||
| 78 | (let ((distro (resolve-interface '(gnu packages version-control)))) | 79 | (let ((distro (resolve-interface '(gnu packages version-control)))) |
| 79 | (module-ref distro 'git-minimal))) | 80 | (module-ref distro 'git-minimal))) |
| 80 | 81 | ||
| 81 | (define* (git-fetch ref hash-algo hash | 82 | (define* (git-fetch/in-band ref hash-algo hash |
| 82 | #:optional name | 83 | #:optional name |
| 83 | #:key (system (%current-system)) (guile (default-guile)) | 84 | #:key (system (%current-system)) |
| 84 | (git (git-package))) | 85 | (guile (default-guile)) |
| 85 | "Return a fixed-output derivation that fetches REF, a <git-reference> | 86 | (git (git-package))) |
| 86 | object. The output is expected to have recursive hash HASH of type | 87 | "Return a fixed-output derivation that performs a Git checkout of REF, using |
| 87 | HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f." | 88 | GIT and GUILE (thus, said derivation depends on GIT and GUILE). |
| 89 | |||
| 90 | This method is deprecated in favor of the \"builtin:git-download\" builder. | ||
| 91 | It will be removed when versions of guix-daemon implementing | ||
| 92 | \"builtin:git-download\" will be sufficiently widespread." | ||
| 88 | (define inputs | 93 | (define inputs |
| 89 | `(("git" ,git) | 94 | `(("git" ,(or git (git-package))) |
| 90 | 95 | ||
| 91 | ;; When doing 'git clone --recursive', we need sed, grep, etc. to be | 96 | ;; When doing 'git clone --recursive', we need sed, grep, etc. to be |
| 92 | ;; available so that 'git submodule' works. | 97 | ;; available so that 'git submodule' works. |
| @@ -154,7 +159,8 @@ HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f." | |||
| 154 | #:recursive? recursive? | 159 | #:recursive? recursive? |
| 155 | #:git-command "git"))))) | 160 | #:git-command "git"))))) |
| 156 | 161 | ||
| 157 | (mlet %store-monad ((guile (package->derivation guile system))) | 162 | (mlet %store-monad ((guile (package->derivation (or guile (default-guile)) |
| 163 | system))) | ||
| 158 | (gexp->derivation (or name "git-checkout") build | 164 | (gexp->derivation (or name "git-checkout") build |
| 159 | 165 | ||
| 160 | ;; Use environment variables and a fixed script name so | 166 | ;; Use environment variables and a fixed script name so |
| @@ -181,6 +187,54 @@ HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f." | |||
| 181 | #:recursive? #t | 187 | #:recursive? #t |
| 182 | #:guile-for-build guile))) | 188 | #:guile-for-build guile))) |
| 183 | 189 | ||
| 190 | (define* (git-fetch/built-in ref hash-algo hash | ||
| 191 | #:optional name | ||
| 192 | #:key (system (%current-system))) | ||
| 193 | "Return a fixed-output derivation that performs a Git checkout of REF, using | ||
| 194 | the \"builtin:git-download\" derivation builder. | ||
| 195 | |||
| 196 | This is an \"out-of-band\" download in that the returned derivation does not | ||
| 197 | explicitly depend on Git, Guile, etc. Instead, the daemon performs the | ||
| 198 | download by itself using its own dependencies." | ||
| 199 | (raw-derivation (or name "git-checkout") "builtin:git-download" '() | ||
| 200 | #:system system | ||
| 201 | #:hash-algo hash-algo | ||
| 202 | #:hash hash | ||
| 203 | #:recursive? #t | ||
| 204 | #:env-vars | ||
| 205 | `(("url" . ,(object->string | ||
| 206 | (match (%download-fallback-test) | ||
| 207 | ('content-addressed-mirrors | ||
| 208 | "https://example.org/does-not-exist") | ||
| 209 | (_ | ||
| 210 | (git-reference-url ref))))) | ||
| 211 | ("commit" . ,(git-reference-commit ref)) | ||
| 212 | ("recursive?" . ,(object->string | ||
| 213 | (git-reference-recursive? ref)))) | ||
| 214 | #:leaked-env-vars '("http_proxy" "https_proxy" | ||
| 215 | "LC_ALL" "LC_MESSAGES" "LANG" | ||
| 216 | "COLUMNS") | ||
| 217 | #:local-build? #t)) | ||
| 218 | |||
| 219 | (define built-in-builders* | ||
| 220 | (store-lift built-in-builders)) | ||
| 221 | |||
| 222 | (define* (git-fetch ref hash-algo hash | ||
| 223 | #:optional name | ||
| 224 | #:key (system (%current-system)) | ||
| 225 | guile git) | ||
| 226 | "Return a fixed-output derivation that fetches REF, a <git-reference> | ||
| 227 | object. The output is expected to have recursive hash HASH of type | ||
| 228 | HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f." | ||
| 229 | (mlet %store-monad ((builtins (built-in-builders*))) | ||
| 230 | (if (member "git-download" builtins) | ||
| 231 | (git-fetch/built-in ref hash-algo hash name | ||
| 232 | #:system system) | ||
| 233 | (git-fetch/in-band ref hash-algo hash name | ||
| 234 | #:system system | ||
| 235 | #:guile guile | ||
| 236 | #:git git)))) | ||
| 237 | |||
| 184 | (define (git-version version revision commit) | 238 | (define (git-version version revision commit) |
| 185 | "Return the version string for packages using git-download." | 239 | "Return the version string for packages using git-download." |
| 186 | ;; git-version is almost exclusively executed while modules are being loaded. | 240 | ;; git-version is almost exclusively executed while modules are being loaded. |
diff --git a/tests/builders.scm b/tests/builders.scm index 0b5577c7a3c..619caa5f313 100644 --- a/tests/builders.scm +++ b/tests/builders.scm | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | ;;; GNU Guix --- Functional package management for GNU | 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2012, 2013, 2014, 2015, 2018, 2019, 2021 Ludovic Courtès <ludo@gnu.org> | 2 | ;;; Copyright © 2012-2015, 2018-2019, 2021, 2023 Ludovic Courtès <ludo@gnu.org> |
| 3 | ;;; Copyright © 2021 Lars-Dominik Braun <lars@6xq.net> | 3 | ;;; Copyright © 2021 Lars-Dominik Braun <lars@6xq.net> |
| 4 | ;;; | 4 | ;;; |
| 5 | ;;; This file is part of GNU Guix. | 5 | ;;; This file is part of GNU Guix. |
| @@ -20,6 +20,7 @@ | |||
| 20 | 20 | ||
| 21 | (define-module (tests builders) | 21 | (define-module (tests builders) |
| 22 | #:use-module (guix download) | 22 | #:use-module (guix download) |
| 23 | #:use-module (guix git-download) | ||
| 23 | #:use-module (guix build-system) | 24 | #:use-module (guix build-system) |
| 24 | #:use-module (guix build-system gnu) | 25 | #:use-module (guix build-system gnu) |
| 25 | #:use-module (guix build gnu-build-system) | 26 | #:use-module (guix build gnu-build-system) |
| @@ -31,9 +32,12 @@ | |||
| 31 | #:use-module (guix base32) | 32 | #:use-module (guix base32) |
| 32 | #:use-module (guix derivations) | 33 | #:use-module (guix derivations) |
| 33 | #:use-module (gcrypt hash) | 34 | #:use-module (gcrypt hash) |
| 35 | #:use-module ((guix hash) #:select (file-hash*)) | ||
| 34 | #:use-module (guix tests) | 36 | #:use-module (guix tests) |
| 37 | #:use-module (guix tests git) | ||
| 35 | #:use-module (guix packages) | 38 | #:use-module (guix packages) |
| 36 | #:use-module (gnu packages bootstrap) | 39 | #:use-module (gnu packages bootstrap) |
| 40 | #:use-module ((ice-9 ftw) #:select (scandir)) | ||
| 37 | #:use-module (ice-9 match) | 41 | #:use-module (ice-9 match) |
| 38 | #:use-module (ice-9 textual-ports) | 42 | #:use-module (ice-9 textual-ports) |
| 39 | #:use-module (srfi srfi-1) | 43 | #:use-module (srfi srfi-1) |
| @@ -84,6 +88,29 @@ | |||
| 84 | (and (file-exists? out) | 88 | (and (file-exists? out) |
| 85 | (valid-path? %store out)))) | 89 | (valid-path? %store out)))) |
| 86 | 90 | ||
| 91 | (test-equal "git-fetch, file URI" | ||
| 92 | '("." ".." "a.txt" "b.scm") | ||
| 93 | (let ((nonce (random-text))) | ||
| 94 | (with-temporary-git-repository directory | ||
| 95 | `((add "a.txt" ,nonce) | ||
| 96 | (add "b.scm" "#t") | ||
| 97 | (commit "Commit.") | ||
| 98 | (tag "v1.0.0" "The tag.")) | ||
| 99 | (run-with-store %store | ||
| 100 | (mlet* %store-monad ((hash | ||
| 101 | -> (file-hash* directory | ||
| 102 | #:algorithm (hash-algorithm sha256) | ||
| 103 | #:recursive? #t)) | ||
| 104 | (drv (git-fetch | ||
| 105 | (git-reference | ||
| 106 | (url (string-append "file://" directory)) | ||
| 107 | (commit "v1.0.0")) | ||
| 108 | 'sha256 hash | ||
| 109 | "git-fetch-test"))) | ||
| 110 | (mbegin %store-monad | ||
| 111 | (built-derivations (list drv)) | ||
| 112 | (return (scandir (derivation->output-path drv))))))))) | ||
| 113 | |||
| 87 | (test-assert "gnu-build-system" | 114 | (test-assert "gnu-build-system" |
| 88 | (build-system? gnu-build-system)) | 115 | (build-system? gnu-build-system)) |
| 89 | 116 | ||
