mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2025-01-12 06:06:53 -05:00
gexp: Add <gexp-input>.
* guix/gexp.scm (<gexp-input>): New record type. (gexp-inputs)[add-reference-inputs]: Adjust clauses to expect <gexp-input> objects. (gexp-outputs)[add-reference-output]: Likewise. (gexp->sexp)[reference->sexp]: Likewise. (canonicalize-reference): Remove. (gexp)[escape->ref]: Use 'gexp-input' for all the references. Remove use of 'canonicalize-reference'.
This commit is contained in:
parent
1e87da58a1
commit
e39d146107
2 changed files with 69 additions and 53 deletions
113
guix/gexp.scm
113
guix/gexp.scm
|
@ -79,6 +79,14 @@ (define (write-gexp gexp port)
|
||||||
|
|
||||||
(set-record-type-printer! <gexp> write-gexp)
|
(set-record-type-printer! <gexp> write-gexp)
|
||||||
|
|
||||||
|
;; The input of a gexp.
|
||||||
|
(define-record-type <gexp-input>
|
||||||
|
(gexp-input thing output native?)
|
||||||
|
gexp-input?
|
||||||
|
(thing gexp-input-thing) ;<package> | <origin> | <derivation> | ...
|
||||||
|
(output gexp-input-output) ;string
|
||||||
|
(native? gexp-input-native?)) ;Boolean
|
||||||
|
|
||||||
;; Reference to one of the derivation's outputs, for gexps used in
|
;; Reference to one of the derivation's outputs, for gexps used in
|
||||||
;; derivations.
|
;; derivations.
|
||||||
(define-record-type <gexp-output>
|
(define-record-type <gexp-output>
|
||||||
|
@ -281,20 +289,27 @@ (define* (gexp-inputs exp #:optional (references gexp-references))
|
||||||
references."
|
references."
|
||||||
(define (add-reference-inputs ref result)
|
(define (add-reference-inputs ref result)
|
||||||
(match ref
|
(match ref
|
||||||
(((? derivation?) (? string?))
|
(($ <gexp-input> (? derivation? drv) output)
|
||||||
(cons ref result))
|
(cons `(,drv ,output) result))
|
||||||
(((? package?) (? string?))
|
(($ <gexp-input> (? package? pkg) output)
|
||||||
(cons ref result))
|
(cons `(,pkg ,output) result))
|
||||||
(((? origin?) (? string?))
|
(($ <gexp-input> (? origin? o))
|
||||||
(cons ref result))
|
(cons `(,o "out") result))
|
||||||
((? gexp? exp)
|
(($ <gexp-input> (? gexp? exp))
|
||||||
(append (gexp-inputs exp references) result))
|
(append (gexp-inputs exp references) result))
|
||||||
(((? string? file))
|
(($ <gexp-input> (? string? str))
|
||||||
(if (direct-store-path? file)
|
(if (direct-store-path? str)
|
||||||
(cons ref result)
|
(cons `(,str) result)
|
||||||
result))
|
result))
|
||||||
((refs ...)
|
(($ <gexp-input> ((? package? p) (? string? output)) _ native?)
|
||||||
(fold-right add-reference-inputs result refs))
|
;; XXX: For now, for backward-compatibility, automatically convert a
|
||||||
|
;; pair like this to an gexp-input for OUTPUT of P.
|
||||||
|
(add-reference-inputs (gexp-input p output native?) result))
|
||||||
|
(($ <gexp-input> (lst ...) output native?)
|
||||||
|
(fold-right add-reference-inputs result
|
||||||
|
;; XXX: For now, automatically convert LST to a list of
|
||||||
|
;; gexp-inputs.
|
||||||
|
(map (cut gexp-input <> output native?) lst)))
|
||||||
(_
|
(_
|
||||||
;; Ignore references to other kinds of objects.
|
;; Ignore references to other kinds of objects.
|
||||||
result)))
|
result)))
|
||||||
|
@ -312,8 +327,12 @@ (define (add-reference-output ref result)
|
||||||
(match ref
|
(match ref
|
||||||
(($ <gexp-output> name)
|
(($ <gexp-output> name)
|
||||||
(cons name result))
|
(cons name result))
|
||||||
((? gexp? exp)
|
(($ <gexp-input> (? gexp? exp))
|
||||||
(append (gexp-outputs exp) result))
|
(append (gexp-outputs exp) result))
|
||||||
|
(($ <gexp-input> (lst ...) output native?)
|
||||||
|
;; XXX: Automatically convert LST.
|
||||||
|
(add-reference-output (map (cut gexp-input <> output native?) lst)
|
||||||
|
result))
|
||||||
((lst ...)
|
((lst ...)
|
||||||
(fold-right add-reference-output result lst))
|
(fold-right add-reference-output result lst))
|
||||||
(_
|
(_
|
||||||
|
@ -330,14 +349,21 @@ (define* (gexp->sexp exp #:key
|
||||||
(define* (reference->sexp ref #:optional native?)
|
(define* (reference->sexp ref #:optional native?)
|
||||||
(with-monad %store-monad
|
(with-monad %store-monad
|
||||||
(match ref
|
(match ref
|
||||||
(((? derivation? drv) (? string? output))
|
(($ <gexp-input> (? derivation? drv) output)
|
||||||
(return (derivation->output-path drv output)))
|
(return (derivation->output-path drv output)))
|
||||||
(((? package? p) (? string? output))
|
(($ <gexp-input> (? package? p) output n?)
|
||||||
(package-file p
|
(package-file p
|
||||||
#:output output
|
#:output output
|
||||||
#:system system
|
#:system system
|
||||||
#:target (if native? #f target)))
|
#:target (if (or n? native?) #f target)))
|
||||||
(((? origin? o) (? string? output))
|
(($ <gexp-input> ((? package? p) (? string? output)) _ n?)
|
||||||
|
;; XXX: For backward compatibility, automatically interpret such a
|
||||||
|
;; pair.
|
||||||
|
(package-file p
|
||||||
|
#:output output
|
||||||
|
#:system system
|
||||||
|
#:target (if (or n? native?) #f target)))
|
||||||
|
(($ <gexp-input> (? origin? o) output)
|
||||||
(mlet %store-monad ((drv (origin->derivation o)))
|
(mlet %store-monad ((drv (origin->derivation o)))
|
||||||
(return (derivation->output-path drv output))))
|
(return (derivation->output-path drv output))))
|
||||||
(($ <gexp-output> output)
|
(($ <gexp-output> output)
|
||||||
|
@ -345,15 +371,19 @@ (define* (reference->sexp ref #:optional native?)
|
||||||
;; an environment variable for each of them at build time, so use
|
;; an environment variable for each of them at build time, so use
|
||||||
;; that trick.
|
;; that trick.
|
||||||
(return `((@ (guile) getenv) ,output)))
|
(return `((@ (guile) getenv) ,output)))
|
||||||
((? gexp? exp)
|
(($ <gexp-input> (? gexp? exp) output n?)
|
||||||
(gexp->sexp exp
|
(gexp->sexp exp
|
||||||
#:system system
|
#:system system
|
||||||
#:target (if native? #f target)))
|
#:target (if (or n? native?) #f target)))
|
||||||
(((? string? str))
|
(($ <gexp-input> (refs ...) output n?)
|
||||||
(return (if (direct-store-path? str) str ref)))
|
|
||||||
((refs ...)
|
|
||||||
(sequence %store-monad
|
(sequence %store-monad
|
||||||
(map (cut reference->sexp <> native?) refs)))
|
(map (lambda (ref)
|
||||||
|
;; XXX: Automatically convert REF to an gexp-input.
|
||||||
|
(reference->sexp (gexp-input ref "out"
|
||||||
|
(or n? native?))))
|
||||||
|
refs)))
|
||||||
|
(($ <gexp-input> x)
|
||||||
|
(return x))
|
||||||
(x
|
(x
|
||||||
(return x)))))
|
(return x)))))
|
||||||
|
|
||||||
|
@ -364,28 +394,6 @@ (define* (reference->sexp ref #:optional native?)
|
||||||
(gexp-native-references exp))))))
|
(gexp-native-references exp))))))
|
||||||
(return (apply (gexp-proc exp) args))))
|
(return (apply (gexp-proc exp) args))))
|
||||||
|
|
||||||
(define (canonicalize-reference ref)
|
|
||||||
"Return a canonical variant of REF, which adds any missing output part in
|
|
||||||
package/derivation references."
|
|
||||||
(match ref
|
|
||||||
((? package? p)
|
|
||||||
`(,p "out"))
|
|
||||||
((? origin? o)
|
|
||||||
`(,o "out"))
|
|
||||||
((? derivation? d)
|
|
||||||
`(,d "out"))
|
|
||||||
(((? package?) (? string?))
|
|
||||||
ref)
|
|
||||||
(((? origin?) (? string?))
|
|
||||||
ref)
|
|
||||||
(((? derivation?) (? string?))
|
|
||||||
ref)
|
|
||||||
((? string? s)
|
|
||||||
(if (direct-store-path? s) `(,s) s))
|
|
||||||
((refs ...)
|
|
||||||
(map canonicalize-reference refs))
|
|
||||||
(x x)))
|
|
||||||
|
|
||||||
(define (syntax-location-string s)
|
(define (syntax-location-string s)
|
||||||
"Return a string representing the source code location of S."
|
"Return a string representing the source code location of S."
|
||||||
(let ((props (syntax-source s)))
|
(let ((props (syntax-source s)))
|
||||||
|
@ -445,17 +453,17 @@ (define (escape->ref exp)
|
||||||
((ungexp output name)
|
((ungexp output name)
|
||||||
#'(gexp-output name))
|
#'(gexp-output name))
|
||||||
((ungexp thing)
|
((ungexp thing)
|
||||||
#'thing)
|
#'(gexp-input thing "out" #f))
|
||||||
((ungexp drv-or-pkg out)
|
((ungexp drv-or-pkg out)
|
||||||
#'(list drv-or-pkg out))
|
#'(gexp-input drv-or-pkg out #f))
|
||||||
((ungexp-splicing lst)
|
((ungexp-splicing lst)
|
||||||
#'lst)
|
#'(gexp-input lst "out" #f))
|
||||||
((ungexp-native thing)
|
((ungexp-native thing)
|
||||||
#'thing)
|
#'(gexp-input thing "out" #t))
|
||||||
((ungexp-native drv-or-pkg out)
|
((ungexp-native drv-or-pkg out)
|
||||||
#'(list drv-or-pkg out))
|
#'(gexp-input drv-or-pkg out #t))
|
||||||
((ungexp-native-splicing lst)
|
((ungexp-native-splicing lst)
|
||||||
#'lst)))
|
#'(gexp-input lst "out" #t))))
|
||||||
|
|
||||||
(define (substitute-ungexp exp substs)
|
(define (substitute-ungexp exp substs)
|
||||||
;; Given EXP, an 'ungexp' or 'ungexp-native' form, substitute it with
|
;; Given EXP, an 'ungexp' or 'ungexp-native' form, substitute it with
|
||||||
|
@ -506,8 +514,7 @@ (define (substitute-references exp substs)
|
||||||
(sexp (substitute-references #'exp (zip escapes formals)))
|
(sexp (substitute-references #'exp (zip escapes formals)))
|
||||||
(refs (map escape->ref normals))
|
(refs (map escape->ref normals))
|
||||||
(nrefs (map escape->ref natives)))
|
(nrefs (map escape->ref natives)))
|
||||||
#`(make-gexp (map canonicalize-reference (list #,@refs))
|
#`(make-gexp (list #,@refs) (list #,@nrefs)
|
||||||
(map canonicalize-reference (list #,@nrefs))
|
|
||||||
(lambda #,formals
|
(lambda #,formals
|
||||||
#,sexp)))))))
|
#,sexp)))))))
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ (define-module (test-profiles)
|
||||||
#:use-module (guix packages)
|
#:use-module (guix packages)
|
||||||
#:use-module (guix derivations)
|
#:use-module (guix derivations)
|
||||||
#:use-module (gnu packages bootstrap)
|
#:use-module (gnu packages bootstrap)
|
||||||
|
#:use-module ((gnu packages base) #:prefix packages:)
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
#:use-module (ice-9 regex)
|
#:use-module (ice-9 regex)
|
||||||
#:use-module (srfi srfi-11)
|
#:use-module (srfi srfi-11)
|
||||||
|
@ -191,6 +192,14 @@ (define glibc
|
||||||
(string=? (dirname (readlink bindir))
|
(string=? (dirname (readlink bindir))
|
||||||
(derivation->output-path guile))))))
|
(derivation->output-path guile))))))
|
||||||
|
|
||||||
|
(test-assertm "profile-derivation, inputs"
|
||||||
|
(mlet* %store-monad
|
||||||
|
((entry -> (package->manifest-entry packages:glibc "debug"))
|
||||||
|
(drv (profile-derivation (manifest (list entry))
|
||||||
|
#:info-dir? #f
|
||||||
|
#:ca-certificate-bundle? #f)))
|
||||||
|
(return (derivation-inputs drv))))
|
||||||
|
|
||||||
(test-end "profiles")
|
(test-end "profiles")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue