svn-download: Reduce svn-multi-fetch builder duplication.
Rather than creating a different builder in the store for every different
download (by hash), remove the hash from the builder and pass it in via an
environment variable. This means that when svn-multi-fetch is used by two
different package sources, the derivations will still differ but the builder
will be shared.
It used to be this way, but changed with
0e73f933b2
. I noticed the hash in the builder
script when wondering why the build coordinator on bayfront was substituting
svn-multi-download files over and over again.
To try and make the effects of introducing variance in to the builder script
more obvious, separate it out in to it's own procedure, so that it's clearer
when there's new data going in that could cause variance.
* guix/svn-download.scm (svn-multi-fetch): Extract out builder script, include
hash in the derivation as an environment variable and update comment to be
more directive.
(svn-multi-fetch-builder): New procedure.
Change-Id: I83c60140ae09e189ee5e5428038a9428ecb8e281
master
parent
aed2e17768
commit
04ca393b38
|
@ -30,6 +30,7 @@
|
||||||
#:use-module ((guix build utils) #:select (mkdir-p))
|
#:use-module ((guix build utils) #:select (mkdir-p))
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
#:use-module (srfi srfi-1)
|
#:use-module (srfi srfi-1)
|
||||||
|
#:use-module (rnrs bytevectors)
|
||||||
#:export (svn-reference
|
#:export (svn-reference
|
||||||
svn-reference?
|
svn-reference?
|
||||||
svn-reference-url
|
svn-reference-url
|
||||||
|
@ -179,14 +180,7 @@ HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f."
|
||||||
(user-name svn-multi-reference-user-name (default #f))
|
(user-name svn-multi-reference-user-name (default #f))
|
||||||
(password svn-multi-reference-password (default #f)))
|
(password svn-multi-reference-password (default #f)))
|
||||||
|
|
||||||
(define* (svn-multi-fetch ref hash-algo hash
|
(define (svn-multi-fetch-builder svn hash-algo)
|
||||||
#:optional name
|
|
||||||
#:key (system (%current-system)) (guile (default-guile))
|
|
||||||
(svn (subversion-package)))
|
|
||||||
"Return a fixed-output derivation that fetches REF, a <svn-multi-reference>
|
|
||||||
object. The output is expected to have recursive hash HASH of type
|
|
||||||
HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f."
|
|
||||||
|
|
||||||
(define guile-json
|
(define guile-json
|
||||||
(module-ref (resolve-interface '(gnu packages guile)) 'guile-json-4))
|
(module-ref (resolve-interface '(gnu packages guile)) 'guile-json-4))
|
||||||
|
|
||||||
|
@ -202,69 +196,83 @@ HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f."
|
||||||
(module-ref (resolve-interface '(gnu packages base))
|
(module-ref (resolve-interface '(gnu packages base))
|
||||||
'tar)))
|
'tar)))
|
||||||
|
|
||||||
(define build
|
(with-imported-modules
|
||||||
(with-imported-modules
|
(source-module-closure '((guix build svn)
|
||||||
(source-module-closure '((guix build svn)
|
(guix build download)
|
||||||
(guix build download)
|
(guix build download-nar)
|
||||||
(guix build download-nar)
|
(guix build utils)
|
||||||
(guix build utils)
|
(guix swh)))
|
||||||
(guix swh)))
|
(with-extensions (list guile-json guile-gnutls ;for (guix swh)
|
||||||
(with-extensions (list guile-json guile-gnutls ;for (guix swh)
|
guile-lzlib)
|
||||||
guile-lzlib)
|
#~(begin
|
||||||
#~(begin
|
(use-modules (guix build svn)
|
||||||
(use-modules (guix build svn)
|
(guix build utils)
|
||||||
(guix build utils)
|
((guix build download)
|
||||||
((guix build download)
|
#:select (download-method-enabled?))
|
||||||
#:select (download-method-enabled?))
|
(guix build download-nar)
|
||||||
(guix build download-nar)
|
(guix swh)
|
||||||
(guix swh)
|
(srfi srfi-1)
|
||||||
(srfi srfi-1)
|
(ice-9 match)
|
||||||
(ice-9 match))
|
(rnrs bytevectors))
|
||||||
|
|
||||||
;; Add tar and gzip to $PATH so
|
;; Add tar and gzip to $PATH so
|
||||||
;; 'swh-download-directory-by-nar-hash' can invoke them.
|
;; 'swh-download-directory-by-nar-hash' can invoke them.
|
||||||
(set-path-environment-variable "PATH" '("bin") '(#+@tar+gzip))
|
(set-path-environment-variable "PATH" '("bin") '(#+@tar+gzip))
|
||||||
|
|
||||||
(or (every
|
(or (every
|
||||||
(lambda (location)
|
(lambda (location)
|
||||||
;; The directory must exist if we are to fetch only a
|
;; The directory must exist if we are to fetch only a
|
||||||
;; single file.
|
;; single file.
|
||||||
(unless (string-suffix? "/" location)
|
(unless (string-suffix? "/" location)
|
||||||
(mkdir-p (string-append #$output "/" (dirname location))))
|
(mkdir-p (string-append #$output "/" (dirname location))))
|
||||||
(and (download-method-enabled? 'upstream)
|
(and (download-method-enabled? 'upstream)
|
||||||
(svn-fetch (string-append (getenv "svn url") "/" location)
|
(svn-fetch (string-append (getenv "svn url") "/" location)
|
||||||
(string->number (getenv "svn revision"))
|
(string->number (getenv "svn revision"))
|
||||||
(if (string-suffix? "/" location)
|
(if (string-suffix? "/" location)
|
||||||
(string-append #$output "/" location)
|
(string-append #$output "/" location)
|
||||||
(string-append #$output "/" (dirname location)))
|
(string-append #$output "/" (dirname location)))
|
||||||
#:svn-command #+(file-append svn "/bin/svn")
|
#:svn-command #+(file-append svn "/bin/svn")
|
||||||
#:recursive? (match (getenv "svn recursive?")
|
#:recursive? (match (getenv "svn recursive?")
|
||||||
("yes" #t)
|
("yes" #t)
|
||||||
(_ #f))
|
(_ #f))
|
||||||
#:user-name (getenv "svn user name")
|
#:user-name (getenv "svn user name")
|
||||||
#:password (getenv "svn password"))))
|
#:password (getenv "svn password"))))
|
||||||
(call-with-input-string (getenv "svn locations")
|
(call-with-input-string (getenv "svn locations")
|
||||||
read))
|
read))
|
||||||
(begin
|
(begin
|
||||||
(when (file-exists? #$output)
|
(when (file-exists? #$output)
|
||||||
(delete-file-recursively #$output))
|
(delete-file-recursively #$output))
|
||||||
(or (and (download-method-enabled? 'nar)
|
(or (and (download-method-enabled? 'nar)
|
||||||
(download-nar #$output))
|
(download-nar #$output))
|
||||||
(and (download-method-enabled? 'swh)
|
(and (download-method-enabled? 'swh)
|
||||||
;; SWH keeps HASH as an ExtID for the combination
|
;; SWH keeps HASH as an ExtID for the combination
|
||||||
;; of files/directories, which allows us to
|
;; of files/directories, which allows us to
|
||||||
;; retrieve the entire combination at once:
|
;; retrieve the entire combination at once:
|
||||||
;; <https://gitlab.softwareheritage.org/swh/infra/sysadm-environment/-/issues/5263>.
|
;; <https://gitlab.softwareheritage.org/swh/infra/sysadm-environment/-/issues/5263>.
|
||||||
(parameterize ((%verify-swh-certificate? #f))
|
(parameterize ((%verify-swh-certificate? #f))
|
||||||
(swh-download-directory-by-nar-hash
|
(swh-download-directory-by-nar-hash
|
||||||
#$hash '#$hash-algo #$output))))))))))
|
(u8-list->bytevector
|
||||||
|
(map string->number
|
||||||
|
(string-split (getenv "hash") #\,)))
|
||||||
|
'#$hash-algo
|
||||||
|
#$output))))))))))
|
||||||
|
|
||||||
|
(define* (svn-multi-fetch ref hash-algo hash
|
||||||
|
#:optional name
|
||||||
|
#:key (system (%current-system)) (guile (default-guile))
|
||||||
|
(svn (subversion-package)))
|
||||||
|
"Return a fixed-output derivation that fetches REF, a <svn-multi-reference>
|
||||||
|
object. The output is expected to have recursive hash HASH of type
|
||||||
|
HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f."
|
||||||
(mlet %store-monad ((guile (package->derivation guile system)))
|
(mlet %store-monad ((guile (package->derivation guile system)))
|
||||||
(gexp->derivation (or name "svn-checkout") build
|
(gexp->derivation (or name "svn-checkout")
|
||||||
|
;; Avoid the builder differing for every single use as
|
||||||
;; Use environment variables and a fixed script name so
|
;; having less builder is more efficient for computing
|
||||||
;; there's only one script in store for all the
|
;; derivations.
|
||||||
;; downloads.
|
;;
|
||||||
|
;; Don't pass package specific data in to the following
|
||||||
|
;; procedure, use #:env-vars below instead.
|
||||||
|
(svn-multi-fetch-builder svn hash-algo)
|
||||||
#:script-name "svn-multi-download"
|
#:script-name "svn-multi-download"
|
||||||
#:env-vars
|
#:env-vars
|
||||||
`(("svn url" . ,(svn-multi-reference-url ref))
|
`(("svn url" . ,(svn-multi-reference-url ref))
|
||||||
|
@ -286,7 +294,14 @@ HASH-ALGO (a symbol). Use NAME as the file name, or a generic name if #f."
|
||||||
,@(match (getenv "GUIX_DOWNLOAD_METHODS")
|
,@(match (getenv "GUIX_DOWNLOAD_METHODS")
|
||||||
(#f '())
|
(#f '())
|
||||||
(value
|
(value
|
||||||
`(("GUIX_DOWNLOAD_METHODS" . ,value)))))
|
`(("GUIX_DOWNLOAD_METHODS" . ,value))))
|
||||||
|
;; To avoid pulling in (guix base32) in the builder
|
||||||
|
;; script, use bytevector->u8-list from (rnrs
|
||||||
|
;; bytevectors)
|
||||||
|
("hash" . ,(string-join
|
||||||
|
(map number->string
|
||||||
|
(bytevector->u8-list hash))
|
||||||
|
",")))
|
||||||
|
|
||||||
#:leaked-env-vars '("http_proxy" "https_proxy"
|
#:leaked-env-vars '("http_proxy" "https_proxy"
|
||||||
"LC_ALL" "LC_MESSAGES" "LANG"
|
"LC_ALL" "LC_MESSAGES" "LANG"
|
||||||
|
|
Reference in New Issue