grafts: Preserve empty directories when grafting.
authorLudovic Courtès <ludo@gnu.org>
Fri, 20 May 2016 20:11:56 +0000 (22:11 +0200)
committerLudovic Courtès <ludo@gnu.org>
Fri, 20 May 2016 23:35:14 +0000 (01:35 +0200)
* guix/build/graft.scm (rewrite-directory)[rewrite-leaf]: Add case for
'directory.
Pass #:directories? #t to 'find-files'.

guix/build/graft.scm
tests/grafts.scm

index b216e6c..e9fce03 100644 (file)
@@ -115,6 +115,8 @@ file name pairs."
                    (replace-store-references input output mapping
                                              store)
                    (chmod output (stat:perms stat))))))))
+        ((directory)
+         (mkdir-p dest))
         (else
          (error "unsupported file type" stat)))))
 
@@ -124,6 +126,7 @@ file name pairs."
   (umask #o022)
 
   (n-par-for-each (parallel-job-count)
-                  rewrite-leaf (find-files directory)))
+                  rewrite-leaf (find-files directory (const #t)
+                                           #:directories? #t)))
 
 ;;; graft.scm ends here
index afed704..f8c9ece 100644 (file)
                        (list one two dep)
                        (references %store dep)))))))
 
+(test-assert "graft-derivation, preserve empty directories"
+  (run-with-store %store
+    (mlet* %store-monad ((fake    (text-file "bash" "Fake bash."))
+                         (graft -> (graft
+                                     (origin %bash)
+                                     (replacement fake)))
+                         (drv     (gexp->derivation
+                                   "to-graft"
+                                   #~(begin
+                                       (use-modules (guix build utils))
+                                       (mkdir-p (string-append #$output
+                                                               "/a/b/c/d"))
+                                       (symlink #$%bash
+                                                (string-append #$output
+                                                               "/bash")))
+                                   #:modules '((guix build utils))))
+                         (grafted ((store-lift graft-derivation) drv
+                                   (list graft)))
+                         (_       (built-derivations (list grafted)))
+                         (out ->  (derivation->output-path grafted)))
+      (return (and (string=? (readlink (string-append out "/bash"))
+                             fake)
+                   (file-is-directory? (string-append out "/a/b/c/d")))))))
+
 (test-assert "graft-derivation, no dependencies on grafted output"
   (run-with-store %store
     (mlet* %store-monad ((fake    (text-file "bash" "Fake bash."))