From 20d83444dda3ccbb4e8bbff1d4cbfe429eb015f6 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Fri, 26 Oct 2012 09:07:37 +0200 Subject: utils: Remove special `substitute*' syntax for lists of files. * guix/build/utils.scm (substitute*): Remove special syntax for list-of-files; instead, check whether FILE is `list?' at run time. * distro/packages/base.scm (gcc-4.7, %binutils-static): Adjust accordingly. --- guix/build/utils.scm | 68 +++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 30 deletions(-) (limited to 'guix') diff --git a/guix/build/utils.scm b/guix/build/utils.scm index 26bdfff1db..8ae190f656 100644 --- a/guix/build/utils.scm +++ b/guix/build/utils.scm @@ -312,10 +312,10 @@ (define-syntax substitute* sub-expression. For example: (substitute* file - ((\"hello\") - \"good morning\\n\") - ((\"foo([a-z]+)bar(.*)$\" all letters end) - (string-append \"baz\" letter end))) + ((\"hello\") + \"good morning\\n\") + ((\"foo([a-z]+)bar(.*)$\" all letters end) + (string-append \"baz\" letter end))) Here, anytime a line of FILE contains \"hello\", it is replaced by \"good morning\". Anytime a line of FILE matches the second regexp, ALL is bound to @@ -323,33 +323,41 @@ (define-syntax substitute* bound to the last one. When one of the MATCH-VAR is `_', no variable is bound to the corresponding -match substring." - ((substitute* (file ...) clause ...) - (begin - (substitute* file clause ...) - ...)) +match substring. + +Alternatively, FILE may be a list of file names, in which case they are +all subject to the substitutions." ((substitute* file ((regexp match-var ...) body ...) ...) - (substitute file - (list (cons regexp - (lambda (l m+) - ;; Iterate over matches M+ and return the - ;; modified line based on L. - (let loop ((m* m+) ; matches - (o 0) ; offset in L - (r '())) ; result - (match m* - (() - (let ((r (cons (substring l o) r))) - (string-concatenate-reverse r))) - ((m . rest) - (let-matches 0 m (match-var ...) - (loop rest - (match:end m) - (cons* - (begin body ...) - (substring l o (match:start m)) - r)))))))) - ...))))) + (let () + (define (substitute-one-file file-name) + (substitute + file-name + (list (cons regexp + (lambda (l m+) + ;; Iterate over matches M+ and return the + ;; modified line based on L. + (let loop ((m* m+) ; matches + (o 0) ; offset in L + (r '())) ; result + (match m* + (() + (let ((r (cons (substring l o) r))) + (string-concatenate-reverse r))) + ((m . rest) + (let-matches 0 m (match-var ...) + (loop rest + (match:end m) + (cons* + (begin body ...) + (substring l o (match:start m)) + r)))))))) + ...))) + + (match file + ((files (... ...)) + (for-each substitute-one-file files)) + ((? string? f) + (substitute-one-file f))))))) ;;; -- cgit v1.2.3