diff options
Diffstat (limited to 'Mac/BuildScript/build-installer.py')
| -rwxr-xr-x | Mac/BuildScript/build-installer.py | 169 |
1 files changed, 103 insertions, 66 deletions
diff --git a/Mac/BuildScript/build-installer.py b/Mac/BuildScript/build-installer.py index ba92012..1a16165 100755 --- a/Mac/BuildScript/build-installer.py +++ b/Mac/BuildScript/build-installer.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/env python """ This script is used to build "official" universal installers on Mac OS X. It requires at least Mac OS X 10.4, Xcode 2.2 and the 10.4u SDK for @@ -12,16 +12,25 @@ Python 2.4. Usage: see USAGE variable in the script. """ -import platform, os, sys, getopt, textwrap, shutil, urllib2, stat, time, pwd -import grp +import platform, os, sys, getopt, textwrap, shutil, stat, time, pwd, grp +try: + import urllib2 as urllib_request +except ImportError: + import urllib.request as urllib_request + +STAT_0o755 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR + | stat.S_IRGRP | stat.S_IXGRP + | stat.S_IROTH | stat.S_IXOTH ) + +STAT_0o775 = ( stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR + | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP + | stat.S_IROTH | stat.S_IXOTH ) INCLUDE_TIMESTAMP = 1 VERBOSE = 1 from plistlib import Plist -import MacOS - try: from plistlib import writePlist except ImportError: @@ -42,20 +51,35 @@ def grepValue(fn, variable): if ln.startswith(variable): value = ln[len(variable):].strip() return value[1:-1] - raise RuntimeError, "Cannot find variable %s" % variable[:-1] + raise RuntimeError("Cannot find variable %s" % variable[:-1]) + +_cache_getVersion = None def getVersion(): - return grepValue(os.path.join(SRCDIR, 'configure'), 'PACKAGE_VERSION') + global _cache_getVersion + if _cache_getVersion is None: + _cache_getVersion = grepValue( + os.path.join(SRCDIR, 'configure'), 'PACKAGE_VERSION') + return _cache_getVersion def getVersionTuple(): return tuple([int(n) for n in getVersion().split('.')]) +def getVersionMajorMinor(): + return tuple([int(n) for n in getVersion().split('.', 2)]) + +_cache_getFullVersion = None + def getFullVersion(): + global _cache_getFullVersion + if _cache_getFullVersion is not None: + return _cache_getFullVersion fn = os.path.join(SRCDIR, 'Include', 'patchlevel.h') for ln in open(fn): if 'PY_VERSION' in ln: - return ln.split()[-1][1:-1] - raise RuntimeError, "Cannot find full version??" + _cache_getFullVersion = ln.split()[-1][1:-1] + return _cache_getFullVersion + raise RuntimeError("Cannot find full version??") # The directory we'll use to create the build (will be erased and recreated) WORKDIR = "/tmp/_py" @@ -113,8 +137,10 @@ DEPTARGET = '10.3' target_cc_map = { '10.3': 'gcc-4.0', '10.4': 'gcc-4.0', - '10.5': 'gcc-4.0', + '10.5': 'gcc-4.2', '10.6': 'gcc-4.2', + '10.7': 'clang', + '10.8': 'clang', } CC = target_cc_map[DEPTARGET] @@ -143,6 +169,17 @@ USAGE = textwrap.dedent("""\ def library_recipes(): result = [] + result.extend([ + dict( + name="XZ 5.0.3", + url="http://tukaani.org/xz/xz-5.0.3.tar.gz", + checksum='fefe52f9ecd521de2a8ce38c21a27574', + configure_pre=[ + '--disable-dependency-tracking', + ] + ) + ]) + if DEPTARGET < '10.5': result.extend([ dict( @@ -326,7 +363,7 @@ def pkg_recipes(): ), ] - if DEPTARGET < '10.4': + if DEPTARGET < '10.4' and not PYTHON_3: result.append( dict( name="PythonSystemFixes", @@ -358,7 +395,7 @@ def fileContents(fn): """ Return the contents of the named file """ - return open(fn, 'rb').read() + return open(fn, 'r').read() def runCommand(commandline): """ @@ -370,7 +407,7 @@ def runCommand(commandline): xit = fd.close() if xit is not None: sys.stdout.write(data) - raise RuntimeError, "command failed: %s"%(commandline,) + raise RuntimeError("command failed: %s"%(commandline,)) if VERBOSE: sys.stdout.write(data); sys.stdout.flush() @@ -381,7 +418,7 @@ def captureCommand(commandline): xit = fd.close() if xit is not None: sys.stdout.write(data) - raise RuntimeError, "command failed: %s"%(commandline,) + raise RuntimeError("command failed: %s"%(commandline,)) return data @@ -450,12 +487,12 @@ def checkEnvironment(): for ev in list(os.environ): for prefix in environ_var_prefixes: if ev.startswith(prefix) : - print "INFO: deleting environment variable %s=%s" % ( - ev, os.environ[ev]) + print("INFO: deleting environment variable %s=%s" % ( + ev, os.environ[ev])) del os.environ[ev] os.environ['PATH'] = '/bin:/sbin:/usr/bin:/usr/sbin' - print "Setting default PATH: %s"%(os.environ['PATH']) + print("Setting default PATH: %s"%(os.environ['PATH'])) def parseOptions(args=None): @@ -472,18 +509,18 @@ def parseOptions(args=None): options, args = getopt.getopt(args, '?hb', [ 'build-dir=', 'third-party=', 'sdk-path=' , 'src-dir=', 'dep-target=', 'universal-archs=', 'help' ]) - except getopt.error, msg: - print msg + except getopt.GetoptError: + print(sys.exc_info()[1]) sys.exit(1) if args: - print "Additional arguments" + print("Additional arguments") sys.exit(1) deptarget = None for k, v in options: if k in ('-h', '-?', '--help'): - print USAGE + print(USAGE) sys.exit(0) elif k in ('-d', '--build-dir'): @@ -511,10 +548,10 @@ def parseOptions(args=None): # target DEPTARGET = default_target_map.get(v, '10.3') else: - raise NotImplementedError, v + raise NotImplementedError(v) else: - raise NotImplementedError, k + raise NotImplementedError(k) SRCDIR=os.path.abspath(SRCDIR) WORKDIR=os.path.abspath(WORKDIR) @@ -523,15 +560,15 @@ def parseOptions(args=None): CC=target_cc_map[DEPTARGET] - print "Settings:" - print " * Source directory:", SRCDIR - print " * Build directory: ", WORKDIR - print " * SDK location: ", SDKPATH - print " * Third-party source:", DEPSRC - print " * Deployment target:", DEPTARGET - print " * Universal architectures:", ARCHLIST - print " * C compiler:", CC - print "" + print("Settings:") + print(" * Source directory:", SRCDIR) + print(" * Build directory: ", WORKDIR) + print(" * SDK location: ", SDKPATH) + print(" * Third-party source:", DEPSRC) + print(" * Deployment target:", DEPTARGET) + print(" * Universal architectures:", ARCHLIST) + print(" * C compiler:", CC) + print("") @@ -576,7 +613,7 @@ def extractArchive(builddir, archiveName): xit = fp.close() if xit is not None: sys.stdout.write(data) - raise RuntimeError, "Cannot extract %s"%(archiveName,) + raise RuntimeError("Cannot extract %s"%(archiveName,)) return os.path.join(builddir, retval) @@ -598,9 +635,9 @@ def downloadURL(url, fname): pass else: if KNOWNSIZES.get(url) == size: - print "Using existing file for", url + print("Using existing file for", url) return - fpIn = urllib2.urlopen(url) + fpIn = urllib_request.urlopen(url) fpOut = open(fname, 'wb') block = fpIn.read(10240) try: @@ -637,15 +674,15 @@ def buildRecipe(recipe, basedir, archList): if os.path.exists(sourceArchive): - print "Using local copy of %s"%(name,) + print("Using local copy of %s"%(name,)) else: - print "Did not find local copy of %s"%(name,) - print "Downloading %s"%(name,) + print("Did not find local copy of %s"%(name,)) + print("Downloading %s"%(name,)) downloadURL(url, sourceArchive) - print "Archive for %s stored as %s"%(name, sourceArchive) + print("Archive for %s stored as %s"%(name, sourceArchive)) - print "Extracting archive for %s"%(name,) + print("Extracting archive for %s"%(name,)) buildDir=os.path.join(WORKDIR, '_bld') if not os.path.exists(buildDir): os.mkdir(buildDir) @@ -711,14 +748,14 @@ def buildRecipe(recipe, basedir, archList): if 'configure_env' in recipe: configure_args.insert(0, recipe['configure_env']) - print "Running configure for %s"%(name,) + print("Running configure for %s"%(name,)) runCommand(' '.join(configure_args) + ' 2>&1') - print "Running install for %s"%(name,) + print("Running install for %s"%(name,)) runCommand('{ ' + install + ' ;} 2>&1') - print "Done %s"%(name,) - print "" + print("Done %s"%(name,)) + print("") os.chdir(curdir) @@ -726,9 +763,9 @@ def buildLibraries(): """ Build our dependencies into $WORKDIR/libraries/usr/local """ - print "" - print "Building required libraries" - print "" + print("") + print("Building required libraries") + print("") universal = os.path.join(WORKDIR, 'libraries') os.mkdir(universal) os.makedirs(os.path.join(universal, 'usr', 'local', 'lib')) @@ -742,7 +779,7 @@ def buildLibraries(): def buildPythonDocs(): # This stores the documentation as Resources/English.lproj/Documentation # inside the framwork. pydoc and IDLE will pick it up there. - print "Install python documentation" + print("Install python documentation") rootDir = os.path.join(WORKDIR, '_root') buildDir = os.path.join('../../Doc') docdir = os.path.join(rootDir, 'pydocs') @@ -757,7 +794,7 @@ def buildPythonDocs(): def buildPython(): - print "Building a universal python for %s architectures" % UNIVERSALARCHS + print("Building a universal python for %s architectures" % UNIVERSALARCHS) buildDir = os.path.join(WORKDIR, '_bld', 'python') rootDir = os.path.join(WORKDIR, '_root') @@ -785,7 +822,7 @@ def buildPython(): # will find them during its extension import sanity checks. os.environ['DYLD_LIBRARY_PATH'] = os.path.join(WORKDIR, 'libraries', 'usr', 'local', 'lib') - print "Running configure..." + print("Running configure...") runCommand("%s -C --enable-framework --enable-universalsdk=%s " "--with-universal-archs=%s " "%s " @@ -797,19 +834,19 @@ def buildPython(): shellQuote(WORKDIR)[1:-1], shellQuote(WORKDIR)[1:-1])) - print "Running make" + print("Running make") runCommand("make") - print "Running make install" + print("Running make install") runCommand("make install DESTDIR=%s"%( shellQuote(rootDir))) - print "Running make frameworkinstallextras" + print("Running make frameworkinstallextras") runCommand("make frameworkinstallextras DESTDIR=%s"%( shellQuote(rootDir))) del os.environ['DYLD_LIBRARY_PATH'] - print "Copying required shared libraries" + print("Copying required shared libraries") if os.path.exists(os.path.join(WORKDIR, 'libraries', 'Library')): runCommand("mv %s/* %s"%( shellQuote(os.path.join( @@ -820,13 +857,13 @@ def buildPython(): 'Python.framework', 'Versions', getVersion(), 'lib')))) - print "Fix file modes" + print("Fix file modes") frmDir = os.path.join(rootDir, 'Library', 'Frameworks', 'Python.framework') gid = grp.getgrnam('admin').gr_gid for dirpath, dirnames, filenames in os.walk(frmDir): for dn in dirnames: - os.chmod(os.path.join(dirpath, dn), 0775) + os.chmod(os.path.join(dirpath, dn), STAT_0o775) os.chown(os.path.join(dirpath, dn), -1, gid) @@ -907,17 +944,17 @@ def patchFile(inPath, outPath): # This one is not handy as a template variable data = data.replace('$PYTHONFRAMEWORKINSTALLDIR', '/Library/Frameworks/Python.framework') - fp = open(outPath, 'wb') + fp = open(outPath, 'w') fp.write(data) fp.close() def patchScript(inPath, outPath): data = fileContents(inPath) data = data.replace('@PYVER@', getVersion()) - fp = open(outPath, 'wb') + fp = open(outPath, 'w') fp.write(data) fp.close() - os.chmod(outPath, 0755) + os.chmod(outPath, STAT_0o755) @@ -934,7 +971,7 @@ def packageFromRecipe(targetDir, recipe): readme = textwrap.dedent(recipe['readme']) isRequired = recipe.get('required', True) - print "- building package %s"%(pkgname,) + print("- building package %s"%(pkgname,)) # Substitute some variables textvars = dict( @@ -979,7 +1016,7 @@ def packageFromRecipe(targetDir, recipe): patchScript(postflight, os.path.join(rsrcDir, 'postflight')) vers = getFullVersion() - major, minor = map(int, getVersion().split('.', 2)) + major, minor = getVersionMajorMinor() pl = Plist( CFBundleGetInfoString="Python.%s %s"%(pkgname, vers,), CFBundleIdentifier='org.python.Python.%s'%(pkgname,), @@ -1016,7 +1053,7 @@ def packageFromRecipe(targetDir, recipe): def makeMpkgPlist(path): vers = getFullVersion() - major, minor = map(int, getVersion().split('.', 2)) + major, minor = getVersionMajorMinor() pl = Plist( CFBundleGetInfoString="Python %s"%(vers,), @@ -1198,7 +1235,7 @@ def main(): folder = os.path.join(WORKDIR, "_root", "Applications", "Python %s"%( getVersion(),)) - os.chmod(folder, 0755) + os.chmod(folder, STAT_0o755) setIcon(folder, "../Icons/Python Folder.icns") # Create the installer @@ -1211,9 +1248,9 @@ def main(): shutil.copy('../../LICENSE', os.path.join(WORKDIR, 'installer', 'License.txt')) fp = open(os.path.join(WORKDIR, 'installer', 'Build.txt'), 'w') - print >> fp, "# BUILD INFO" - print >> fp, "# Date:", time.ctime() - print >> fp, "# By:", pwd.getpwuid(os.getuid()).pw_gecos + fp.write("# BUILD INFO\n") + fp.write("# Date: %s\n" % time.ctime()) + fp.write("# By: %s\n" % pwd.getpwuid(os.getuid()).pw_gecos) fp.close() # And copy it to a DMG |
