Changes to allow these build scripts to use python3

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71549 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2012-05-24 23:26:34 +00:00
parent c9db153a51
commit 016a3d4cee
3 changed files with 57 additions and 46 deletions

View File

@@ -9,7 +9,6 @@ import os
import re import re
import sys import sys
import builder import builder
import commands
import glob import glob
import optparse import optparse
import platform import platform
@@ -38,7 +37,7 @@ def numCPUs():
""" """
# Linux, Unix and MacOS: # Linux, Unix and MacOS:
if hasattr(os, "sysconf"): if hasattr(os, "sysconf"):
if os.sysconf_names.has_key("SC_NPROCESSORS_ONLN"): if "SC_NPROCESSORS_ONLN" in os.sysconf_names:
# Linux & Unix: # Linux & Unix:
ncpus = os.sysconf("SC_NPROCESSORS_ONLN") ncpus = os.sysconf("SC_NPROCESSORS_ONLN")
if isinstance(ncpus, int) and ncpus > 0: if isinstance(ncpus, int) and ncpus > 0:
@@ -48,7 +47,7 @@ def numCPUs():
return p.stdout.read() return p.stdout.read()
# Windows: # Windows:
if os.environ.has_key("NUMBER_OF_PROCESSORS"): if "NUMBER_OF_PROCESSORS" in os.environ:
ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]); ncpus = int(os.environ["NUMBER_OF_PROCESSORS"]);
if ncpus > 0: if ncpus > 0:
return ncpus return ncpus
@@ -56,16 +55,14 @@ def numCPUs():
def getXcodePath(): def getXcodePath():
p = subprocess.Popen("xcode-select -print-path", shell=True, stdout=subprocess.PIPE) return getoutput("xcode-select -print-path")
output = p.stdout.read()
return output.strip()
def exitIfError(code, msg): def exitIfError(code, msg):
if code != 0: if code != 0:
print msg print(msg)
if exitWithException: if exitWithException:
raise builder.BuildError, msg raise builder.BuildError(msg)
else: else:
sys.exit(1) sys.exit(1)
@@ -110,14 +107,14 @@ def macFixupInstallNames(destdir, prefix, buildDir=None):
# When an installdir is used then the install_names embedded in # When an installdir is used then the install_names embedded in
# the dylibs are not correct. Reset the IDs and the dependencies # the dylibs are not correct. Reset the IDs and the dependencies
# to use just the prefix. # to use just the prefix.
print "**** macFixupInstallNames(%s, %s, %s)" % (destdir, prefix, buildDir) print("**** macFixupInstallNames(%s, %s, %s)" % (destdir, prefix, buildDir))
pwd = os.getcwd() pwd = os.getcwd()
os.chdir(destdir+prefix+'/lib') os.chdir(destdir+prefix+'/lib')
dylibs = glob.glob('*.dylib') # ('*[0-9].[0-9].[0-9].[0-9]*.dylib') dylibs = glob.glob('*.dylib') # ('*[0-9].[0-9].[0-9].[0-9]*.dylib')
for lib in dylibs: for lib in dylibs:
cmd = 'install_name_tool -id %s/lib/%s %s/lib/%s' % \ cmd = 'install_name_tool -id %s/lib/%s %s/lib/%s' % \
(prefix,lib, destdir+prefix,lib) (prefix,lib, destdir+prefix,lib)
print cmd print(cmd)
run(cmd) run(cmd)
for dep in dylibs: for dep in dylibs:
if buildDir is not None: if buildDir is not None:
@@ -126,7 +123,7 @@ def macFixupInstallNames(destdir, prefix, buildDir=None):
else: else:
cmd = 'install_name_tool -change %s/lib/%s %s/lib/%s %s/lib/%s' % \ cmd = 'install_name_tool -change %s/lib/%s %s/lib/%s %s/lib/%s' % \
(destdir+prefix,dep, prefix,dep, destdir+prefix,lib) (destdir+prefix,dep, prefix,dep, destdir+prefix,lib)
print cmd print(cmd)
run(cmd) run(cmd)
os.chdir(pwd) os.chdir(pwd)
@@ -134,10 +131,25 @@ def macFixupInstallNames(destdir, prefix, buildDir=None):
def run(cmd): def run(cmd):
global verbose global verbose
if verbose: if verbose:
print "Running %s" % cmd print("Running %s" % cmd)
return exitIfError(os.system(cmd), "Error running %s" % cmd) return exitIfError(os.system(cmd), "Error running %s" % cmd)
def getoutput(cmd):
sp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
output = None
output = sp.stdout.read()
if sys.version_info > (3,):
output = output.decode('utf-8') # TODO: is utf-8 okay here?
output = output.rstrip()
rval = sp.wait()
if rval:
# Failed!
print("Command '%s' failed with exit code %d." % (cmd, rval))
sys.exit(rval)
return output
def main(scriptName, args): def main(scriptName, args):
global scriptDir global scriptDir
global wxRootDir global wxRootDir
@@ -196,11 +208,10 @@ def main(scriptName, args):
parser = optparse.OptionParser(usage="usage: %prog [options]", version="%prog 1.0") parser = optparse.OptionParser(usage="usage: %prog [options]", version="%prog 1.0")
keys = option_dict.keys() keys = option_dict.keys()
keys.sort() for opt in sorted(keys):
for opt in keys:
default = option_dict[opt][0] default = option_dict[opt][0]
action = "store" action = "store"
if type(default) == types.BooleanType: if type(default) == bool:
action = "store_true" action = "store_true"
parser.add_option("--" + opt, default=default, action=action, dest=opt, parser.add_option("--" + opt, default=default, action=action, dest=opt,
help=option_dict[opt][1]) help=option_dict[opt][1])
@@ -321,7 +332,7 @@ def main(scriptName, args):
configure_opts.append("--enable-universal_binary=%s" % options.mac_universal_binary) configure_opts.append("--enable-universal_binary=%s" % options.mac_universal_binary)
print "Configure options: " + `configure_opts` print("Configure options: " + repr(configure_opts))
wxBuilder = builder.AutoconfBuilder() wxBuilder = builder.AutoconfBuilder()
if not options.no_config and not options.clean: if not options.no_config and not options.clean:
olddir = os.getcwd() olddir = os.getcwd()
@@ -332,14 +343,14 @@ def main(scriptName, args):
os.chdir(olddir) os.chdir(olddir)
if options.config_only: if options.config_only:
print "Exiting after configure" print("Exiting after configure")
return return
elif toolkit in ["msvc", "msvcProject"]: elif toolkit in ["msvc", "msvcProject"]:
flags = {} flags = {}
buildDir = os.path.abspath(os.path.join(scriptDir, "..", "msw")) buildDir = os.path.abspath(os.path.join(scriptDir, "..", "msw"))
print "creating wx/msw/setup.h from setup0.h" print("creating wx/msw/setup.h from setup0.h")
if options.unicode: if options.unicode:
flags["wxUSE_UNICODE"] = "1" flags["wxUSE_UNICODE"] = "1"
if VERSION < (2,9): if VERSION < (2,9):
@@ -347,7 +358,7 @@ def main(scriptName, args):
if options.cairo: if options.cairo:
if not os.environ.get("CAIRO_ROOT"): if not os.environ.get("CAIRO_ROOT"):
print "WARNING: Expected CAIRO_ROOT set in the environment!" print("WARNING: Expected CAIRO_ROOT set in the environment!")
flags["wxUSE_CAIRO"] = "1" flags["wxUSE_CAIRO"] = "1"
if options.wxpython: if options.wxpython:
@@ -375,7 +386,7 @@ def main(scriptName, args):
for flag in flags: for flag in flags:
setupText, subsMade = re.subn(flag + "\s+?\d", "%s %s" % (flag, flags[flag]), setupText) setupText, subsMade = re.subn(flag + "\s+?\d", "%s %s" % (flag, flags[flag]), setupText)
if subsMade == 0: if subsMade == 0:
print "Flag %s wasn't found in setup0.h!" % flag print("Flag %s wasn't found in setup0.h!" % flag)
sys.exit(1) sys.exit(1)
setupFile = open(os.path.join(mswIncludeDir, "setup.h"), "wb") setupFile = open(os.path.join(mswIncludeDir, "setup.h"), "wb")
@@ -383,7 +394,7 @@ def main(scriptName, args):
setupFile.close() setupFile.close()
args = [] args = []
if toolkit == "msvc": if toolkit == "msvc":
print "setting build options..." print("setting build options...")
args.append("-f makefile.vc") args.append("-f makefile.vc")
if options.unicode: if options.unicode:
args.append("UNICODE=1") args.append("UNICODE=1")
@@ -424,11 +435,11 @@ def main(scriptName, args):
if not wxBuilder: if not wxBuilder:
print "Builder not available for your specified platform/compiler." print("Builder not available for your specified platform/compiler.")
sys.exit(1) sys.exit(1)
if options.clean: if options.clean:
print "Performing cleanup." print("Performing cleanup.")
wxBuilder.clean(dir=buildDir, options=args) wxBuilder.clean(dir=buildDir, options=args)
sys.exit(0) sys.exit(0)
@@ -455,7 +466,7 @@ def main(scriptName, args):
links.append(reallib) links.append(reallib)
reallib = "lib/" + os.readlink(reallib) reallib = "lib/" + os.readlink(reallib)
#print "reallib is %s" % reallib #print("reallib is %s" % reallib)
run("mv -f %s lib/%s.dylib" % (reallib, frameworkname)) run("mv -f %s lib/%s.dylib" % (reallib, frameworkname))
for link in links: for link in links:
@@ -463,7 +474,7 @@ def main(scriptName, args):
frameworkRootDir = prefixDir frameworkRootDir = prefixDir
if installDir: if installDir:
print "installDir = %s" % installDir print("installDir = %s" % installDir)
frameworkRootDir = installDir + prefixDir frameworkRootDir = installDir + prefixDir
os.chdir(frameworkRootDir) os.chdir(frameworkRootDir)
build_string = "" build_string = ""
@@ -471,10 +482,10 @@ def main(scriptName, args):
build_string = "d" build_string = "d"
fwname = getFrameworkName(options) fwname = getFrameworkName(options)
version = commands.getoutput("bin/wx-config --release") version = getoutput("bin/wx-config --release")
version_full = commands.getoutput("bin/wx-config --version") version_full = getoutput("bin/wx-config --version")
basename = commands.getoutput("bin/wx-config --basename") basename = getoutput("bin/wx-config --basename")
configname = commands.getoutput("bin/wx-config --selected-config") configname = getoutput("bin/wx-config --selected-config")
os.makedirs("Resources") os.makedirs("Resources")
wxplist = dict( wxplist = dict(
@@ -559,10 +570,10 @@ def main(scriptName, args):
file('lib/wx/config/%s' % configname, 'w').write(text) file('lib/wx/config/%s' % configname, 'w').write(text)
# The framework is finished! # The framework is finished!
print "wxWidgets framework created at: " + \ print("wxWidgets framework created at: " +
os.path.join( installDir, os.path.join( installDir,
options.mac_framework_prefix, options.mac_framework_prefix,
'%s.framework' % fwname) '%s.framework' % fwname))
# adjust the install_name if needed # adjust the install_name if needed
@@ -596,7 +607,7 @@ def main(scriptName, args):
args.append("--version %s" % getWxRelease()) args.append("--version %s" % getWxRelease())
args.append("--out %s" % os.path.join(packagedir, packageName + ".pkg")) args.append("--out %s" % os.path.join(packagedir, packageName + ".pkg"))
cmd = packageMakerPath + ' '.join(args) cmd = packageMakerPath + ' '.join(args)
print "cmd = %s" % cmd print("cmd = %s" % cmd)
run(cmd) run(cmd)
os.chdir(options.mac_distdir) os.chdir(options.mac_distdir)

View File

@@ -18,7 +18,7 @@ def runInDir(command, dir=None, verbose=True):
commandStr = " ".join(command) commandStr = " ".join(command)
if verbose: if verbose:
print commandStr print(commandStr)
result = os.system(commandStr) result = os.system(commandStr)
if dir: if dir:
@@ -181,7 +181,7 @@ class AutoconfBuilder(GNUMakeBuilder):
optionsStr = string.join(options, " ") if options else "" optionsStr = string.join(options, " ") if options else ""
command = "%s %s" % (configure_cmd, optionsStr) command = "%s %s" % (configure_cmd, optionsStr)
print command print(command)
result = os.system(command) result = os.system(command)
#os.chdir(olddir) #os.chdir(olddir)
return result return result

View File

@@ -785,7 +785,7 @@ def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest, docstr_dest):
curDocStrings = [] curDocStrings = []
elif op == 'cat ': elif op == 'cat ':
if string.strip(line[4:]) == 'Deprecated': if line[4:].strip() == 'Deprecated':
break # skip the rest of the file break # skip the rest of the file
elif op == 'evt ': elif op == 'evt ':
@@ -798,7 +798,7 @@ def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest, docstr_dest):
pass pass
else: else:
print '***** Unknown line type: ', line print('***** Unknown line type: %s' % line)
# process templates # process templates
@@ -825,7 +825,7 @@ def processIface(iface, h_tmplt, cpp_tmplt, h_dest, cpp_dest, docstr_dest):
def joinWithNewLines(values): def joinWithNewLines(values):
return string.join(values, '\n') return '\n'.join(values)
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
@@ -905,7 +905,7 @@ def processMethods(methods):
def checkMethodOverride(name, number, docs): def checkMethodOverride(name, number, docs):
theDef = theImp = None theDef = theImp = None
if methodOverrideMap.has_key(name): if name in methodOverrideMap:
item = methodOverrideMap[name] item = methodOverrideMap[name]
try: try:
@@ -918,7 +918,7 @@ def checkMethodOverride(name, number, docs):
if item[3] != 0: if item[3] != 0:
docs = item[3] docs = item[3]
except: except:
print "*************", name print("************* " + name)
raise raise
return name, theDef, theImp, docs return name, theDef, theImp, docs
@@ -958,7 +958,7 @@ def makeParamString(param1, param2):
#---------------------------------------------------------------------------- #----------------------------------------------------------------------------
def parseVal(line, values, docs): def parseVal(line, values, docs):
name, val = string.split(line, '=') name, val = line.split('=')
# remove prefixes such as SCI, etc. # remove prefixes such as SCI, etc.
for old, new in valPrefixes: for old, new in valPrefixes:
@@ -981,16 +981,16 @@ funregex = re.compile(r'\s*([a-zA-Z0-9_]+)' # <ws>return type
def parseFun(line, methods, docs, values, is_const): def parseFun(line, methods, docs, values, is_const):
def parseParam(param): def parseParam(param):
param = string.strip(param) param = param.strip()
if param == '': if param == '':
param = None param = None
else: else:
param = tuple(string.split(param)) param = tuple(param.split())
return param return param
mo = funregex.match(line) mo = funregex.match(line)
if mo is None: if mo is None:
print "***** Line doesn't match! : " + line print("***** Line doesn't match! : %s" % line)
retType, name, number, param1, param2 = mo.groups() retType, name, number, param1, param2 = mo.groups()
@@ -998,10 +998,10 @@ def parseFun(line, methods, docs, values, is_const):
param2 = parseParam(param2) param2 = parseParam(param2)
# Special case. For the key command functions we want a value defined too # Special case. For the key command functions we want a value defined too
num = string.atoi(number) num = int(number)
for v in cmdValues: for v in cmdValues:
if (type(v) == type(()) and v[0] <= num <= v[1]) or v == num: if (type(v) == type(()) and v[0] <= num <= v[1]) or v == num:
parseVal('CMD_%s=%s' % (string.upper(name), number), values, docs) parseVal('CMD_%s=%s' % (name.upper(), number), values, docs)
# if we are not also doing a function for CMD values, then # if we are not also doing a function for CMD values, then
# just return, otherwise fall through to the append blow. # just return, otherwise fall through to the append blow.
@@ -1019,7 +1019,7 @@ def main(args):
# TODO: parse command line args to replace default input/output files??? # TODO: parse command line args to replace default input/output files???
if not os.path.exists(IFACE): if not os.path.exists(IFACE):
print 'Please run this script from src/stc subdirectory.' print('Please run this script from src/stc subdirectory.')
sys.exit(1) sys.exit(1)
# Now just do it # Now just do it