summaryrefslogtreecommitdiff
path: root/guix/scripts/build.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-01-31 20:18:52 +0100
committerLudovic Courtès <ludo@gnu.org>2016-02-01 08:59:13 +0100
commit629a064f3244e8cd13114842969de7e3b6b02f46 (patch)
tree8886fc34606f4fe3d78bbbd42eea68d5e53e4c7c /guix/scripts/build.scm
parentefdcb6f29cd0fd384ed88b0b9eb65547514a79a5 (diff)
downloadguix-patches-629a064f3244e8cd13114842969de7e3b6b02f46.tar
guix-patches-629a064f3244e8cd13114842969de7e3b6b02f46.tar.gz
guix build: Transformations operate on single objects.
* guix/scripts/build.scm (transform-package-source): Return a procedure that expects a single object rather than a list of packages. (options->transformation): Rewrite to precompute the list of applicable transformations and to return a procedure that expects a single object rather than a list of objects. (options->derivations): Adjust accordingly. * tests/scripts-build.scm: New file. * Makefile.am (SCM_TESTS): Add it.
Diffstat (limited to 'guix/scripts/build.scm')
-rw-r--r--guix/scripts/build.scm77
1 files changed, 41 insertions, 36 deletions
diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
index 7ca2c6ebc8..77f7a0c3bf 100644
--- a/guix/scripts/build.scm
+++ b/guix/scripts/build.scm
@@ -41,6 +41,7 @@
set-build-options-from-command-line
set-build-options-from-command-line*
show-build-options-help
+ options->transformation
guix-build))
@@ -484,39 +485,29 @@ build."
(set-guile-for-build (default-guile))
(gexp->derivation "gexp" gexp
#:system system))))))
- (transform store (options->things-to-build opts)))))
+ (map (cut transform store <>)
+ (options->things-to-build opts)))))
(define (transform-package-source sources)
- "Return a transformation procedure that uses replaces package sources with
-the matching URIs given in SOURCES."
+ "Return a transformation procedure that replaces package sources with the
+matching URIs given in SOURCES."
(define new-sources
(map (lambda (uri)
(cons (package-name->name+version (basename uri))
uri))
sources))
- (lambda (store packages)
- (let loop ((packages packages)
- (sources new-sources)
+ (lambda (store obj)
+ (let loop ((sources new-sources)
(result '()))
- (match packages
- (()
- (unless (null? sources)
- (warning (_ "sources do not match any package:~{ ~a~}~%")
- (match sources
- (((name . uri) ...)
- uri))))
- (reverse result))
- (((? package? p) tail ...)
+ (match obj
+ ((? package? p)
(let ((source (assoc-ref sources (package-name p))))
- (loop tail
- (alist-delete (package-name p) sources)
- (cons (if source
- (package-with-source store p source)
- p)
- result))))
- ((thing tail ...)
- (loop tail sources result))))))
+ (if source
+ (package-with-source store p source)
+ p)))
+ (_
+ obj)))))
(define %transformations
;; Transformations that can be applied to things to build. The car is the
@@ -526,19 +517,33 @@ the matching URIs given in SOURCES."
`((with-source . ,transform-package-source)))
(define (options->transformation opts)
- "Return a procedure that, when passed a list of things to build (packages,
-derivations, etc.), applies the transformations specified by OPTS."
- (apply compose
- (map (match-lambda
- ((key . transform)
- (let ((args (filter-map (match-lambda
- ((k . arg)
- (and (eq? k key) arg)))
- opts)))
- (if (null? args)
- (lambda (store things) things)
- (transform args)))))
- %transformations)))
+ "Return a procedure that, when passed an object to build (package,
+derivation, etc.), applies the transformations specified by OPTS."
+ (define applicable
+ ;; List of applicable transformations as symbol/procedure pairs.
+ (filter-map (match-lambda
+ ((key . transform)
+ (match (filter-map (match-lambda
+ ((k . arg)
+ (and (eq? k key) arg)))
+ opts)
+ (() #f)
+ (args (cons key (transform args))))))
+ %transformations))
+
+ (lambda (store obj)
+ (fold (match-lambda*
+ (((name . transform) obj)
+ (let ((new (transform store obj)))
+ (when (eq? new obj)
+ (warning (_ "transformation '~a' had no effect on ~a~%")
+ name
+ (if (package? obj)
+ (package-full-name obj)
+ obj)))
+ new)))
+ obj
+ applicable)))
(define (show-build-log store file urls)
"Show the build log for FILE, falling back to remote logs from URLS if