Patchwork [2,of,5,osx] osx: override default exclude filter for pkgbuild

login
register
mail settings
Submitter Augie Fackler
Date May 27, 2017, 12:27 a.m.
Message ID <6bf80f254aac0c1238e6.1495844849@augie-macbookpro2.roam.corp.google.com>
Download mbox | patch
Permalink /patch/20950/
State Accepted
Headers show

Comments

Augie Fackler - May 27, 2017, 12:27 a.m.
# HG changeset patch
# User Augie Fackler <augie@google.com>
# Date 1495843385 14400
#      Fri May 26 20:03:05 2017 -0400
# Node ID 6bf80f254aac0c1238e6cd8c54d5a9f23dfc73fa
# Parent  6663e603bc92abbe4ff60e4b1c0c283ec18f402a
osx: override default exclude filter for pkgbuild

To quote `man 1 pkgbuild`:

     --filter filter-expression
                 By default, --root will include the entire contents of the
                 given root-path in the package payload, except for any .svn
                 or CVS directories, and any .DS_Store files. You can override
                 these default filters by specifying one or more --filter
                 options. Each filter-expression is an re_format(7)
                 ``extended'' expression: any path in the root which matches
                 any of the given expressions will be excluded from the pack-
                 age payload. (Note that specifying even one --filter inhibits
                 the default filters, so you must respecify the default fil-
                 ters if you still want them to be used.)

It turns out the default filter these days *also* includes .git and
.hg. Notice how that filter expression is a regular expression?  That
(presumably unintentionally) prevents a file named "chg" or "_hg" from
getting included in the distribution. Many many thanks to spectral@
for trying to include a _hg file which led us to figure this bug out.

Bug filed with Apple for this as rdar://problem/32437369, mentioning
both the gap in documentation and the wrong defaults.

Patch

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -163,6 +163,9 @@  osx:
 	  --root=build/mercurial/ --prefix=/usr/local/ \
 	  --install-lib=/Library/Python/2.7/site-packages/
 	make -C doc all install DESTDIR="$(PWD)/build/mercurial/"
+        # Place a bogon .DS_Store file in the target dir so we can be
+        # sure it doesn't get included in the final package.
+	touch build/mercurial/.DS_Store
         # install zsh completions - this location appears to be
         # searched by default as of macOS Sierra.
 	install -d build/mercurial/usr/local/share/zsh/site-functions/
@@ -176,7 +179,7 @@  osx:
 	mkdir -p $${OUTPUTDIR:-dist}
 	HGVER=$$((cat build/mercurial/Library/Python/2.7/site-packages/mercurial/__version__.py; echo 'print(version)') | python) && \
 	OSXVER=$$(sw_vers -productVersion | cut -d. -f1,2) && \
-	pkgbuild --root build/mercurial/ \
+	pkgbuild --filter \\.DS_Store --root build/mercurial/ \
 	  --identifier org.mercurial-scm.mercurial \
 	  --version "$${HGVER}" \
 	  build/mercurial.pkg && \
diff --git a/tests/test-mac-packages.t b/tests/test-mac-packages.t
--- a/tests/test-mac-packages.t
+++ b/tests/test-mac-packages.t
@@ -18,6 +18,11 @@ 
 Gather list of all installed files:
   $ lsbom mercurial.pkg/Bom > boms.txt
 
+We've had problems with the filter logic in the past. Make sure no
+.DS_Store files ended up in the final package:
+  $ grep DS_S boms.txt
+  [1]
+
 Spot-check some randomly selected files:
   $ grep bdiff boms.txt | cut -d '	' -f 1,2,3
   ./Library/Python/2.7/site-packages/mercurial/cext/bdiff.so	100755	0/0