packages: Factorize things common to `package-{,cross-}derivation'.

* guix/packages.scm (expand-input): New procedure, moved out of...
  (package-derivation): ... here.  Adjust accordingly.
  (package-cross-derivation): Add `cross-system' and `system'
  parameters.
This commit is contained in:
Ludovic Courtès 2013-05-20 23:00:47 +02:00
parent 7046c48d72
commit a63062b55a
1 changed files with 41 additions and 31 deletions

View File

@ -27,6 +27,7 @@
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9 gnu)
#:use-module (srfi srfi-11)
#:use-module (srfi srfi-26)
#:use-module (srfi srfi-34)
#:use-module (srfi srfi-35)
#:re-export (%current-system)
@ -305,24 +306,26 @@ Return the cached result when available."
(#f
(cache package system thunk)))))
(define* (package-derivation store package
#:optional (system (%current-system)))
"Return the derivation path and corresponding <derivation> object of
PACKAGE for SYSTEM."
(define* (expand-input store package input system #:optional cross-system)
"Expand INPUT, an input tuple, such that it contains only references to
derivation paths or store paths. PACKAGE is only used to provide contextual
information in exceptions."
(define (intern file)
;; Add FILE to the store. Set the `recursive?' bit to #t, so that
;; file permissions are preserved.
(add-to-store store (basename file) #t "sha256" file))
(define expand-input
;; Expand the given input tuple such that it contains only
;; references to derivation paths or store paths.
(match-lambda
(define derivation
(if cross-system
(cut package-cross-derivation store <> cross-system system)
(cut package-derivation store <> system)))
(match input
(((? string? name) (? package? package))
(list name (package-derivation store package system)))
(list name (derivation package)))
(((? string? name) (? package? package)
(? string? sub-drv))
(list name (package-derivation store package system)
(list name (derivation package)
sub-drv))
(((? string? name)
(and (? string?) (? derivation-path?) drv))
@ -340,6 +343,10 @@ PACKAGE for SYSTEM."
(package package)
(input x)))))))
(define* (package-derivation store package
#:optional (system (%current-system)))
"Return the derivation path and corresponding <derivation> object of
PACKAGE for SYSTEM."
;; Compute the derivation and cache the result. Caching is important
;; because some derivations, such as the implicit inputs of the GNU build
;; system, will be queried many, many times in a row.
@ -353,7 +360,9 @@ PACKAGE for SYSTEM."
args inputs propagated-inputs native-inputs self-native-input?
outputs)
(let* ((inputs (package-transitive-inputs package))
(input-drvs (map expand-input inputs))
(input-drvs (map (cut expand-input
store package <> system)
inputs))
(paths (delete-duplicates
(append-map (match-lambda
((_ (? package? p) _ ...)
@ -371,7 +380,8 @@ PACKAGE for SYSTEM."
#:outputs outputs #:system system
(args))))))))
(define* (package-cross-derivation store package)
(define* (package-cross-derivation store package cross-system
#:optional (system (%current-system)))
;; TODO
#f)