source: trunk/misc/build_helpers/test-osx-pkg.py

Last change on this file was b856238, checked in by Alexandre Detiste <alexandre.detiste@…>, at 2024-02-15T15:53:34Z

remove old Python2 future statements

  • Property mode set to 100644
File size: 4.7 KB
Line 
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# zfec: 1.4.24 (/Applications/tahoe.app/support/lib/python2.7/site-packages/zfec-1.4.24-py2.7-macosx-10.9-intel.egg)
19# Twisted: 13.0.0 (/Applications/tahoe.app/support/lib/python2.7/site-packages/Twisted-13.0.0-py2.7-macosx-10.9-intel.egg)
20# Nevow: 0.11.1 (/Applications/tahoe.app/support/lib/python2.7/site-packages/Nevow-0.11.1-py2.7.egg)
21# zope.interface: unknown (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/zope)
22# python: 2.7.5 (/usr/bin/python)
23# platform: Darwin-13.4.0-x86_64-i386-64bit (None)
24# pyOpenSSL: 0.13 (/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python)
25# pyasn1: 0.1.7 (/Applications/tahoe.app/support/lib/python2.7/site-packages/pyasn1-0.1.7-py2.7.egg)
26# mock: 1.0.1 (/Applications/tahoe.app/support/lib/python2.7/site-packages)
27# setuptools: 0.6c16dev6 (/Applications/tahoe.app/support/lib/python2.7/site-packages/setuptools-0.6c16dev6.egg)
28# service-identity: 14.0.0 (/Applications/tahoe.app/support/lib/python2.7/site-packages/service_identity-14.0.0-py2.7.egg)
29# characteristic: 14.1.0 (/Applications/tahoe.app/support/lib/python2.7/site-packages)
30# pyasn1-modules: 0.0.5 (/Applications/tahoe.app/support/lib/python2.7/site-packages/pyasn1_modules-0.0.5-py2.7.egg)
31
32
33import os, re, shutil, subprocess, sys, tempfile
34
35def test_osx_pkg(pkgfile):
36    """ Return on success, raise exception on failure. """
37
38    tmpdir = tempfile.mkdtemp(dir='/tmp')
39    # xar -C /tmp/tmpdir -xf PKGNAME
40    cmd = ['xar', '-C', tmpdir, '-xf', pkgfile]
41    extractit = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
42    rc = extractit.wait()
43    if rc != 0:
44        raise Exception("FAIL: xar returned non-zero exit code: %r from command: %r" % (rc, cmd,))
45
46    stderrtxt = extractit.stderr.read()
47    if stderrtxt:
48        raise Exception("FAIL: xar said something on stderr: %r" % (stderrtxt,))
49
50    # cd /tmp/tmpXXX/tahoe-lafs.pkg
51    os.chdir(tmpdir + '/tahoe-lafs.pkg')
52
53    # cat Payload | gunzip -dc | cpio -i
54    cat_process = subprocess.Popen(['cat', 'Payload'], stdout=subprocess.PIPE)
55    gunzip_process = subprocess.Popen(['gunzip', '-dc'],
56                                      stdin=cat_process.stdout,
57                                      stdout=subprocess.PIPE)
58    cpio_process = subprocess.Popen(['cpio', '-i', '--verbose'],
59                                    stdin=gunzip_process.stdout,
60                                    stdout=subprocess.PIPE)
61    cpio_process.communicate()
62
63    try:
64        basedir = os.getcwd()
65        cmd = ['bin/tahoe', '--version-and-path']
66        callit = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
67
68        rc = callit.wait()
69        if rc != 0:
70            print(
71                "{} failed.\n"
72                "stdout: {}\n"
73                "stderr: {}\n".format(
74                    cmd, callit.stdout.read(), callit.stderr.read(),
75                ),
76            )
77            raise Exception("FAIL: '%s' returned non-zero exit code: %r" % (" ".join(cmd), rc))
78        stdouttxt = callit.stdout.read()
79
80        PKG_VER_PATH_RE=re.compile("^(\S+): ([^\(]+)\((.+?)\)$", re.UNICODE)
81
82        for mo in PKG_VER_PATH_RE.finditer(stdouttxt):
83            if not mo.group(3).startswith(basedir):
84                # the following packages are provided by the OS X default installation itself
85                if not mo.group(1) in ['zope.interface', 'python', 'platform', 'pyOpenSSL']:
86                    raise Exception("FAIL: found package not loaded from basedir (%s); package was: %s" % (basedir, mo.groups(),))
87        # success!
88    finally:
89        shutil.rmtree(tmpdir)
90
91
92if __name__ == '__main__':
93    pkgs = [fn for fn in os.listdir(".") if fn.endswith("-osx.pkg")]
94    if len(pkgs) != 1:
95        print("ERR: unable to find a single .pkg file:", pkgs)
96        sys.exit(1)
97    print("Testing %s ..." % pkgs[0])
98    test_osx_pkg(pkgs[0])
99    print("Looks OK!")
Note: See TracBrowser for help on using the repository browser.