]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
Merge pull request #122 from tahoe-lafs/182-osx-packaging-6
authorDaira Hopwood <daira@jacaranda.org>
Tue, 21 Oct 2014 15:11:05 +0000 (16:11 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Tue, 21 Oct 2014 15:11:05 +0000 (16:11 +0100)
182 osx packaging 6

Makefile
misc/build_helpers/osx/Distribution.xml [new file with mode: 0644]
misc/build_helpers/osx/scripts/postinstall [new file with mode: 0755]
misc/build_helpers/test-osx-pkg.py [new file with mode: 0644]

index 3905a8de062dbb83a90926668b1f47f6d659262f..4ad77d615a34f4671b200a1bcd0bb8590140610e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -31,6 +31,34 @@ build:
        $(PYTHON) setup.py build
        touch .built
 
+# Build OS X pkg packages.
+# The editing of .egg-link and .pth files ensures that we reference the source at the correct path.
+.PHONY: build-osx-pkg
+build-osx-pkg:
+       $(PYTHON) setup.py build
+       find support -name allmydata-tahoe.egg-link -execdir sh -c "echo >> {}; echo /Applications/tahoe.app/src >> {}" \;
+       find support -name easy-install.pth -execdir sed -i.bak 's|^.*/src$$|../../../../src|' '{}' \;
+       touch .built
+
+# create component pkg
+       pkgbuild --root $(shell pwd) \
+       --identifier com.leastauthority.tahoe \
+       --version $(shell sh -c "cat src/allmydata/_version.py | grep verstr | head -n 1 | cut -d' ' -f 3") \
+       --ownership recommended \
+       --install-location /Applications/tahoe.app \
+       --scripts $(shell pwd)/misc/build_helpers/osx/scripts \
+       tahoe-lafs.pkg
+
+# create product archive
+       productbuild --distribution $(shell pwd)/misc/build_helpers/osx/Distribution.xml \
+       --package-path . \
+       tahoe-lafs-osx.pkg
+
+# remove intermediate pkg
+       rm -f tahoe-lafs.pkg
+
+# test the result
+       $(PYTHON) misc/build_helpers/test-osx-pkg.py
 
 # TESTING
 
@@ -236,6 +264,7 @@ clean:
        rm -rf misc/dependencies/build misc/dependencies/temp
        rm -rf misc/dependencies/tahoe_deps.egg-info
        rm -f bin/tahoe bin/tahoe.pyscript
+       rm -f *.pkg
 
 .PHONY: distclean
 distclean: clean
diff --git a/misc/build_helpers/osx/Distribution.xml b/misc/build_helpers/osx/Distribution.xml
new file mode 100644 (file)
index 0000000..7662a98
--- /dev/null
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<installer-script minSpecVersion="1">
+
+<!-- The original version was generated by PackageMaker -->
+<!-- Reference Documentation for installer scripts: https://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Distribution_XML_Ref.html -->
+
+<title>Tahoe-LAFS</title>
+
+<options customize="never" allow-external-scripts="no" rootVolumeOnly="yes" />
+
+<installation-check script="(function(){
+  if(system.sysctl('hw.machine') != 'x86_64'){
+    my.result.type = 'Fatal';
+    my.result.message = 'x86_64 system required';
+    return false;
+  }
+  return true;
+})()" />
+
+<volume-check>
+  <allowed-os-versions>
+    <os-version min="10.7" />
+  </allowed-os-versions>
+</volume-check>
+
+<choices-outline>
+  <line choice="choice0"/>
+</choices-outline>
+<choice id="choice0" visible="false">
+  <pkg-ref id="com.leastauthority.tahoe"/>
+</choice>
+<pkg-ref id="com.leastauthority.tahoe" version="1.10.0" auth="Root">tahoe-lafs.pkg</pkg-ref>
+
+<license language="en" mime-type="text/plain"><![CDATA[
+Copyright 2006-2014 The Tahoe-LAFS Software Foundation
+
+You may use this package under the GNU General Public License, version 2 or, at
+your option, any later version.  You may use this package under the Transitive
+Grace Period Public Licence, version 1.0, or at your option, any later
+version. (You may choose to use this package under the terms of either licence,
+at your option.)  See the file 'COPYING.GPL' for the terms of the GNU General
+Public License, version 2.  See the file 'COPYING.TGPPL.rst' for the terms of
+the Transitive Grace Period Public Licence, version 1.0.
+]]></license>
+</installer-script>
diff --git a/misc/build_helpers/osx/scripts/postinstall b/misc/build_helpers/osx/scripts/postinstall
new file mode 100755 (executable)
index 0000000..aefc4fd
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/bash
+
+echo "/Applications/tahoe.app/bin" >> /etc/paths.d/tahoe
diff --git a/misc/build_helpers/test-osx-pkg.py b/misc/build_helpers/test-osx-pkg.py
new file mode 100644 (file)
index 0000000..ddd945e
--- /dev/null
@@ -0,0 +1,91 @@
+# This script treats the OS X pkg as an xar archive and uncompresses it to
+# the filesystem. The xar file contains a file called Payload, which is a
+# gziped cpio archive of the filesystem. It then cd's into the file system
+# and executes '$appname --version-and-path' and checks whether the output
+# of that command is right.
+
+# If all of the paths listed therein are loaded from within the current PWD
+# then it exits with code 0.
+
+# If anything goes wrong then it exits with non-zero (failure).  This is to
+# check that the Mac OS '.pkg' package that gets built is correctly loading
+# all of its packages from inside the image.
+
+# Here is an example output from --version-and-path:
+
+# allmydata-tahoe: 1.10.0.post185.dev0 [2249-deps-and-osx-packaging-1: 76ac53846042d9a4095995be92af66cdc09d5ad0-dirty] (/Applications/tahoe.app/src)
+# foolscap: 0.7.0 (/Applications/tahoe.app/support/lib/python2.7/site-packages/foolscap-0.7.0-py2.7.egg)
+# pycryptopp: 0.6.0.1206569328141510525648634803928199668821045408958 (/Applications/tahoe.app/support/lib/python2.7/site-packages/pycryptopp-0.6.0.1206569328141510525648634803928199668821045408958-py2.7-macosx-10.9-intel.egg)
+# zfec: 1.4.24 (/Applications/tahoe.app/support/lib/python2.7/site-packages/zfec-1.4.24-py2.7-macosx-10.9-intel.egg)
+# Twisted: 13.0.0 (/Applications/tahoe.app/support/lib/python2.7/site-packages/Twisted-13.0.0-py2.7-macosx-10.9-intel.egg)
+# Nevow: 0.11.1 (/Applications/tahoe.app/support/lib/python2.7/site-packages/Nevow-0.11.1-py2.7.egg)
+# zope.interface: unknown (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/zope)
+# python: 2.7.5 (/usr/bin/python)
+# platform: Darwin-13.4.0-x86_64-i386-64bit (None)
+# pyOpenSSL: 0.13 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python)
+# simplejson: 3.6.4 (/Applications/tahoe.app/support/lib/python2.7/site-packages/simplejson-3.6.4-py2.7-macosx-10.9-intel.egg)
+# pycrypto: 2.6.1 (/Applications/tahoe.app/support/lib/python2.7/site-packages/pycrypto-2.6.1-py2.7-macosx-10.9-intel.egg)
+# pyasn1: 0.1.7 (/Applications/tahoe.app/support/lib/python2.7/site-packages/pyasn1-0.1.7-py2.7.egg)
+# mock: 1.0.1 (/Applications/tahoe.app/support/lib/python2.7/site-packages)
+# setuptools: 0.6c16dev5 (/Applications/tahoe.app/support/lib/python2.7/site-packages/setuptools-0.6c16dev5.egg)
+# service-identity: 14.0.0 (/Applications/tahoe.app/support/lib/python2.7/site-packages/service_identity-14.0.0-py2.7.egg)
+# characteristic: 14.1.0 (/Applications/tahoe.app/support/lib/python2.7/site-packages)
+# pyasn1-modules: 0.0.5 (/Applications/tahoe.app/support/lib/python2.7/site-packages/pyasn1_modules-0.0.5-py2.7.egg)
+
+import os, re, subprocess, time, tempfile, shutil
+
+def test_osx_pkg(pkgfile):
+    """ Return on success, raise exception on failure. """
+
+    tmpdir = tempfile.mkdtemp(dir='/tmp')
+    # xar -C /tmp/tmpdir -xf PKGNAME
+    cmd = ['xar', '-C', tmpdir, '-xf', pkgfile]
+    extractit = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    rc = extractit.wait()
+    if rc != 0:
+        raise Exception("FAIL: xar returned non-zero exit code: %r from command: %r" % (rc, cmd,))
+
+    stderrtxt = extractit.stderr.read()
+    if stderrtxt:
+        raise Exception("FAIL: xar said something on stderr: %r" % (stderrtxt,))
+
+    # cd /tmp/tmpXXX/tahoe-lafs.pkg
+    os.chdir(tmpdir + '/tahoe-lafs.pkg')
+
+    # cat Payload | gunzip -dc | cpio -i
+    cat_process = subprocess.Popen(['cat', 'Payload'], stdout=subprocess.PIPE)
+    gunzip_process = subprocess.Popen(['gunzip', '-dc'], 
+                                      stdin=cat_process.stdout,
+                                      stdout=subprocess.PIPE)
+    cpio_process = subprocess.Popen(['cpio', '-i'],
+                                    stdin=gunzip_process.stdout,
+                                    stdout=subprocess.PIPE)
+    cpio_process.communicate()
+
+    try:
+        basedir = os.getcwd()
+        cmd = ['bin/tahoe', '--version-and-path']
+        callit = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+        rc = callit.wait()
+        if rc != 0:
+            raise Exception("FAIL: '%s' returned non-zero exit code: %r" % (" ".join(cmd), rc))
+        stdouttxt = callit.stdout.read()
+
+        PKG_VER_PATH_RE=re.compile("^(\S+): ([^\(]+)\((.+?)\)$", re.UNICODE)
+
+        for mo in PKG_VER_PATH_RE.finditer(stdouttxt):
+            if not mo.group(3).startswith(basedir):
+                # the following packages are provided by the OS X default installation itself
+                if not mo.group(1) in ['zope.interface', 'python', 'platform', 'pyOpenSSL']:
+                    raise Exception("FAIL: found package not loaded from basedir (%s); package was: %s" % (basedir, mo.groups(),))
+        # success!
+    finally:
+        shutil.rmtree(tmpdir)
+
+
+if __name__ == '__main__':
+    print "Testing..."
+    test_osx_pkg('tahoe-lafs-osx.pkg')
+    print "Looks OK!"
+