comparison mx/commands.py @ 4177:c843578c269d

Make building work on Windows.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 02 Jan 2012 17:47:48 +0100
parents 48f89a17f86a
children d1b26c17910a
comparison
equal deleted inserted replaced
4167:3e749481e445 4177:c843578c269d
24 # or visit www.oracle.com if you need additional information or have any 24 # or visit www.oracle.com if you need additional information or have any
25 # questions. 25 # questions.
26 # 26 #
27 # ---------------------------------------------------------------------------------------------------- 27 # ----------------------------------------------------------------------------------------------------
28 28
29 import os, sys, shutil, StringIO, zipfile, tempfile, re, time, datetime 29 import os, sys, shutil, StringIO, zipfile, tempfile, re, time, datetime, platform, subprocess
30 from os.path import join, exists, dirname, isdir, isfile, isabs, basename 30 from os.path import join, exists, dirname, isdir, isfile, isabs, basename
31 from argparse import ArgumentParser, REMAINDER 31 from argparse import ArgumentParser, REMAINDER
32 import mx 32 import mx
33 33
34 _graal_home = dirname(dirname(__file__)) 34 _graal_home = dirname(dirname(__file__))
35 _vmSourcesAvailable = exists(join(_graal_home, 'make')) and exists(join(_graal_home, 'src')) 35 _vmSourcesAvailable = exists(join(_graal_home, 'make')) and exists(join(_graal_home, 'src'))
36 _vmbuild = 'product' 36 _vmbuild = 'product'
37 _winSDK = 'C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\'
38 _mksHome = 'C:\\cygwin\\bin'
37 39
38 def clean(args): 40 def clean(args):
39 """cleans the GraalVM source tree""" 41 """cleans the GraalVM source tree"""
40 mx.clean(args) 42 mx.clean(args)
41 os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='16') 43 os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='16')
231 for d in ['bin', 'db', 'include', 'jre', 'lib', 'man']: 233 for d in ['bin', 'db', 'include', 'jre', 'lib', 'man']:
232 shutil.copytree(join(jdk, d), join(res, d)) 234 shutil.copytree(join(jdk, d), join(res, d))
233 return res 235 return res
234 else: 236 else:
235 mx.abort('Unknown build type: ' + build) 237 mx.abort('Unknown build type: ' + build)
238
239 # run a command in the windows SDK Debug Shell
240 def runInDebugShell(cmd, workingDir, logFile=None, findInOutput=None, respondTo={}):
241 newLine = os.linesep
242 STARTTOKEN = 'RUNINDEBUGSHELL_STARTSEQUENCE'
243 ENDTOKEN = 'RUNINDEBUGSHELL_ENDSEQUENCE'
244 p = subprocess.Popen('cmd.exe /E:ON /V:ON /K ""' + _winSDK + '/Bin/SetEnv.cmd" & echo ' + STARTTOKEN + '"', \
245 shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
246 output = p.stdout
247 input = p.stdin
248 if logFile:
249 log = open(logFile, 'w')
250 ret = False
251 while True:
252 line = output.readline().decode()
253 if logFile:
254 log.write(line)
255 line = line.strip()
256 mx.log(line)
257 if line == STARTTOKEN:
258 input.write('cd /D ' + workingDir + ' & ' + cmd + ' & echo ' + ENDTOKEN + newLine)
259 for regex in respondTo.keys():
260 match = regex.search(line)
261 if match:
262 input.write(respondTo[regex] + newLine)
263 if findInOutput:
264 match = findInOutput.search(line)
265 if match:
266 ret = True
267 if line == ENDTOKEN:
268 break
269 input.write('exit' + newLine)
270 if logFile:
271 log.close()
272 return ret
236 273
237 def build(args): 274 def build(args):
238 """builds the GraalVM binary and compiles the Graal classes 275 """builds the GraalVM binary and compiles the Graal classes
239 276
240 The optional argument specifies what type of VM to build.""" 277 The optional argument specifies what type of VM to build."""
260 297
261 def filterXusage(line): 298 def filterXusage(line):
262 if not 'Xusage.txt' in line: 299 if not 'Xusage.txt' in line:
263 sys.stderr.write(line + os.linesep) 300 sys.stderr.write(line + os.linesep)
264 301
265 os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='3', ALT_BOOTDIR=jdk, INSTALL='y') 302 if platform.system() == 'Windows':
266 mx.run([mx.gmake_cmd(), build + 'graal'], cwd=join(_graal_home, 'make'), err=filterXusage) 303 compilelogfile = _graal_home + '/graalCompile.log'
304 runInDebugShell('msbuild ' + _graal_home + r'\build\vs-amd64\jvm.vcproj /p:Configuration=compiler1_product /target:clean', _graal_home)
305 winCompileCmd = r'set HotSpotMksHome=' + _mksHome + r'& set OUT_DIR=' + jdk + r'& set JAVA_HOME=' + jdk + r'& set path=%JAVA_HOME%\bin;%path%;%HotSpotMksHome%& cd /D "' +_graal_home + r'\make\windows"& call create.bat ' + _graal_home + ''
306 print(winCompileCmd)
307 winCompileSuccess = re.compile(r"^Writing \.vcxproj file:")
308 if not runInDebugShell(winCompileCmd, _graal_home, compilelogfile, winCompileSuccess):
309 mx.log('Error executing create command')
310 return
311 winBuildCmd = 'msbuild ' + _graal_home + r'\build\vs-amd64\jvm.vcxproj /p:Configuration=compiler1_product /p:Platform=x64'
312 winBuildSuccess = re.compile('Build succeeded.')
313 if not runInDebugShell(winBuildCmd, _graal_home, compilelogfile, winBuildSuccess):
314 mx.log('Error building project')
315 return
316 else:
317 os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='3', ALT_BOOTDIR=jdk, INSTALL='y')
318 mx.run([mx.gmake_cmd(), build + 'graal'], cwd=join(_graal_home, 'make'), err=filterXusage)
267 319
268 def vm(args, vm='-graal', nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None): 320 def vm(args, vm='-graal', nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None):
269 """run the GraalVM""" 321 """run the GraalVM"""
270 322
271 build = _vmbuild if _vmSourcesAvailable else 'product' 323 build = _vmbuild if _vmSourcesAvailable else 'product'