From cf744500503a3f8020363e9d52ddf7c05d3ec268 Mon Sep 17 00:00:00 2001
From: Francois-Rene Rideau <tunes@google.com>
Date: Fri, 25 Jul 2014 14:25:22 -0400
Subject: [PATCH] Better tarball making: tell MacOS's BSD tar to not include
 resource files and don't create a subdirectory or symlink with .asd files
 even temporarily, for it can create conflicts if interrupted or in a race
 condition.

---
 tools/release.lisp | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/tools/release.lisp b/tools/release.lisp
index 49d26a62..bc303544 100644
--- a/tools/release.lisp
+++ b/tools/release.lisp
@@ -59,7 +59,8 @@
              destination))
     (ensure-directories-exist destination)
     (run `(cp "-pHux" --parents ,@files ,destination) :directory base :show t)
-    (run `(tar "zcfC" ,tarball ,(pn "build/") (,name /)) :show t)
+    (run `(env "COPYFILE_DISABLE=1" ;; tell MacOS X's BSD tar to behave.
+           tar "zcfC" ,tarball ,(pn "build/") (,name /)) :show t)
     (delete-directory-tree destination :validate (complement #'wild-pathname-p))
     (values)))
 
@@ -86,8 +87,24 @@
 
 (defun make-git-tarball ()
   (build-asdf)
-  (make-tarball-under-build (asdf-git-name) (pn)
-                            (cons "build/asdf.lisp" (run/lines '(git ls-files)))))
+  (let* ((name (asdf-git-name))
+         (tarball (strcat name ".tar")))
+    (with-asdf-dir ()
+      (run `(git archive -o (build/ ,tarball)
+                 :prefix (,name /) ,*version*)
+           :show t))
+    (with-asdf-dir ("build/")
+      (ensure-directories-exist (pn "build" name "build/"))
+      (run `(cp -a asdf.lisp (,name /build/)))
+      ;; TODO: find which tar it is and tell --uid 0 --gid 0 to BSD tar
+      ;; and --owner root --group root to GNU tar,
+      ;; falling back to nothing. Sigh.
+      (run `(env "COPYFILE_DISABLE=1"
+                 tar "-rf" ,tarball (,name /build/asdf.lisp)) :show t)
+      (run `(rm -f (,name /build/asdf.lisp)))
+      (run `(rmdir (,name /build/) (,name /)))
+      (run `(gzip -f9 ,tarball) :show t)))
+  (values))
 
 (defun asdf-lisp-name ()
   (format nil "asdf-~A.lisp" *version*))
-- 
GitLab