[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
06/06: grafts: Rename files whose name matches a graft.
From: |
Ludovic Courtès |
Subject: |
06/06: grafts: Rename files whose name matches a graft. |
Date: |
Fri, 20 May 2016 23:35:46 +0000 (UTC) |
civodul pushed a commit to branch master
in repository guix.
commit ece6864bd04fc2f9ff86fd4ac9cb0712dd71c094
Author: Ludovic Courtès <address@hidden>
Date: Fri May 20 22:14:46 2016 +0200
grafts: Rename files whose name matches a graft.
Fixes <http://bugs.gnu.org/23132>.
Reported by Mark H Weaver <address@hidden>.
* guix/build/graft.scm (rename-matching-files): New procedure.
(rewrite-directory): Use it.
* tests/grafts.scm ("graft-derivation, renaming"): New test.
---
guix/build/graft.scm | 25 ++++++++++++++++++++++++-
tests/grafts.scm | 17 +++++++++++++++++
2 files changed, 41 insertions(+), 1 deletion(-)
diff --git a/guix/build/graft.scm b/guix/build/graft.scm
index e9fce03..b61982d 100644
--- a/guix/build/graft.scm
+++ b/guix/build/graft.scm
@@ -83,6 +83,28 @@ writing the result to OUTPUT."
(put-u8 output (char->integer char))
result)))))
+(define (rename-matching-files directory mapping)
+ "Apply MAPPING to the names of all the files in DIRECTORY, where MAPPING is
+a list of store file name pairs."
+ (let* ((mapping (map (match-lambda
+ ((source . target)
+ (cons (basename source) (basename target))))
+ mapping))
+ (matches (find-files directory
+ (lambda (file stat)
+ (assoc-ref mapping (basename file)))
+ #:directories? #t)))
+
+ ;; XXX: This is not quite correct: if MAPPING contains "foo", and
+ ;; DIRECTORY contains "bar/foo/foo", we first rename "bar/foo" and then
+ ;; "bar/foo/foo" no longer exists so we fail. Oh well, surely that's good
+ ;; enough!
+ (for-each (lambda (file)
+ (let ((target (assoc-ref mapping (basename file))))
+ (rename-file file
+ (string-append (dirname file) "/" target))))
+ matches)))
+
(define* (rewrite-directory directory output mapping
#:optional (store (%store-directory)))
"Copy DIRECTORY to OUTPUT, replacing strings according to MAPPING, a list of
@@ -127,6 +149,7 @@ file name pairs."
(n-par-for-each (parallel-job-count)
rewrite-leaf (find-files directory (const #t)
- #:directories? #t)))
+ #:directories? #t))
+ (rename-matching-files output mapping))
;;; graft.scm ends here
diff --git a/tests/grafts.scm b/tests/grafts.scm
index f8c9ece..8cd0485 100644
--- a/tests/grafts.scm
+++ b/tests/grafts.scm
@@ -182,4 +182,21 @@
(and (string=? (readlink one) repl)
(string=? (readlink two) one))))))
+(test-assert "graft-derivation, renaming" ;<http://bugs.gnu.org/23132>
+ (let* ((build `(begin
+ (use-modules (guix build utils))
+ (mkdir-p (string-append (assoc-ref %outputs "out") "/"
+ (assoc-ref %build-inputs "in")))))
+ (orig (build-expression->derivation %store "thing-to-graft" build
+ #:modules '((guix build utils))
+ #:inputs `(("in" ,%bash))))
+ (repl (add-text-to-store %store "bash" "fake bash"))
+ (grafted (graft-derivation %store orig
+ (list (graft
+ (origin %bash)
+ (replacement repl))))))
+ (and (build-derivations %store (list grafted))
+ (let ((out (derivation->output-path grafted)))
+ (file-is-directory? (string-append out "/" repl))))))
+
(test-end)
- branch master updated (3c9a718 -> ece6864), Ludovic Courtès, 2016/05/20
- 01/06: graph: Use absolute file name canonicalization., Ludovic Courtès, 2016/05/20
- 04/06: substitute: Gracefully handle invalid store file names., Ludovic Courtès, 2016/05/20
- 03/06: graph: Allow store file names for 'derivation' and 'references' graphs., Ludovic Courtès, 2016/05/20
- 05/06: grafts: Preserve empty directories when grafting., Ludovic Courtès, 2016/05/20
- 06/06: grafts: Rename files whose name matches a graft.,
Ludovic Courtès <=
- 02/06: derivations: 'derivation' sorts items in the resulting object., Ludovic Courtès, 2016/05/20