From 32b174134bccad79f81b74ef02463426837fbcd4 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 14 Dec 2012 08:49:44 +0000 Subject: [PATCH] Verify that the cl.exe used for the wx and py builds is the one that the target Python wants to be built with, and also set the environment vars from that version of the compiler's vcvarsall.bat the same way that distutils does it. Ensure that CPU is set for the wx build. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxPython/Phoenix/trunk@73187 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- build.py | 43 ++++++++++++++++++++++++++++++++++++++++++- buildtools/config.py | 4 ++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/build.py b/build.py index f936f796..6640e8b7 100755 --- a/build.py +++ b/build.py @@ -173,6 +173,7 @@ def setPythonVersion(args): global PYSHORTVER global PYTHON global PYTHON_ARCH + for idx, arg in enumerate(args): if re.match(r'^[0-9]\.[0-9]$', arg): PYVER = arg @@ -191,8 +192,11 @@ def setPythonVersion(args): TOOLS = os.environ.get('TOOLS') if 'cygdrive' in TOOLS: TOOLS = runcmd('c:/cygwin/bin/cygpath -w '+TOOLS, True, False) + use64flag = '--x64' in args + if use64flag: + args.remove('--x64') CPU = os.environ.get('CPU') - if CPU in ['AMD64', 'X64']: + if use64flag or CPU in ['AMD64', 'X64', 'amd64', 'x64']: TOOLS = posixjoin(TOOLS, 'amd64') PYTHON = posixjoin(TOOLS, 'python%s' % PYSHORTVER, @@ -204,6 +208,8 @@ def setPythonVersion(args): PYVER = sys.version[:3] PYSHORTVER = PYVER[0] + PYVER[2] msg('Using %s' % PYTHON) + + else: findPython = runcmd("which %s" % PYTHON, True, False) msg('Found %s at %s' % (PYTHON, findPython)) @@ -214,6 +220,11 @@ def setPythonVersion(args): % PYTHON, True, False) msg('Python\'s architecture is %s' % PYTHON_ARCH) os.environ['PYTHON'] = PYTHON + + if PYTHON_ARCH == '64bit': + # This may be set already, but there are a couple code paths above + # where it may not be... + os.environ['CPU'] = 'X64' @@ -520,6 +531,33 @@ def uploadPackage(fileName, matchString, keep=5): +def checkCompiler(): + if isWindows: + # Make sure that the compiler that Python wants to use can be found. + # It will terminate if the compiler is not found or other exceptions + # are raised. + cmd = "import distutils.msvc9compiler as msvc; " \ + "mc = msvc.MSVCCompiler(); " \ + "mc.initialize(); " \ + "print(mc.cc)" + CC = runcmd('%s -c "%s"' % (PYTHON, cmd), getOutput=True, echoCmd=False) + msg("MSVC: %s" % CC) + + # Now get the environment variables which that compiler needs from + # its vcvarsall.bat command and load them into this process's + # environment. + cmd = "import distutils.msvc9compiler as msvc; " \ + "arch = msvc.PLAT_TO_VCVARS[msvc.get_platform()]; " \ + "env = msvc.query_vcvarsall(msvc.VERSION, arch); " \ + "print(env)" + env = eval(runcmd('%s -c "%s"' % (PYTHON, cmd), getOutput=True, echoCmd=False)) + os.environ['PATH'] = bytes(env['path']) + os.environ['INCLUDE'] = bytes(env['include']) + os.environ['LIB'] = bytes(env['lib']) + os.environ['LIBPATH'] = bytes(env['libpath']) + + + #--------------------------------------------------------------------------- # Command functions #--------------------------------------------------------------------------- @@ -812,6 +850,7 @@ def build(options, args): def build_wx(options, args): cmdTimer = CommandTimer('build_wx') + checkCompiler() build_options = ['--wxpython', '--unicode'] @@ -960,6 +999,7 @@ def copyWxDlls(options): def setup_py(options, args): cmdTimer = CommandTimer('setup_py') + checkCompiler() BUILD_DIR = getBuildDir(options) DESTDIR = options.installdir @@ -1054,6 +1094,7 @@ def setup_py(options, args): def waf_py(options, args): cmdTimer = CommandTimer('waf_py') waf = getWafCmd() + checkCompiler() BUILD_DIR = getBuildDir(options) DESTDIR = options.installdir diff --git a/buildtools/config.py b/buildtools/config.py index a3f42c56..697e9a12 100644 --- a/buildtools/config.py +++ b/buildtools/config.py @@ -792,6 +792,8 @@ def runcmd(cmd, getOutput=False, echoCmd=True, fatal=True): # Failed! #raise subprocess.CalledProcessError(rval, cmd) print("Command '%s' failed with exit code %d." % (cmd, rval)) + if getOutput: + print(output) if fatal: sys.exit(rval) @@ -839,6 +841,8 @@ def getSipFiles(names): def getVisCVersion(): text = runcmd("cl.exe", getOutput=True, echoCmd=False) + if 'Version 13' in text: + return '71' if 'Version 15' in text: return '90' # TODO: Add more tests to get the other versions...