summary refs log tree commit diff
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2015-09-06 12:26:55 -0400
committerMark H Weaver <mhw@netris.org>2015-09-06 17:25:51 -0400
commit140b4bc6cd4cda79ab48c3fecc8c98afeb02cdf6 (patch)
tree5bc8c9281e611a3087df51a1a124f6ca4953bc04
parentf4ae827e26b1bbbd47ac05bb2a4278d5c61c828e (diff)
downloadguix-140b4bc6cd4cda79ab48c3fecc8c98afeb02cdf6.tar.gz
packages: Build tarballs in sorted order even if tar doesn't support it.
This is a followup to commit 92226a470ddc980e54863632e5b179bf40444bd7.

* guix/packages.scm (patch-and-repack)[build]: Determine if tar supports the
  "--sort=name" option using a run-time test.  If not supported, generate the
  sorted file list with 'find-files' and pass it to tar using "--files-from".
-rw-r--r--guix/packages.scm33
1 files changed, 26 insertions, 7 deletions
diff --git a/guix/packages.scm b/guix/packages.scm
index 68ec236451..da4940981d 100644
--- a/guix/packages.scm
+++ b/guix/packages.scm
@@ -425,6 +425,13 @@ IMPORTED-MODULES specify modules to use/import for use by SNIPPET."
                        (srfi srfi-1)
                        (guix build utils))
 
+          ;; The --sort option was added to GNU tar in version 1.28, released
+          ;; 2014-07-28.  During bootstrap we must cope with older versions.
+          (define tar-supports-sort?
+            (zero? (system* (string-append #+tar "/bin/tar")
+                            "cf" "/dev/null" "--files-from=/dev/null"
+                            "--sort=name")))
+
           (define (apply-patch patch)
             (format (current-error-port) "applying '~a'...~%" patch)
 
@@ -484,13 +491,25 @@ IMPORTED-MODULES specify modules to use/import for use by SNIPPET."
                              #~())
 
                       (begin (chdir "..") #t)
-                      (zero? (system* (string-append #+tar "/bin/tar")
-                                      "cvfa" #$output directory
-                                      ;; avoid non-determinism in the archive
-                                      "--sort=name"
-                                      "--mtime=@0"
-                                      "--owner=root:0"
-                                      "--group=root:0")))))))
+
+                      (unless tar-supports-sort?
+                        (call-with-output-file ".file_list"
+                          (lambda (port)
+                            (for-each (lambda (name) (format port "~a~%" name))
+                                      (find-files directory
+                                                  #:directories? #t
+                                                  #:fail-on-error? #t)))))
+                      (zero? (apply system* (string-append #+tar "/bin/tar")
+                                    "cvfa" #$output
+                                    ;; avoid non-determinism in the archive
+                                    "--mtime=@0"
+                                    "--owner=root:0"
+                                    "--group=root:0"
+                                    (if tar-supports-sort?
+                                        `("--sort=name"
+                                          ,directory)
+                                        '("--no-recursion"
+                                          "--files-from=.file_list")))))))))
 
     (let ((name    (tarxz-name original-file-name))
           (modules (delete-duplicates (cons '(guix build utils) modules))))