Mercurial > hg > graal-jvmci-8
comparison mx/mx_graal.py @ 17233:a02c295218aa
mx: add support for cygwin
* use `cygpath' to translate paths
* pay attention when passing paths from unix world to windows world (e.g., when calling out to `javac')
* adapt _runInDebugShell to avoid quoting issues
author | Bernhard Urban <bernhard.urban@jku.at> |
---|---|
date | Fri, 26 Sep 2014 04:53:13 -0700 |
parents | 3e4d3be0b6bf |
children | b641450c19ce |
comparison
equal
deleted
inserted
replaced
17226:5b8f316bdb9e | 17233:a02c295218aa |
---|---|
152 global _vm, _vmbuild | 152 global _vm, _vmbuild |
153 _vm = self.previousVm | 153 _vm = self.previousVm |
154 _vmbuild = self.previousBuild | 154 _vmbuild = self.previousBuild |
155 | 155 |
156 def chmodRecursive(dirname, chmodFlagsDir): | 156 def chmodRecursive(dirname, chmodFlagsDir): |
157 if mx.get_os() == 'windows': | |
158 return | |
159 | |
157 def _chmodDir(chmodFlags, dirname, fnames): | 160 def _chmodDir(chmodFlags, dirname, fnames): |
158 os.chmod(dirname, chmodFlagsDir) | 161 os.chmod(dirname, chmodFlagsDir) |
159 | 162 |
160 os.path.walk(dirname, _chmodDir, chmodFlagsDir) | 163 os.path.walk(dirname, _chmodDir, chmodFlagsDir) |
161 | 164 |
349 def _vmLibDirInJdk(jdk): | 352 def _vmLibDirInJdk(jdk): |
350 """ | 353 """ |
351 Get the directory within a JDK where the server and client | 354 Get the directory within a JDK where the server and client |
352 subdirectories are located. | 355 subdirectories are located. |
353 """ | 356 """ |
354 if platform.system() == 'Darwin': | 357 mxos = mx.get_os() |
358 if mxos == 'darwin': | |
355 return join(jdk, 'jre', 'lib') | 359 return join(jdk, 'jre', 'lib') |
356 if platform.system() == 'Windows': | 360 if mxos == 'windows' or mxos == 'cygwin': |
357 return join(jdk, 'jre', 'bin') | 361 return join(jdk, 'jre', 'bin') |
358 return join(jdk, 'jre', 'lib', mx.get_arch()) | 362 return join(jdk, 'jre', 'lib', mx.get_arch()) |
359 | 363 |
360 def _vmJliLibDirs(jdk): | 364 def _vmJliLibDirs(jdk): |
361 """ | 365 """ |
362 Get the directories within a JDK where the jli library designates to. | 366 Get the directories within a JDK where the jli library designates to. |
363 """ | 367 """ |
364 if platform.system() == 'Darwin': | 368 mxos = mx.get_os() |
369 if mxos == 'darwin': | |
365 return [join(jdk, 'jre', 'lib', 'jli')] | 370 return [join(jdk, 'jre', 'lib', 'jli')] |
366 if platform.system() == 'Windows': | 371 if mxos == 'windows' or mxos == 'cygwin': |
367 return [join(jdk, 'jre', 'bin'), join(jdk, 'bin')] | 372 return [join(jdk, 'jre', 'bin'), join(jdk, 'bin')] |
368 return [join(jdk, 'jre', 'lib', mx.get_arch(), 'jli'), join(jdk, 'lib', mx.get_arch(), 'jli')] | 373 return [join(jdk, 'jre', 'lib', mx.get_arch(), 'jli'), join(jdk, 'lib', mx.get_arch(), 'jli')] |
369 | 374 |
370 def _vmCfgInJdk(jdk, jvmCfgFile='jvm.cfg'): | 375 def _vmCfgInJdk(jdk, jvmCfgFile='jvm.cfg'): |
371 """ | 376 """ |
372 Get the jvm.cfg file. | 377 Get the jvm.cfg file. |
373 """ | 378 """ |
374 if platform.system() == 'Windows': | 379 mxos = mx.get_os() |
380 if mxos == "windows" or mxos == "cygwin": | |
375 return join(jdk, 'jre', 'lib', mx.get_arch(), jvmCfgFile) | 381 return join(jdk, 'jre', 'lib', mx.get_arch(), jvmCfgFile) |
376 return join(_vmLibDirInJdk(jdk), jvmCfgFile) | 382 return join(_vmLibDirInJdk(jdk), jvmCfgFile) |
377 | 383 |
378 def _jdksDir(): | 384 def _jdksDir(): |
379 return os.path.abspath(join(_installed_jdks if _installed_jdks else _graal_home, 'jdk' + str(mx.java().version))) | 385 return os.path.abspath(join(_installed_jdks if _installed_jdks else _graal_home, 'jdk' + str(mx.java().version))) |
424 mx.log("WARNING: skipping not parsable line \"" + line + "\"") | 430 mx.log("WARNING: skipping not parsable line \"" + line + "\"") |
425 else: | 431 else: |
426 jvmCfgLines += [line] | 432 jvmCfgLines += [line] |
427 | 433 |
428 assert defaultVM is not None, 'Could not find default VM in ' + jvmCfg | 434 assert defaultVM is not None, 'Could not find default VM in ' + jvmCfg |
429 if mx.get_os() != 'windows': | 435 chmodRecursive(jdk, JDK_UNIX_PERMISSIONS_DIR) |
430 chmodRecursive(jdk, JDK_UNIX_PERMISSIONS_DIR) | |
431 shutil.move(join(_vmLibDirInJdk(jdk), defaultVM), join(_vmLibDirInJdk(jdk), 'original')) | 436 shutil.move(join(_vmLibDirInJdk(jdk), defaultVM), join(_vmLibDirInJdk(jdk), 'original')) |
432 | |
433 | 437 |
434 with open(jvmCfg, 'w') as fp: | 438 with open(jvmCfg, 'w') as fp: |
435 for line in jvmCfgLines: | 439 for line in jvmCfgLines: |
436 fp.write(line) | 440 fp.write(line) |
437 | 441 |
523 if exists(join(p.output_dir(), mainClass.replace('.', os.sep) + '.class')): | 527 if exists(join(p.output_dir(), mainClass.replace('.', os.sep) + '.class')): |
524 genSrcDir = _makeHotspotGeneratedSourcesDir() | 528 genSrcDir = _makeHotspotGeneratedSourcesDir() |
525 graalRuntime_inline_hpp = join(genSrcDir, 'graalRuntime.inline.hpp') | 529 graalRuntime_inline_hpp = join(genSrcDir, 'graalRuntime.inline.hpp') |
526 cp = os.pathsep.join([mx.distribution(d).path for d in dist.distDependencies] + [dist.path, p.output_dir()]) | 530 cp = os.pathsep.join([mx.distribution(d).path for d in dist.distDependencies] + [dist.path, p.output_dir()]) |
527 tmp = StringIO.StringIO() | 531 tmp = StringIO.StringIO() |
528 mx.run_java(['-cp', cp, mainClass], out=tmp.write) | 532 mx.run_java(['-cp', mx._tspU2W(cp), mainClass], out=tmp.write) |
529 | 533 |
530 # Compute SHA1 for currently generated graalRuntime.inline.hpp content | 534 # Compute SHA1 for currently generated graalRuntime.inline.hpp content |
531 # and all other generated sources in genSrcDir | 535 # and all other generated sources in genSrcDir |
532 d = hashlib.sha1() | 536 d = hashlib.sha1() |
533 d.update(tmp.getvalue()) | 537 d.update(tmp.getvalue()) |
546 # Store SHA1 in generated Java class and append class to specified jar | 550 # Store SHA1 in generated Java class and append class to specified jar |
547 javaSource = join(_graal_home, 'GeneratedSourcesSha1.java') | 551 javaSource = join(_graal_home, 'GeneratedSourcesSha1.java') |
548 javaClass = join(_graal_home, 'GeneratedSourcesSha1.class') | 552 javaClass = join(_graal_home, 'GeneratedSourcesSha1.class') |
549 with open(javaSource, 'w') as fp: | 553 with open(javaSource, 'w') as fp: |
550 print >> fp, 'class GeneratedSourcesSha1 { private static final String value = "' + sha1 + '"; }' | 554 print >> fp, 'class GeneratedSourcesSha1 { private static final String value = "' + sha1 + '"; }' |
551 subprocess.check_call([mx.java().javac, '-d', _graal_home, javaSource], stderr=subprocess.PIPE, stdout=subprocess.PIPE) | 555 subprocess.check_call([mx.java().javac, '-d', mx._tpU2W(_graal_home), mx._tpU2W(javaSource)], stderr=subprocess.PIPE, stdout=subprocess.PIPE) |
552 zf = zipfile.ZipFile(dist.path, 'a') | 556 zf = zipfile.ZipFile(dist.path, 'a') |
553 with open(javaClass, 'rb') as fp: | 557 with open(javaClass, 'rb') as fp: |
554 zf.writestr(os.path.basename(javaClass), fp.read()) | 558 zf.writestr(os.path.basename(javaClass), fp.read()) |
555 zf.close() | 559 zf.close() |
556 os.unlink(javaSource) | 560 os.unlink(javaSource) |
605 startToken = 'RUNINDEBUGSHELL_STARTSEQUENCE' | 609 startToken = 'RUNINDEBUGSHELL_STARTSEQUENCE' |
606 endToken = 'RUNINDEBUGSHELL_ENDSEQUENCE' | 610 endToken = 'RUNINDEBUGSHELL_ENDSEQUENCE' |
607 | 611 |
608 winSDK = mx.get_env('WIN_SDK', 'C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\') | 612 winSDK = mx.get_env('WIN_SDK', 'C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\') |
609 | 613 |
610 if not exists(winSDK): | 614 if not exists(mx._tpW2U(winSDK)): |
611 mx.abort("Could not find Windows SDK : '" + winSDK + "' does not exist") | 615 mx.abort("Could not find Windows SDK : '" + winSDK + "' does not exist") |
612 | 616 |
613 if not exists(join(winSDK, 'Bin', 'SetEnv.cmd')): | 617 winSDKSetEnv = mx._tpW2U(join(winSDK, 'Bin', 'SetEnv.cmd')) |
618 if not exists(winSDKSetEnv): | |
614 mx.abort("Invalid Windows SDK path (" + winSDK + ") : could not find Bin/SetEnv.cmd (you can use the WIN_SDK environment variable to specify an other path)") | 619 mx.abort("Invalid Windows SDK path (" + winSDK + ") : could not find Bin/SetEnv.cmd (you can use the WIN_SDK environment variable to specify an other path)") |
615 | 620 |
616 p = subprocess.Popen('cmd.exe /E:ON /V:ON /K ""' + winSDK + '/Bin/SetEnv.cmd" & echo ' + startToken + '"', \ | 621 wincmd = 'cmd.exe /E:ON /V:ON /K "' + mx._tpU2W(winSDKSetEnv) + '"' |
617 shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP) | 622 p = subprocess.Popen(wincmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
618 stdout = p.stdout | 623 stdout = p.stdout |
619 stdin = p.stdin | 624 stdin = p.stdin |
620 if logFile: | 625 if logFile: |
621 log = open(logFile, 'w') | 626 log = open(logFile, 'w') |
622 ret = False | 627 ret = False |
628 | |
629 def _writeProcess(s): | |
630 stdin.write(s + newLine) | |
631 | |
632 _writeProcess("echo " + startToken) | |
623 while True: | 633 while True: |
624 | |
625 # encoding may be None on windows plattforms | 634 # encoding may be None on windows plattforms |
626 if sys.stdout.encoding is None: | 635 if sys.stdout.encoding is None: |
627 encoding = 'utf-8' | 636 encoding = 'utf-8' |
628 else: | 637 else: |
629 encoding = sys.stdout.encoding | 638 encoding = sys.stdout.encoding |
632 if logFile: | 641 if logFile: |
633 log.write(line.encode('utf-8')) | 642 log.write(line.encode('utf-8')) |
634 line = line.strip() | 643 line = line.strip() |
635 mx.log(line) | 644 mx.log(line) |
636 if line == startToken: | 645 if line == startToken: |
637 stdin.write('cd /D ' + workingDir + ' & ' + cmd + ' & echo ' + endToken + newLine) | 646 _writeProcess('cd /D ' + workingDir + ' & ' + cmd + ' & echo ' + endToken) |
638 for regex in respondTo.keys(): | 647 for regex in respondTo.keys(): |
639 match = regex.search(line) | 648 match = regex.search(line) |
640 if match: | 649 if match: |
641 stdin.write(respondTo[regex] + newLine) | 650 _writeProcess(respondTo[regex]) |
642 if findInOutput: | 651 if findInOutput: |
643 match = findInOutput.search(line) | 652 match = findInOutput.search(line) |
644 if match: | 653 if match: |
645 ret = True | 654 ret = True |
646 if line == endToken: | 655 if line == endToken: |
647 if not findInOutput: | 656 if not findInOutput: |
648 stdin.write('echo ERRXXX%errorlevel%' + newLine) | 657 _writeProcess('echo ERRXXX%errorlevel%') |
649 else: | 658 else: |
650 break | 659 break |
651 if line.startswith('ERRXXX'): | 660 if line.startswith('ERRXXX'): |
652 if line == 'ERRXXX0': | 661 if line == 'ERRXXX0': |
653 ret = True | 662 ret = True |
654 break | 663 break |
655 stdin.write('exit' + newLine) | 664 _writeProcess("exit") |
656 if logFile: | 665 if logFile: |
657 log.close() | 666 log.close() |
658 return ret | 667 return ret |
659 | 668 |
660 def jdkhome(vm=None): | 669 def jdkhome(vm=None): |
804 mx.log('The ' + vm + ' VM is not supported on this platform - skipping') | 813 mx.log('The ' + vm + ' VM is not supported on this platform - skipping') |
805 continue | 814 continue |
806 | 815 |
807 vmDir = join(_vmLibDirInJdk(jdk), vm) | 816 vmDir = join(_vmLibDirInJdk(jdk), vm) |
808 if not exists(vmDir): | 817 if not exists(vmDir): |
809 if mx.get_os() != 'windows': | 818 chmodRecursive(jdk, JDK_UNIX_PERMISSIONS_DIR) |
810 chmodRecursive(jdk, JDK_UNIX_PERMISSIONS_DIR) | |
811 mx.log('Creating VM directory in JDK: ' + vmDir) | 819 mx.log('Creating VM directory in JDK: ' + vmDir) |
812 os.makedirs(vmDir) | 820 os.makedirs(vmDir) |
813 | 821 |
814 def filterXusage(line): | 822 def filterXusage(line): |
815 if not 'Xusage.txt' in line: | 823 if not 'Xusage.txt' in line: |
836 | 844 |
837 if not mustBuild: | 845 if not mustBuild: |
838 mx.logv('[all files in src and make directories are older than ' + timestampFile[len(_graal_home) + 1:] + ' - skipping native build]') | 846 mx.logv('[all files in src and make directories are older than ' + timestampFile[len(_graal_home) + 1:] + ' - skipping native build]') |
839 continue | 847 continue |
840 | 848 |
841 if platform.system() == 'Windows': | 849 if platform.system() == 'Windows' or "CYGWIN" in platform.system(): |
842 compilelogfile = _graal_home + '/graalCompile.log' | 850 t_compilelogfile = mx._tpU2W(os.path.join(_graal_home, "graalCompile.log")) |
843 mksHome = mx.get_env('MKS_HOME', 'C:\\cygwin\\bin') | 851 mksHome = mx.get_env('MKS_HOME', 'C:\\cygwin\\bin') |
844 | 852 |
845 variant = {'client': 'compiler1', 'server': 'compiler2'}.get(vm, vm) | 853 variant = {'client': 'compiler1', 'server': 'compiler2'}.get(vm, vm) |
846 project_config = variant + '_' + build | 854 project_config = variant + '_' + build |
847 _runInDebugShell('msbuild ' + _graal_home + r'\build\vs-amd64\jvm.vcproj /p:Configuration=' + project_config + ' /target:clean', _graal_home) | 855 t_graal_home = mx._tpU2W(_graal_home) |
848 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 | 856 _runInDebugShell('msbuild ' + t_graal_home + r'\build\vs-amd64\jvm.vcproj /p:Configuration=' + project_config + ' /target:clean', t_graal_home) |
857 winCompileCmd = r'set HotSpotMksHome=' + mksHome + r'& set OUT_DIR=' + mx._tpU2W(jdk) + r'& set JAVA_HOME=' + mx._tpU2W(jdk) + r'& set path=%JAVA_HOME%\bin;%path%;%HotSpotMksHome%& cd /D "' + t_graal_home + r'\make\windows"& call create.bat ' + t_graal_home | |
849 print winCompileCmd | 858 print winCompileCmd |
850 winCompileSuccess = re.compile(r"^Writing \.vcxproj file:") | 859 winCompileSuccess = re.compile(r"^Writing \.vcxproj file:") |
851 if not _runInDebugShell(winCompileCmd, _graal_home, compilelogfile, winCompileSuccess): | 860 if not _runInDebugShell(winCompileCmd, t_graal_home, t_compilelogfile, winCompileSuccess): |
852 mx.log('Error executing create command') | 861 mx.log('Error executing create command') |
853 return | 862 return |
854 winBuildCmd = 'msbuild ' + _graal_home + r'\build\vs-amd64\jvm.vcxproj /p:Configuration=' + project_config + ' /p:Platform=x64' | 863 winBuildCmd = 'msbuild ' + t_graal_home + r'\build\vs-amd64\jvm.vcxproj /p:Configuration=' + project_config + ' /p:Platform=x64' |
855 if not _runInDebugShell(winBuildCmd, _graal_home, compilelogfile): | 864 if not _runInDebugShell(winBuildCmd, t_graal_home, t_compilelogfile): |
856 mx.log('Error building project') | 865 mx.log('Error building project') |
857 return | 866 return |
858 else: | 867 else: |
859 cpus = multiprocessing.cpu_count() | 868 cpus = multiprocessing.cpu_count() |
860 makeDir = join(_graal_home, 'make') | 869 makeDir = join(_graal_home, 'make') |
1440 | 1449 |
1441 global _jacoco | 1450 global _jacoco |
1442 _jacoco = 'off' | 1451 _jacoco = 'off' |
1443 | 1452 |
1444 t = Task('CleanAndBuildIdealGraphVisualizer') | 1453 t = Task('CleanAndBuildIdealGraphVisualizer') |
1445 mx.run(['ant', '-f', join(_graal_home, 'src', 'share', 'tools', 'IdealGraphVisualizer', 'build.xml'), '-q', 'clean', 'build']) | 1454 buildxml = mx._tpU2W(join(_graal_home, 'src', 'share', 'tools', 'IdealGraphVisualizer', 'build.xml')) |
1455 mx.run(['ant', '-f', buildxml, '-q', 'clean', 'build']) | |
1446 tasks.append(t.stop()) | 1456 tasks.append(t.stop()) |
1447 | 1457 |
1448 # Prevent Graal modifications from breaking the standard builds | 1458 # Prevent Graal modifications from breaking the standard builds |
1449 if args.buildNonGraal: | 1459 if args.buildNonGraal: |
1450 t = Task('BuildHotSpotVarieties') | 1460 t = Task('BuildHotSpotVarieties') |
2233 finally: | 2243 finally: |
2234 shutil.rmtree(tmp) | 2244 shutil.rmtree(tmp) |
2235 findbugsJar = join(findbugsLib, 'findbugs.jar') | 2245 findbugsJar = join(findbugsLib, 'findbugs.jar') |
2236 assert exists(findbugsJar) | 2246 assert exists(findbugsJar) |
2237 nonTestProjects = [p for p in mx.projects() if not p.name.endswith('.test') and not p.name.endswith('.jtt')] | 2247 nonTestProjects = [p for p in mx.projects() if not p.name.endswith('.test') and not p.name.endswith('.jtt')] |
2238 outputDirs = [p.output_dir() for p in nonTestProjects] | 2248 outputDirs = map(mx._tpU2W, [p.output_dir() for p in nonTestProjects]) |
2239 findbugsResults = join(_graal_home, 'findbugs.results') | 2249 findbugsResults = join(_graal_home, 'findbugs.results') |
2240 | 2250 |
2241 cmd = ['-jar', findbugsJar, '-textui', '-low', '-maxRank', '15'] | 2251 cmd = ['-jar', mx._tpU2W(findbugsJar), '-textui', '-low', '-maxRank', '15'] |
2242 if sys.stdout.isatty(): | 2252 if sys.stdout.isatty(): |
2243 cmd.append('-progress') | 2253 cmd.append('-progress') |
2244 cmd = cmd + ['-auxclasspath', mx.classpath([d.name for d in _jdkDeployedDists] + [p.name for p in nonTestProjects]), '-output', findbugsResults, '-exitcode'] + args + outputDirs | 2254 cmd = cmd + ['-auxclasspath', mx.classpath([d.name for d in _jdkDeployedDists] + [p.name for p in nonTestProjects]), '-output', mx._tpU2W(findbugsResults), '-exitcode'] + args + outputDirs |
2245 exitcode = mx.run_java(cmd, nonZeroIsFatal=False) | 2255 exitcode = mx.run_java(cmd, nonZeroIsFatal=False) |
2246 if exitcode != 0: | 2256 if exitcode != 0: |
2247 with open(findbugsResults) as fp: | 2257 with open(findbugsResults) as fp: |
2248 mx.log(fp.read()) | 2258 mx.log(fp.read()) |
2249 os.unlink(findbugsResults) | 2259 os.unlink(findbugsResults) |