summaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2016-01-31 20:44:21 +0100
committerLudovic Courtès <ludo@gnu.org>2016-02-01 08:59:13 +0100
commit88ad6deda6dc25ac752074d402879594142a5a9f (patch)
tree329c2b57e8f8215ca3a2a9827ce6f4ba34f5f52d /guix
parentccd7158d2ab182713891701e08970dbd6b68f4e5 (diff)
guix build: Separate transformation options.
* guix/scripts/build.scm (%transformation-options): New variable. (show-transformation-options-help): New procedure. (show-help): Remove '--with-source' documentation and add 'show-transformation-options-help' call. (%options): Remove "with-source" and append %TRANSFORMATION-OPTIONS. * doc/guix.texi (Package Transformation Options): New node. Document '--with-source', moved from... (Additional Build Options): ... here.
Diffstat (limited to 'guix')
-rw-r--r--guix/scripts/build.scm159
1 files changed, 89 insertions, 70 deletions
diff --git a/guix/scripts/build.scm b/guix/scripts/build.scm
index 77f7a0c3bf..b37d923b3a 100644
--- a/guix/scripts/build.scm
+++ b/guix/scripts/build.scm
@@ -41,7 +41,10 @@
set-build-options-from-command-line
set-build-options-from-command-line*
show-build-options-help
+
+ %transformation-options
options->transformation
+ show-transformation-options-help
guix-build))
@@ -142,6 +145,82 @@ the new package's version number from URI."
;;;
+;;; Transformations.
+;;;
+
+(define (transform-package-source 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 obj)
+ (let loop ((sources new-sources)
+ (result '()))
+ (match obj
+ ((? package? p)
+ (let ((source (assoc-ref sources (package-name p))))
+ (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
+ ;; key used in the option alist, and the cdr is the transformation
+ ;; procedure; it is called with two arguments: the store, and a list of
+ ;; things to build.
+ `((with-source . ,transform-package-source)))
+
+(define %transformation-options
+ ;; The command-line interface to the above transformations.
+ (list (option '("with-source") #t #f
+ (lambda (opt name arg result . rest)
+ (apply values
+ (cons (alist-cons 'with-source arg result)
+ rest))))))
+
+(define (show-transformation-options-help)
+ (display (_ "
+ --with-source=SOURCE
+ use SOURCE when building the corresponding package")))
+
+
+(define (options->transformation opts)
+ "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)))
+
+
+;;;
;;; Standard command-line build options.
;;;
@@ -321,9 +400,6 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n"))
(display (_ "
--target=TRIPLET cross-build for TRIPLET--e.g., \"armel-linux-gnu\""))
(display (_ "
- --with-source=SOURCE
- use SOURCE when building the corresponding package"))
- (display (_ "
--no-grafts do not graft packages"))
(display (_ "
-d, --derivations return the derivation paths of the given packages"))
@@ -337,6 +413,8 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n"))
(newline)
(show-build-options-help)
(newline)
+ (show-transformation-options-help)
+ (newline)
(display (_ "
-h, --help display this help and exit"))
(display (_ "
@@ -369,12 +447,12 @@ Build the given PACKAGE-OR-DERIVATION and return their output paths.\n"))
(leave (_ "invalid argument: '~a' option argument: ~a, ~
must be one of 'package', 'all', or 'transitive'~%")
name arg)))))
- (option '("check") #f #f
- (lambda (opt name arg result . rest)
- (apply values
- (alist-cons 'build-mode (build-mode check)
- result)
- rest)))
+ (option '("check") #f #f
+ (lambda (opt name arg result . rest)
+ (apply values
+ (alist-cons 'build-mode (build-mode check)
+ result)
+ rest)))
(option '(#\s "system") #t #f
(lambda (opt name arg result)
(alist-cons 'system arg
@@ -401,15 +479,13 @@ must be one of 'package', 'all', or 'transitive'~%")
(option '("log-file") #f #f
(lambda (opt name arg result)
(alist-cons 'log-file? #t result)))
- (option '("with-source") #t #f
- (lambda (opt name arg result)
- (alist-cons 'with-source arg result)))
(option '("no-grafts") #f #f
(lambda (opt name arg result)
(alist-cons 'graft? #f
(alist-delete 'graft? result eq?))))
- %standard-build-options))
+ (append %transformation-options
+ %standard-build-options)))
(define (options->things-to-build opts)
"Read the arguments from OPTS and return a list of high-level objects to
@@ -488,63 +564,6 @@ build."
(map (cut transform store <>)
(options->things-to-build opts)))))
-(define (transform-package-source 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 obj)
- (let loop ((sources new-sources)
- (result '()))
- (match obj
- ((? package? p)
- (let ((source (assoc-ref sources (package-name p))))
- (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
- ;; key used in the option alist, and the cdr is the transformation
- ;; procedure; it is called with two arguments: the store, and a list of
- ;; things to build.
- `((with-source . ,transform-package-source)))
-
-(define (options->transformation opts)
- "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
needed."