gexp: Add 'mixed-text-file'.
* guix/gexp.scm (mixed-text-file): New procedure. * tests/gexp.scm ("mixed-text-file"): New test. * doc/guix.texi (G-Expressions): Document it.
This commit is contained in:
parent
15a01c7220
commit
b751cde36b
|
@ -3463,6 +3463,19 @@ will references @var{coreutils}, @var{grep}, and @var{sed}, thereby
|
||||||
preventing them from being garbage-collected during its lifetime.
|
preventing them from being garbage-collected during its lifetime.
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
||||||
|
@deffn {Scheme Procedure} mixed-text-file @var{name} @var{text} @dots{}
|
||||||
|
Return an object representing store file @var{name} containing
|
||||||
|
@var{text}. @var{text} is a sequence of strings and file-like objects,
|
||||||
|
as in:
|
||||||
|
|
||||||
|
@example
|
||||||
|
(mixed-text-file "profile"
|
||||||
|
"export PATH=" coreutils "/bin:" grep "/bin")
|
||||||
|
@end example
|
||||||
|
|
||||||
|
This is the declarative counterpart of @code{text-file*}.
|
||||||
|
@end deffn
|
||||||
|
|
||||||
Of course, in addition to gexps embedded in ``host'' code, there are
|
Of course, in addition to gexps embedded in ``host'' code, there are
|
||||||
also modules containing build tools. To make it clear that they are
|
also modules containing build tools. To make it clear that they are
|
||||||
meant to be used in the build stratum, these modules are kept in the
|
meant to be used in the build stratum, these modules are kept in the
|
||||||
|
|
|
@ -61,6 +61,7 @@
|
||||||
gexp->file
|
gexp->file
|
||||||
gexp->script
|
gexp->script
|
||||||
text-file*
|
text-file*
|
||||||
|
mixed-text-file
|
||||||
imported-files
|
imported-files
|
||||||
imported-modules
|
imported-modules
|
||||||
compiled-modules
|
compiled-modules
|
||||||
|
@ -969,6 +970,21 @@ resulting store file holds references to all these."
|
||||||
|
|
||||||
(gexp->derivation name builder))
|
(gexp->derivation name builder))
|
||||||
|
|
||||||
|
(define* (mixed-text-file name #:rest text)
|
||||||
|
"Return an object representing store file NAME containing TEXT. TEXT is a
|
||||||
|
sequence of strings and file-like objects, as in:
|
||||||
|
|
||||||
|
(mixed-text-file \"profile\"
|
||||||
|
\"export PATH=\" coreutils \"/bin:\" grep \"/bin\")
|
||||||
|
|
||||||
|
This is the declarative counterpart of 'text-file*'."
|
||||||
|
(define build
|
||||||
|
(gexp (call-with-output-file (ungexp output "out")
|
||||||
|
(lambda (port)
|
||||||
|
(display (string-append (ungexp-splicing text)) port)))))
|
||||||
|
|
||||||
|
(computed-file name build))
|
||||||
|
|
||||||
|
|
||||||
;;;
|
;;;
|
||||||
;;; Syntactic sugar.
|
;;; Syntactic sugar.
|
||||||
|
|
|
@ -660,6 +660,21 @@
|
||||||
file)))))
|
file)))))
|
||||||
#:guile-for-build (package-derivation %store %bootstrap-guile))))
|
#:guile-for-build (package-derivation %store %bootstrap-guile))))
|
||||||
|
|
||||||
|
(test-assertm "mixed-text-file"
|
||||||
|
(mlet* %store-monad ((file -> (mixed-text-file "mixed"
|
||||||
|
"export PATH="
|
||||||
|
%bootstrap-guile "/bin"))
|
||||||
|
(drv (lower-object file))
|
||||||
|
(out -> (derivation->output-path drv))
|
||||||
|
(guile-drv (package->derivation %bootstrap-guile))
|
||||||
|
(guile -> (derivation->output-path guile-drv)))
|
||||||
|
(mbegin %store-monad
|
||||||
|
(built-derivations (list drv))
|
||||||
|
(mlet %store-monad ((refs ((store-lift references) out)))
|
||||||
|
(return (and (string=? (string-append "export PATH=" guile "/bin")
|
||||||
|
(call-with-input-file out get-string-all))
|
||||||
|
(equal? refs (list guile))))))))
|
||||||
|
|
||||||
(test-assert "gexp->derivation vs. %current-target-system"
|
(test-assert "gexp->derivation vs. %current-target-system"
|
||||||
(let ((mval (gexp->derivation "foo"
|
(let ((mval (gexp->derivation "foo"
|
||||||
#~(begin
|
#~(begin
|
||||||
|
|
Loading…
Reference in New Issue