]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - misc/build_helpers/test-osx-pkg.py
c39850195cc80cc11a94b462fb9efc7bf8fa905b
[tahoe-lafs/tahoe-lafs.git] / misc / build_helpers / test-osx-pkg.py
1 # This script treats the OS X pkg as an xar archive and uncompresses it to
2 # the filesystem. The xar file contains a file called Payload, which is a
3 # gziped cpio archive of the filesystem. It then cd's into the file system
4 # and executes '$appname --version-and-path' and checks whether the output
5 # of that command is right.
6
7 # If all of the paths listed therein are loaded from within the current PWD
8 # then it exits with code 0.
9
10 # If anything goes wrong then it exits with non-zero (failure).  This is to
11 # check that the Mac OS '.pkg' package that gets built is correctly loading
12 # all of its packages from inside the image.
13
14 # Here is an example output from --version-and-path:
15
16 # allmydata-tahoe: 1.10.0.post185.dev0 [2249-deps-and-osx-packaging-1: 76ac53846042d9a4095995be92af66cdc09d5ad0-dirty] (/Applications/tahoe.app/src)
17 # foolscap: 0.7.0 (/Applications/tahoe.app/support/lib/python2.7/site-packages/foolscap-0.7.0-py2.7.egg)
18 # 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)
19 # zfec: 1.4.24 (/Applications/tahoe.app/support/lib/python2.7/site-packages/zfec-1.4.24-py2.7-macosx-10.9-intel.egg)
20 # Twisted: 13.0.0 (/Applications/tahoe.app/support/lib/python2.7/site-packages/Twisted-13.0.0-py2.7-macosx-10.9-intel.egg)
21 # Nevow: 0.11.1 (/Applications/tahoe.app/support/lib/python2.7/site-packages/Nevow-0.11.1-py2.7.egg)
22 # zope.interface: unknown (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/zope)
23 # python: 2.7.5 (/usr/bin/python)
24 # platform: Darwin-13.4.0-x86_64-i386-64bit (None)
25 # pyOpenSSL: 0.13 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python)
26 # simplejson: 3.6.4 (/Applications/tahoe.app/support/lib/python2.7/site-packages/simplejson-3.6.4-py2.7-macosx-10.9-intel.egg)
27 # pycrypto: 2.6.1 (/Applications/tahoe.app/support/lib/python2.7/site-packages/pycrypto-2.6.1-py2.7-macosx-10.9-intel.egg)
28 # pyasn1: 0.1.7 (/Applications/tahoe.app/support/lib/python2.7/site-packages/pyasn1-0.1.7-py2.7.egg)
29 # mock: 1.0.1 (/Applications/tahoe.app/support/lib/python2.7/site-packages)
30 # setuptools: 0.6c16dev5 (/Applications/tahoe.app/support/lib/python2.7/site-packages/setuptools-0.6c16dev5.egg)
31 # service-identity: 14.0.0 (/Applications/tahoe.app/support/lib/python2.7/site-packages/service_identity-14.0.0-py2.7.egg)
32 # characteristic: 14.1.0 (/Applications/tahoe.app/support/lib/python2.7/site-packages)
33 # pyasn1-modules: 0.0.5 (/Applications/tahoe.app/support/lib/python2.7/site-packages/pyasn1_modules-0.0.5-py2.7.egg)
34
35 import os, re, shutil, subprocess, sys, tempfile
36
37 def test_osx_pkg(pkgfile):
38     """ Return on success, raise exception on failure. """
39
40     tmpdir = tempfile.mkdtemp(dir='/tmp')
41     # xar -C /tmp/tmpdir -xf PKGNAME
42     cmd = ['xar', '-C', tmpdir, '-xf', pkgfile]
43     extractit = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
44     rc = extractit.wait()
45     if rc != 0:
46         raise Exception("FAIL: xar returned non-zero exit code: %r from command: %r" % (rc, cmd,))
47
48     stderrtxt = extractit.stderr.read()
49     if stderrtxt:
50         raise Exception("FAIL: xar said something on stderr: %r" % (stderrtxt,))
51
52     # cd /tmp/tmpXXX/tahoe-lafs.pkg
53     os.chdir(tmpdir + '/tahoe-lafs.pkg')
54
55     # cat Payload | gunzip -dc | cpio -i
56     cat_process = subprocess.Popen(['cat', 'Payload'], stdout=subprocess.PIPE)
57     gunzip_process = subprocess.Popen(['gunzip', '-dc'],
58                                       stdin=cat_process.stdout,
59                                       stdout=subprocess.PIPE)
60     cpio_process = subprocess.Popen(['cpio', '-i'],
61                                     stdin=gunzip_process.stdout,
62                                     stdout=subprocess.PIPE)
63     cpio_process.communicate()
64
65     try:
66         basedir = os.getcwd()
67         cmd = ['bin/tahoe', '--version-and-path']
68         callit = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
69
70         rc = callit.wait()
71         if rc != 0:
72             raise Exception("FAIL: '%s' returned non-zero exit code: %r" % (" ".join(cmd), rc))
73         stdouttxt = callit.stdout.read()
74
75         PKG_VER_PATH_RE=re.compile("^(\S+): ([^\(]+)\((.+?)\)$", re.UNICODE)
76
77         for mo in PKG_VER_PATH_RE.finditer(stdouttxt):
78             if not mo.group(3).startswith(basedir):
79                 # the following packages are provided by the OS X default installation itself
80                 if not mo.group(1) in ['zope.interface', 'python', 'platform', 'pyOpenSSL']:
81                     raise Exception("FAIL: found package not loaded from basedir (%s); package was: %s" % (basedir, mo.groups(),))
82         # success!
83     finally:
84         shutil.rmtree(tmpdir)
85
86
87 if __name__ == '__main__':
88     pkgs = [fn for fn in os.listdir(".") if fn.endswith("-osx.pkg")]
89     if len(pkgs) != 1:
90         print "ERR: unable to find a single .pkg file:", pkgs
91         sys.exit(1)
92     print "Testing %s ..." % pkgs[0]
93     test_osx_pkg(pkgs[0])
94     print "Looks OK!"
95