diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2020-05-18 23:21:36 +0200 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2020-05-22 00:35:24 +0200 |
| commit | 56f7ca6e7c8b5eadeee48b00bcbd78f9fa9e5f43 (patch) | |
| tree | e7b069dfcd83f9a65aa710e247465bf7ad25ee7b | |
| parent | 0e4e9c8e7655f3e2a9c2615923768d211ac02a3e (diff) | |
packages: Add 'base64' macro.
* guix/packages.scm (define-compile-time-decoder): New macro.
(base32): Redefine in terms of it.
(base64): New macro.
| -rw-r--r-- | guix/packages.scm | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/guix/packages.scm b/guix/packages.scm index 3fff50a6e85..c1c4805ae9d 100644 --- a/guix/packages.scm +++ b/guix/packages.scm | |||
| @@ -28,6 +28,7 @@ | |||
| 28 | #:use-module (guix monads) | 28 | #:use-module (guix monads) |
| 29 | #:use-module (guix gexp) | 29 | #:use-module (guix gexp) |
| 30 | #:use-module (guix base32) | 30 | #:use-module (guix base32) |
| 31 | #:autoload (guix base64) (base64-decode) | ||
| 31 | #:use-module (guix grafts) | 32 | #:use-module (guix grafts) |
| 32 | #:use-module (guix derivations) | 33 | #:use-module (guix derivations) |
| 33 | #:use-module (guix memoization) | 34 | #:use-module (guix memoization) |
| @@ -62,6 +63,7 @@ | |||
| 62 | origin-snippet | 63 | origin-snippet |
| 63 | origin-modules | 64 | origin-modules |
| 64 | base32 | 65 | base32 |
| 66 | base64 | ||
| 65 | 67 | ||
| 66 | package | 68 | package |
| 67 | package? | 69 | package? |
| @@ -197,19 +199,24 @@ | |||
| 197 | 199 | ||
| 198 | (set-record-type-printer! <origin> print-origin) | 200 | (set-record-type-printer! <origin> print-origin) |
| 199 | 201 | ||
| 200 | (define-syntax base32 | 202 | (define-syntax-rule (define-compile-time-decoder name string->bytevector) |
| 201 | (lambda (s) | 203 | "Define NAME as a macro that runs STRING->BYTEVECTOR at macro expansion time |
| 202 | "Return the bytevector corresponding to the given Nix-base32 | 204 | if possible." |
| 205 | (define-syntax name | ||
| 206 | (lambda (s) | ||
| 207 | "Return the bytevector corresponding to the given textual | ||
| 203 | representation." | 208 | representation." |
| 204 | (syntax-case s () | 209 | (syntax-case s () |
| 205 | ((_ str) | 210 | ((_ str) |
| 206 | (string? (syntax->datum #'str)) | 211 | (string? (syntax->datum #'str)) |
| 207 | ;; A literal string: do the conversion at expansion time. | 212 | ;; A literal string: do the conversion at expansion time. |
| 208 | (with-syntax ((bv (nix-base32-string->bytevector | 213 | (with-syntax ((bv (string->bytevector (syntax->datum #'str)))) |
| 209 | (syntax->datum #'str)))) | 214 | #''bv)) |
| 210 | #''bv)) | 215 | ((_ str) |
| 211 | ((_ str) | 216 | #'(string->bytevector str)))))) |
| 212 | #'(nix-base32-string->bytevector str))))) | 217 | |
| 218 | (define-compile-time-decoder base32 nix-base32-string->bytevector) | ||
| 219 | (define-compile-time-decoder base64 base64-decode) | ||
| 213 | 220 | ||
| 214 | (define (origin-actual-file-name origin) | 221 | (define (origin-actual-file-name origin) |
| 215 | "Return the file name of ORIGIN, either its 'file-name' field or the file | 222 | "Return the file name of ORIGIN, either its 'file-name' field or the file |
