diff options
author | Ludovic Courtès <ludo@gnu.org> | 2013-11-18 23:08:20 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2013-11-18 23:08:20 +0100 |
commit | ac5de156ae5de8cb61870469863fb862b6a1205e (patch) | |
tree | b1c13b61c7d3a66e1879f4b3eca28ae8f471e970 /guix/ui.scm | |
parent | e900c5031f4ecf5ac3f131a908a2616871793f8c (diff) | |
download | gnu-guix-ac5de156ae5de8cb61870469863fb862b6a1205e.tar gnu-guix-ac5de156ae5de8cb61870469863fb862b6a1205e.tar.gz |
guix build: '-e' can be passed a monadic thunk.
* guix/ui.scm (read/eval): New procedure.
(read/eval-package-expression): Use it.
* guix/scripts/build.scm (derivations-from-package-expressions): Rename to...
(derivation-from-expression): ... this. Accept procedures, under the
assumption that they are monadic thunk.
(show-help): Adjust accordingly.
(guix-build): Ditto.
* tests/guix-build.sh: Add test.
* doc/guix.texi (Invoking guix build): Augment description of '-e'.
Diffstat (limited to 'guix/ui.scm')
-rw-r--r-- | guix/ui.scm | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/guix/ui.scm b/guix/ui.scm index 8a28574c3c..f15419f7a8 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -45,6 +45,7 @@ show-what-to-build call-with-error-handling with-error-handling + read/eval read/eval-package-expression location->string switch-symlinks @@ -193,25 +194,29 @@ General help using GNU software: <http://www.gnu.org/gethelp/>")) (leave (_ "~a~%") (strerror (system-error-errno args))))))) -(define (read/eval-package-expression str) - "Read and evaluate STR and return the package it refers to, or exit an -error." +(define (read/eval str) + "Read and evaluate STR, raising an error if something goes wrong." (let ((exp (catch #t (lambda () (call-with-input-string str read)) (lambda args (leave (_ "failed to read expression ~s: ~s~%") str args))))) - (let ((p (catch #t - (lambda () - (eval exp the-scm-module)) - (lambda args - (leave (_ "failed to evaluate expression `~a': ~s~%") - exp args))))) - (if (package? p) - p - (leave (_ "expression `~s' does not evaluate to a package~%") - exp))))) + (catch #t + (lambda () + (eval exp the-scm-module)) + (lambda args + (leave (_ "failed to evaluate expression `~a': ~s~%") + exp args))))) + +(define (read/eval-package-expression str) + "Read and evaluate STR and return the package it refers to, or exit an +error." + (match (read/eval str) + ((? package? p) p) + (_ + (leave (_ "expression ~s does not evaluate to a package~%") + str)))) (define* (show-what-to-build store drv #:key dry-run? (use-substitutes? #t)) |