packages: Add 'base64' macro.

* guix/packages.scm (define-compile-time-decoder): New macro.
(base32): Redefine in terms of it.
(base64): New macro.
This commit is contained in:
Ludovic Courtès 2020-05-18 23:21:36 +02:00
parent 0e4e9c8e76
commit 56f7ca6e7c
No known key found for this signature in database
GPG key ID: 090B11993D9AEBB5

View file

@ -28,6 +28,7 @@ (define-module (guix packages)
#:use-module (guix monads)
#:use-module (guix gexp)
#:use-module (guix base32)
#:autoload (guix base64) (base64-decode)
#:use-module (guix grafts)
#:use-module (guix derivations)
#:use-module (guix memoization)
@ -62,6 +63,7 @@ (define-module (guix packages)
origin-snippet
origin-modules
base32
base64
package
package?
@ -197,19 +199,24 @@ (define (print-origin origin port)
(set-record-type-printer! <origin> print-origin)
(define-syntax base32
(lambda (s)
"Return the bytevector corresponding to the given Nix-base32
(define-syntax-rule (define-compile-time-decoder name string->bytevector)
"Define NAME as a macro that runs STRING->BYTEVECTOR at macro expansion time
if possible."
(define-syntax name
(lambda (s)
"Return the bytevector corresponding to the given textual
representation."
(syntax-case s ()
((_ str)
(string? (syntax->datum #'str))
;; A literal string: do the conversion at expansion time.
(with-syntax ((bv (nix-base32-string->bytevector
(syntax->datum #'str))))
#''bv))
((_ str)
#'(nix-base32-string->bytevector str)))))
(syntax-case s ()
((_ str)
(string? (syntax->datum #'str))
;; A literal string: do the conversion at expansion time.
(with-syntax ((bv (string->bytevector (syntax->datum #'str))))
#''bv))
((_ str)
#'(string->bytevector str))))))
(define-compile-time-decoder base32 nix-base32-string->bytevector)
(define-compile-time-decoder base64 base64-decode)
(define (origin-actual-file-name origin)
"Return the file name of ORIGIN, either its 'file-name' field or the file