diff options
author | Ludovic Courtès <ludo@gnu.org> | 2013-03-01 21:55:42 +0100 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2013-03-01 21:55:42 +0100 |
commit | eb0880e71d326753829a41b7afd66392960434cc (patch) | |
tree | 94fe7fc3f4773c23ae21032f15df9a0858b917ed /guix/ui.scm | |
parent | 5d4b411f8a3372455a8c92d10a28e88e9edba6eb (diff) | |
download | gnu-guix-eb0880e71d326753829a41b7afd66392960434cc.tar gnu-guix-eb0880e71d326753829a41b7afd66392960434cc.tar.gz |
ui: Factorize `read/eval-package-expression'.
* guix/scripts/package.scm (read/eval-package-expression): Move to...
* guix/ui.scm (read/eval-package-expression): ... here.
* guix/scripts/build.scm (derivations-from-package-expressions): Use it.
Diffstat (limited to 'guix/ui.scm')
-rw-r--r-- | guix/ui.scm | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/guix/ui.scm b/guix/ui.scm index 7e0c61b4f8..03d881a428 100644 --- a/guix/ui.scm +++ b/guix/ui.scm @@ -38,6 +38,7 @@ show-what-to-build call-with-error-handling with-error-handling + read/eval-package-expression location->string call-with-temporary-output-file switch-symlinks @@ -116,6 +117,26 @@ General help using GNU software: <http://www.gnu.org/gethelp/>")) (nix-protocol-error-message c)))) (thunk))) +(define (read/eval-package-expression str) + "Read and evaluate STR and return the package it refers to, or exit an +error." + (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))))) + (define* (show-what-to-build store drv #:optional dry-run?) "Show what will or would (depending on DRY-RUN?) be built in realizing the derivations listed in DRV. Return #t if there's something to build, #f |