[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug#41382] [PATCH 6/6] packages: Add 'base64' macro.
From: |
Ludovic Courtès |
Subject: |
[bug#41382] [PATCH 6/6] packages: Add 'base64' macro. |
Date: |
Mon, 18 May 2020 23:32:44 +0200 |
* guix/packages.scm (define-compile-time-decoder): New macro.
(base32): Redefine in terms of it.
(base64): New macro.
---
guix/packages.scm | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/guix/packages.scm b/guix/packages.scm
index 7cf4c9c3e6..724d7693c7 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -28,6 +28,7 @@
#: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 @@
origin-snippet
origin-modules
base32
+ base64
package
package?
@@ -198,19 +200,24 @@
(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
--
2.26.2
- [bug#41382] [PATCH 0/6] Allow for a cryptographic hash function migration, Ludovic Courtès, 2020/05/18
- [bug#41382] [PATCH 1/6] tests: Test 'add-to-store' with several hash algorithms., Ludovic Courtès, 2020/05/18
- [bug#41382] [PATCH 3/6] guix hash, guix download: Add '--hash'., Ludovic Courtès, 2020/05/18
- [bug#41382] [PATCH 2/6] tests: Test fixed-output derivations with several hash algorithms., Ludovic Courtès, 2020/05/18
- [bug#41382] [PATCH 5/6] packages: Add 'sha512' optional field to <origin>., Ludovic Courtès, 2020/05/18
- [bug#41382] [PATCH 4/6] guix hash, guix download: Support base64 format., Ludovic Courtès, 2020/05/18
- [bug#41382] [PATCH 6/6] packages: Add 'base64' macro.,
Ludovic Courtès <=
- [bug#41382] [PATCH 0/6] Allow for a cryptographic hash function migration, Ludovic Courtès, 2020/05/19