guix-package: Use more (guix ui) features.

* guix-package.in (leave): Remove.
  (guix-package): Wrap body in `with-error-handling'.
This commit is contained in:
Ludovic Courtès 2012-11-03 21:23:16 +01:00
parent cdd5d6f95f
commit 1275baeba7
1 changed files with 62 additions and 65 deletions

View File

@ -187,12 +187,6 @@ all of PACKAGES, a list of name/version/output/path tuples."
;; Alist of default option values. ;; Alist of default option values.
`((profile . ,%current-profile))) `((profile . ,%current-profile)))
(define-syntax-rule (leave fmt args ...)
"Format FMT and ARGS to the error port and exit."
(begin
(format (current-error-port) fmt args ...)
(exit 1)))
(define (show-help) (define (show-help)
(display (_ "Usage: guix-package [OPTION]... PACKAGES... (display (_ "Usage: guix-package [OPTION]... PACKAGES...
Install, remove, or upgrade PACKAGES in a single transaction.\n")) Install, remove, or upgrade PACKAGES in a single transaction.\n"))
@ -322,67 +316,70 @@ Report bugs to: ~a.~%") "@PACKAGE_BUGREPORT@"))
(setvbuf (current-error-port) _IOLBF) (setvbuf (current-error-port) _IOLBF)
(let ((opts (parse-options))) (let ((opts (parse-options)))
(parameterize ((%guile-for-build (with-error-handling
(package-derivation %store (parameterize ((%guile-for-build
(if (assoc-ref opts 'bootstrap?) (package-derivation %store
(@@ (distro packages base) (if (assoc-ref opts 'bootstrap?)
%bootstrap-guile) (@@ (distro packages base)
guile-2.0)))) %bootstrap-guile)
(let* ((dry-run? (assoc-ref opts 'dry-run?)) guile-2.0))))
(profile (assoc-ref opts 'profile)) (let* ((dry-run? (assoc-ref opts 'dry-run?))
(install (filter-map (match-lambda (profile (assoc-ref opts 'profile))
(('install . (? store-path?)) (install (filter-map (match-lambda
#f) (('install . (? store-path?))
(('install . package) #f)
(find-package package)) (('install . package)
(_ #f)) (find-package package))
opts)) (_ #f))
(drv (filter-map (match-lambda opts))
((name version sub-drv (? package? package)) (drv (filter-map (match-lambda
(package-derivation %store package)) ((name version sub-drv
(_ #f)) (? package? package))
install)) (package-derivation %store package))
(install* (append (_ #f))
(filter-map (match-lambda install))
(('install . (? store-path? path)) (install* (append
`(,(store-path-package-name path) (filter-map (match-lambda
#f #f ,path)) (('install . (? store-path? path))
(_ #f)) `(,(store-path-package-name path)
opts) #f #f ,path))
(map (lambda (tuple drv) (_ #f))
(match tuple opts)
((name version sub-drv _) (map (lambda (tuple drv)
(let ((output-path (match tuple
(derivation-path->output-path drv ((name version sub-drv _)
sub-drv))) (let ((output-path
`(,name ,version ,sub-drv ,output-path))))) (derivation-path->output-path
install drv))) drv sub-drv)))
(remove (filter-map (match-lambda `(,name ,version ,sub-drv ,output-path)))))
(('remove . package) install drv)))
package) (remove (filter-map (match-lambda
(_ #f)) (('remove . package)
opts)) package)
(packages (append install* (_ #f))
(fold alist-delete opts))
(manifest-packages (profile-manifest profile)) (packages (append install*
remove)))) (fold alist-delete
(manifest-packages
(profile-manifest profile))
remove))))
(show-what-to-build drv dry-run?) (show-what-to-build drv dry-run?)
(or dry-run? (or dry-run?
(and (build-derivations %store drv) (and (build-derivations %store drv)
(let* ((prof-drv (profile-derivation %store packages)) (let* ((prof-drv (profile-derivation %store packages))
(prof (derivation-path->output-path prof-drv)) (prof (derivation-path->output-path prof-drv))
(number (latest-profile-number profile)) (number (latest-profile-number profile))
(name (format #f "~a/~a-~a-link" (name (format #f "~a/~a-~a-link"
(dirname profile) (dirname profile)
(basename profile) (+ 1 number)))) (basename profile) (+ 1 number))))
(and (build-derivations %store (list prof-drv)) (and (build-derivations %store (list prof-drv))
(begin (begin
(symlink prof name) (symlink prof name)
(when (file-exists? profile) (when (file-exists? profile)
(delete-file profile)) (delete-file profile))
(symlink name profile)))))))))) (symlink name profile)))))))))))
;; Local Variables: ;; Local Variables:
;; eval: (put 'guard 'scheme-indent-function 1) ;; eval: (put 'guard 'scheme-indent-function 1)