diff options
| -rw-r--r-- | doc/guix.texi | 10 | ||||
| -rw-r--r-- | guix/gexp.scm | 30 | ||||
| -rw-r--r-- | tests/gexp.scm | 10 |
3 files changed, 48 insertions, 2 deletions
diff --git a/doc/guix.texi b/doc/guix.texi index 2d10ec9b598..665bdb028d7 100644 --- a/doc/guix.texi +++ b/doc/guix.texi | |||
| @@ -2948,7 +2948,8 @@ derivations can be defined, such that these objects can also be inserted | |||
| 2948 | into gexps. Another useful type of high-level object that can be | 2948 | into gexps. Another useful type of high-level object that can be |
| 2949 | inserted in a gexp is @dfn{local files}, which allows files from the | 2949 | inserted in a gexp is @dfn{local files}, which allows files from the |
| 2950 | local file system to be added to the store and referred to by | 2950 | local file system to be added to the store and referred to by |
| 2951 | derivations and such (see @code{local-file} below.) | 2951 | derivations and such (see @code{local-file} and @code{plain-file} |
| 2952 | below.) | ||
| 2952 | 2953 | ||
| 2953 | To illustrate the idea, here is an example of a gexp: | 2954 | To illustrate the idea, here is an example of a gexp: |
| 2954 | 2955 | ||
| @@ -3126,6 +3127,13 @@ This is the declarative counterpart of the @code{interned-file} monadic | |||
| 3126 | procedure (@pxref{The Store Monad, @code{interned-file}}). | 3127 | procedure (@pxref{The Store Monad, @code{interned-file}}). |
| 3127 | @end deffn | 3128 | @end deffn |
| 3128 | 3129 | ||
| 3130 | @deffn {Scheme Procedure} plain-file @var{name} @var{content} | ||
| 3131 | Return an object representing a text file called @var{name} with the given | ||
| 3132 | @var{content} (a string) to be added to the store. | ||
| 3133 | |||
| 3134 | This is the declarative counterpart of @code{text-file}. | ||
| 3135 | @end deffn | ||
| 3136 | |||
| 3129 | @deffn {Monadic Procedure} gexp->script @var{name} @var{exp} | 3137 | @deffn {Monadic Procedure} gexp->script @var{name} @var{exp} |
| 3130 | Return an executable script @var{name} that runs @var{exp} using | 3138 | Return an executable script @var{name} that runs @var{exp} using |
| 3131 | @var{guile} with @var{modules} in its search path. | 3139 | @var{guile} with @var{modules} in its search path. |
diff --git a/guix/gexp.scm b/guix/gexp.scm index 03b4cbf19e3..10056e5a1f8 100644 --- a/guix/gexp.scm +++ b/guix/gexp.scm | |||
| @@ -31,12 +31,18 @@ | |||
| 31 | 31 | ||
| 32 | gexp-input | 32 | gexp-input |
| 33 | gexp-input? | 33 | gexp-input? |
| 34 | |||
| 34 | local-file | 35 | local-file |
| 35 | local-file? | 36 | local-file? |
| 36 | local-file-file | 37 | local-file-file |
| 37 | local-file-name | 38 | local-file-name |
| 38 | local-file-recursive? | 39 | local-file-recursive? |
| 39 | 40 | ||
| 41 | plain-file | ||
| 42 | plain-file? | ||
| 43 | plain-file-name | ||
| 44 | plain-file-content | ||
| 45 | |||
| 40 | gexp->derivation | 46 | gexp->derivation |
| 41 | gexp->file | 47 | gexp->file |
| 42 | gexp->script | 48 | gexp->script |
| @@ -140,7 +146,7 @@ cross-compiling.)" | |||
| 140 | 146 | ||
| 141 | 147 | ||
| 142 | ;;; | 148 | ;;; |
| 143 | ;;; Local files. | 149 | ;;; File declarations. |
| 144 | ;;; | 150 | ;;; |
| 145 | 151 | ||
| 146 | (define-record-type <local-file> | 152 | (define-record-type <local-file> |
| @@ -169,6 +175,28 @@ This is the declarative counterpart of the 'interned-file' monadic procedure." | |||
| 169 | (($ <local-file> file name recursive?) | 175 | (($ <local-file> file name recursive?) |
| 170 | (interned-file file name #:recursive? recursive?)))) | 176 | (interned-file file name #:recursive? recursive?)))) |
| 171 | 177 | ||
| 178 | (define-record-type <plain-file> | ||
| 179 | (%plain-file name content references) | ||
| 180 | plain-file? | ||
| 181 | (name plain-file-name) ;string | ||
| 182 | (content plain-file-content) ;string | ||
| 183 | (references plain-file-references)) ;list (currently unused) | ||
| 184 | |||
| 185 | (define (plain-file name content) | ||
| 186 | "Return an object representing a text file called NAME with the given | ||
| 187 | CONTENT (a string) to be added to the store. | ||
| 188 | |||
| 189 | This is the declarative counterpart of 'text-file'." | ||
| 190 | ;; XXX: For now just ignore 'references' because it's not clear how to use | ||
| 191 | ;; them in a declarative context. | ||
| 192 | (%plain-file name content '())) | ||
| 193 | |||
| 194 | (define-gexp-compiler (plain-file-compiler (file plain-file?) system target) | ||
| 195 | ;; "Compile" FILE by adding it to the store. | ||
| 196 | (match file | ||
| 197 | (($ <plain-file> name content references) | ||
| 198 | (text-file name content references)))) | ||
| 199 | |||
| 172 | 200 | ||
| 173 | ;;; | 201 | ;;; |
| 174 | ;;; Inputs & outputs. | 202 | ;;; Inputs & outputs. |
diff --git a/tests/gexp.scm b/tests/gexp.scm index f81ef39860a..7e14073fd4f 100644 --- a/tests/gexp.scm +++ b/tests/gexp.scm | |||
| @@ -109,6 +109,16 @@ | |||
| 109 | (eq? x local))) | 109 | (eq? x local))) |
| 110 | (equal? `(display ,intd) (gexp->sexp* exp))))) | 110 | (equal? `(display ,intd) (gexp->sexp* exp))))) |
| 111 | 111 | ||
| 112 | (test-assert "one plain file" | ||
| 113 | (let* ((file (plain-file "hi" "Hello, world!")) | ||
| 114 | (exp (gexp (display (ungexp file)))) | ||
| 115 | (expected (add-text-to-store %store "hi" "Hello, world!"))) | ||
| 116 | (and (gexp? exp) | ||
| 117 | (match (gexp-inputs exp) | ||
| 118 | (((x "out")) | ||
| 119 | (eq? x file))) | ||
| 120 | (equal? `(display ,expected) (gexp->sexp* exp))))) | ||
| 121 | |||
| 112 | (test-assert "same input twice" | 122 | (test-assert "same input twice" |
| 113 | (let ((exp (gexp (begin | 123 | (let ((exp (gexp (begin |
| 114 | (display (ungexp coreutils)) | 124 | (display (ungexp coreutils)) |
