From c0fa86d316c91044630b85c9e789f9a455fd29f4 Mon Sep 17 00:00:00 2001 From: zimoun Date: Fri, 27 Aug 2021 18:15:16 +0200 Subject: [PATCH] transformations: Error when incorrect specifications. * guix/transformations.scm (transform-package-with-debug-info, transform-package-latest, transform-package-tests)[rewrite]: Raise when incorrect specification. (options->transformation)[package-name?]: New procedure. [applicable]: Use it. --- guix/transformations.scm | 41 ++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/guix/transformations.scm b/guix/transformations.scm index 5122baa403..2546017d0d 100644 --- a/guix/transformations.scm +++ b/guix/transformations.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2016, 2017, 2018, 2019, 2020, 2021 Ludovic Courtès +;;; Copyright © 2021 Simon Tournier ;;; ;;; This file is part of GNU Guix. ;;; @@ -432,9 +433,15 @@ to the same package but with #:strip-binaries? #f in its 'arguments' field." (replacement (loop next)))))))) (define rewrite - (package-input-rewriting/spec (map (lambda (spec) - (cons spec package-with-debug-info)) - specs))) + (package-input-rewriting/spec + (map (lambda (spec) + (match (string-tokenize spec %not-equal) + ((spec) + (cons spec package-with-debug-info)) + (_ + (raise + (formatted-message (G_ "~a: invalid specification") spec))))) + specs))) (lambda (obj) (if (package? obj) @@ -451,9 +458,15 @@ to the same package but with #:strip-binaries? #f in its 'arguments' field." ((#:tests? _ #f) #f))))) (define rewrite - (package-input-rewriting/spec (map (lambda (spec) - (cons spec package-without-tests)) - specs))) + (package-input-rewriting/spec + (map (lambda (spec) + (match (string-tokenize spec %not-equal) + ((spec) + (cons spec package-without-tests)) + (_ + (raise + (formatted-message (G_ "~a: invalid specification") spec))))) + specs))) (lambda (obj) (if (package? obj) @@ -569,7 +582,12 @@ are replaced by their latest upstream version." (define rewrite (package-input-rewriting/spec (map (lambda (spec) - (cons spec package-with-latest-upstream)) + (match (string-tokenize spec %not-equal) + ((spec) + (cons spec package-with-latest-upstream)) + (_ + (raise + (formatted-message (G_ "~a: invalid specification") spec))))) specs))) (lambda (obj) @@ -695,6 +713,12 @@ the resulting objects. OPTS must be a list of symbol/string pairs such as: Each symbol names a transformation and the corresponding string is an argument to that transformation." + (define (package-name? value) + ;; Return an error if value does not correspond to a package. + (match (string-tokenize value %not-equal) + ((name _ ...) + (specification->package name)))) + (define applicable ;; List of applicable transformations as symbol/procedure pairs in the ;; order in which they appear on the command line. @@ -707,7 +731,8 @@ to that transformation." ;; XXX: We used to pass TRANSFORM a list of several ;; arguments, but we now pass only one, assuming that ;; transform composes well. - (list key value (transform (list value))))))) + (and (package-name? value) + (list key value (transform (list value)))))))) (reverse opts))) (define (package-with-transformation-properties p) base-commit: 7125b0d8a1be58e3f5b66a00fc5912aed9b330e4 -- 2.32.0