Skip to content
Snippets Groups Projects
Commit 558e8b11 authored by Ludovic Courtès's avatar Ludovic Courtès
Browse files

gexp: Add 'plain-file'.

* guix/gexp.scm (<plain-file>): New type.
  (plain-file, plain-file-compiler): New procedures.
* tests/gexp.scm ("one plain file"): New test.
* doc/guix.texi (G-Expressions): Document 'plain-file'.
parent 74d441ab
No related branches found
No related tags found
No related merge requests found
...@@ -2948,7 +2948,8 @@ derivations can be defined, such that these objects can also be inserted ...@@ -2948,7 +2948,8 @@ derivations can be defined, such that these objects can also be inserted
into gexps. Another useful type of high-level object that can be into gexps. Another useful type of high-level object that can be
inserted in a gexp is @dfn{local files}, which allows files from the inserted in a gexp is @dfn{local files}, which allows files from the
local file system to be added to the store and referred to by local file system to be added to the store and referred to by
derivations and such (see @code{local-file} below.) derivations and such (see @code{local-file} and @code{plain-file}
below.)
To illustrate the idea, here is an example of a gexp: To illustrate the idea, here is an example of a gexp:
...@@ -3126,6 +3127,13 @@ This is the declarative counterpart of the @code{interned-file} monadic ...@@ -3126,6 +3127,13 @@ This is the declarative counterpart of the @code{interned-file} monadic
procedure (@pxref{The Store Monad, @code{interned-file}}). procedure (@pxref{The Store Monad, @code{interned-file}}).
@end deffn @end deffn
@deffn {Scheme Procedure} plain-file @var{name} @var{content}
Return an object representing a text file called @var{name} with the given
@var{content} (a string) to be added to the store.
This is the declarative counterpart of @code{text-file}.
@end deffn
@deffn {Monadic Procedure} gexp->script @var{name} @var{exp} @deffn {Monadic Procedure} gexp->script @var{name} @var{exp}
Return an executable script @var{name} that runs @var{exp} using Return an executable script @var{name} that runs @var{exp} using
@var{guile} with @var{modules} in its search path. @var{guile} with @var{modules} in its search path.
......
...@@ -31,12 +31,18 @@ (define-module (guix gexp) ...@@ -31,12 +31,18 @@ (define-module (guix gexp)
gexp-input gexp-input
gexp-input? gexp-input?
local-file local-file
local-file? local-file?
local-file-file local-file-file
local-file-name local-file-name
local-file-recursive? local-file-recursive?
plain-file
plain-file?
plain-file-name
plain-file-content
gexp->derivation gexp->derivation
gexp->file gexp->file
gexp->script gexp->script
...@@ -140,7 +146,7 @@ (define-gexp-compiler (derivation-compiler (drv derivation?) system target) ...@@ -140,7 +146,7 @@ (define-gexp-compiler (derivation-compiler (drv derivation?) system target)
;;; ;;;
;;; Local files. ;;; File declarations.
;;; ;;;
(define-record-type <local-file> (define-record-type <local-file>
...@@ -169,6 +175,28 @@ (define-gexp-compiler (local-file-compiler (file local-file?) system target) ...@@ -169,6 +175,28 @@ (define-gexp-compiler (local-file-compiler (file local-file?) system target)
(($ <local-file> file name recursive?) (($ <local-file> file name recursive?)
(interned-file file name #:recursive? recursive?)))) (interned-file file name #:recursive? recursive?))))
(define-record-type <plain-file>
(%plain-file name content references)
plain-file?
(name plain-file-name) ;string
(content plain-file-content) ;string
(references plain-file-references)) ;list (currently unused)
(define (plain-file name content)
"Return an object representing a text file called NAME with the given
CONTENT (a string) to be added to the store.
This is the declarative counterpart of 'text-file'."
;; XXX: For now just ignore 'references' because it's not clear how to use
;; them in a declarative context.
(%plain-file name content '()))
(define-gexp-compiler (plain-file-compiler (file plain-file?) system target)
;; "Compile" FILE by adding it to the store.
(match file
(($ <plain-file> name content references)
(text-file name content references))))
;;; ;;;
;;; Inputs & outputs. ;;; Inputs & outputs.
......
...@@ -109,6 +109,16 @@ (define-syntax-rule (test-assertm name exp) ...@@ -109,6 +109,16 @@ (define-syntax-rule (test-assertm name exp)
(eq? x local))) (eq? x local)))
(equal? `(display ,intd) (gexp->sexp* exp))))) (equal? `(display ,intd) (gexp->sexp* exp)))))
(test-assert "one plain file"
(let* ((file (plain-file "hi" "Hello, world!"))
(exp (gexp (display (ungexp file))))
(expected (add-text-to-store %store "hi" "Hello, world!")))
(and (gexp? exp)
(match (gexp-inputs exp)
(((x "out"))
(eq? x file)))
(equal? `(display ,expected) (gexp->sexp* exp)))))
(test-assert "same input twice" (test-assert "same input twice"
(let ((exp (gexp (begin (let ((exp (gexp (begin
(display (ungexp coreutils)) (display (ungexp coreutils))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment