From 629a064f3244e8cd13114842969de7e3b6b02f46 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Sun, 31 Jan 2016 20:18:52 +0100 Subject: 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. --- guix/scripts/build.scm | 77 +++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 36 deletions(-) (limited to 'guix') 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 @@ (define-module (guix scripts build) set-build-options-from-command-line set-build-options-from-command-line* show-build-options-help + options->transformation guix-build)) @@ -484,39 +485,29 @@ (define graft? (assoc-ref opts 'graft?)) (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 @@ (define %transformations `((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 -- cgit v1.2.3