Mercurial > hg > graal-compiler
comparison mx/commands.py @ 4269:ffd5ce8fc736
Moved IDE project configuration into mx.py.
Added capability for generating NetBeans project configurations.
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 11 Jan 2012 15:14:45 +0100 |
parents | 32b8274f52ad |
children | f8f262212aa4 |
comparison
equal
deleted
inserted
replaced
4258:8d2c14f722ac | 4269:ffd5ce8fc736 |
---|---|
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, platform, subprocess | 29 import os, sys, shutil, zipfile, tempfile, re, time, datetime, platform, subprocess |
30 from os.path import join, exists, dirname, isdir, isabs, basename | 30 from os.path import join, exists, dirname, basename |
31 from argparse import ArgumentParser, REMAINDER | 31 from argparse import ArgumentParser, REMAINDER |
32 import mx | 32 import mx |
33 import sanitycheck | 33 import sanitycheck |
34 | 34 |
35 _graal_home = dirname(dirname(__file__)) | 35 _graal_home = dirname(dirname(__file__)) |
241 | 241 |
242 winSDK = mx.get_env('WIN_SDK', 'C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\') | 242 winSDK = mx.get_env('WIN_SDK', 'C:\\Program Files\\Microsoft SDKs\\Windows\\v7.1\\') |
243 | 243 |
244 p = subprocess.Popen('cmd.exe /E:ON /V:ON /K ""' + winSDK + '/Bin/SetEnv.cmd" & echo ' + STARTTOKEN + '"', \ | 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, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP) | 245 shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, creationflags=subprocess.CREATE_NEW_PROCESS_GROUP) |
246 output = p.stdout | 246 stdout = p.stdout |
247 input = p.stdin | 247 stdin = p.stdin |
248 if logFile: | 248 if logFile: |
249 log = open(logFile, 'w') | 249 log = open(logFile, 'w') |
250 ret = False | 250 ret = False |
251 while True: | 251 while True: |
252 line = output.readline().decode() | 252 line = stdout.readline().decode() |
253 if logFile: | 253 if logFile: |
254 log.write(line) | 254 log.write(line) |
255 line = line.strip() | 255 line = line.strip() |
256 mx.log(line) | 256 mx.log(line) |
257 if line == STARTTOKEN: | 257 if line == STARTTOKEN: |
258 input.write('cd /D ' + workingDir + ' & ' + cmd + ' & echo ' + ENDTOKEN + newLine) | 258 stdin.write('cd /D ' + workingDir + ' & ' + cmd + ' & echo ' + ENDTOKEN + newLine) |
259 for regex in respondTo.keys(): | 259 for regex in respondTo.keys(): |
260 match = regex.search(line) | 260 match = regex.search(line) |
261 if match: | 261 if match: |
262 input.write(respondTo[regex] + newLine) | 262 stdin.write(respondTo[regex] + newLine) |
263 if findInOutput: | 263 if findInOutput: |
264 match = findInOutput.search(line) | 264 match = findInOutput.search(line) |
265 if match: | 265 if match: |
266 ret = True | 266 ret = True |
267 if line == ENDTOKEN: | 267 if line == ENDTOKEN: |
268 break | 268 break |
269 input.write('exit' + newLine) | 269 stdin.write('exit' + newLine) |
270 if logFile: | 270 if logFile: |
271 log.close() | 271 log.close() |
272 return ret | 272 return ret |
273 | 273 |
274 def build(args): | 274 def build(args): |
336 if mx.java().debug: | 336 if mx.java().debug: |
337 args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args | 337 args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args |
338 exe = join(_jdk(build), 'bin', mx.exe_suffix('java')) | 338 exe = join(_jdk(build), 'bin', mx.exe_suffix('java')) |
339 return mx.run([exe, vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout) | 339 return mx.run([exe, vm] + args, nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd, timeout=timeout) |
340 | 340 |
341 def ideinit(args): | |
342 """(re)generate Eclipse project configurations""" | |
343 | |
344 | |
345 def println(out, obj): | |
346 out.write(str(obj) + '\n') | |
347 | |
348 for p in mx.projects(): | |
349 if p.native: | |
350 continue | |
351 | |
352 if not exists(p.dir): | |
353 os.makedirs(p.dir) | |
354 | |
355 out = StringIO.StringIO() | |
356 | |
357 println(out, '<?xml version="1.0" encoding="UTF-8"?>') | |
358 println(out, '<classpath>') | |
359 for src in p.srcDirs: | |
360 srcDir = join(p.dir, src) | |
361 if not exists(srcDir): | |
362 os.mkdir(srcDir) | |
363 println(out, '\t<classpathentry kind="src" path="' + src + '"/>') | |
364 | |
365 # Every Java program depends on the JRE | |
366 println(out, '\t<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>') | |
367 | |
368 for dep in p.all_deps([], True): | |
369 if dep == p: | |
370 continue; | |
371 | |
372 if dep.isLibrary(): | |
373 if hasattr(dep, 'eclipse.container'): | |
374 println(out, '\t<classpathentry exported="true" kind="con" path="' + getattr(dep, 'eclipse.container') + '"/>') | |
375 elif hasattr(dep, 'eclipse.project'): | |
376 println(out, '\t<classpathentry combineaccessrules="false" exported="true" kind="src" path="/' + getattr(dep, 'eclipse.project') + '"/>') | |
377 else: | |
378 path = dep.path | |
379 if dep.mustExist: | |
380 dep.get_path(resolve=True) | |
381 if isabs(path): | |
382 println(out, '\t<classpathentry exported="true" kind="lib" path="' + path + '"/>') | |
383 else: | |
384 println(out, '\t<classpathentry exported="true" kind="lib" path="' + join(_graal_home, path) + '"/>') | |
385 else: | |
386 println(out, '\t<classpathentry combineaccessrules="false" exported="true" kind="src" path="/' + dep.name + '"/>') | |
387 | |
388 println(out, '\t<classpathentry kind="output" path="' + getattr(p, 'eclipse.output', 'bin') + '"/>') | |
389 println(out, '</classpath>') | |
390 mx.update_file(join(p.dir, '.classpath'), out.getvalue()) | |
391 out.close() | |
392 | |
393 csConfig = join(mx.project(p.checkstyleProj).dir, '.checkstyle_checks.xml') | |
394 if exists(csConfig): | |
395 out = StringIO.StringIO() | |
396 | |
397 dotCheckstyle = join(p.dir, ".checkstyle") | |
398 checkstyleConfigPath = '/' + p.checkstyleProj + '/.checkstyle_checks.xml' | |
399 println(out, '<?xml version="1.0" encoding="UTF-8"?>') | |
400 println(out, '<fileset-config file-format-version="1.2.0" simple-config="true">') | |
401 println(out, '\t<local-check-config name="Graal Checks" location="' + checkstyleConfigPath + '" type="project" description="">') | |
402 println(out, '\t\t<additional-data name="protect-config-file" value="false"/>') | |
403 println(out, '\t</local-check-config>') | |
404 println(out, '\t<fileset name="all" enabled="true" check-config-name="Graal Checks" local="true">') | |
405 println(out, '\t\t<file-match-pattern match-pattern="." include-pattern="true"/>') | |
406 println(out, '\t</fileset>') | |
407 println(out, '\t<filter name="FileTypesFilter" enabled="true">') | |
408 println(out, '\t\t<filter-data value="java"/>') | |
409 println(out, '\t</filter>') | |
410 | |
411 exclude = join(p.dir, '.checkstyle.exclude') | |
412 if exists(exclude): | |
413 println(out, '\t<filter name="FilesFromPackage" enabled="true">') | |
414 with open(exclude) as f: | |
415 for line in f: | |
416 if not line.startswith('#'): | |
417 line = line.strip() | |
418 exclDir = join(p.dir, line) | |
419 assert isdir(exclDir), 'excluded source directory listed in ' + exclude + ' does not exist or is not a directory: ' + exclDir | |
420 println(out, '\t\t<filter-data value="' + line + '"/>') | |
421 println(out, '\t</filter>') | |
422 | |
423 println(out, '</fileset-config>') | |
424 mx.update_file(dotCheckstyle, out.getvalue()) | |
425 out.close() | |
426 | |
427 | |
428 out = StringIO.StringIO() | |
429 | |
430 println(out, '<?xml version="1.0" encoding="UTF-8"?>') | |
431 println(out, '<projectDescription>') | |
432 println(out, '\t<name>' + p.name + '</name>') | |
433 println(out, '\t<comment></comment>') | |
434 println(out, '\t<projects>') | |
435 println(out, '\t</projects>') | |
436 println(out, '\t<buildSpec>') | |
437 println(out, '\t\t<buildCommand>') | |
438 println(out, '\t\t\t<name>org.eclipse.jdt.core.javabuilder</name>') | |
439 println(out, '\t\t\t<arguments>') | |
440 println(out, '\t\t\t</arguments>') | |
441 println(out, '\t\t</buildCommand>') | |
442 if exists(csConfig): | |
443 println(out, '\t\t<buildCommand>') | |
444 println(out, '\t\t\t<name>net.sf.eclipsecs.core.CheckstyleBuilder</name>') | |
445 println(out, '\t\t\t<arguments>') | |
446 println(out, '\t\t\t</arguments>') | |
447 println(out, '\t\t</buildCommand>') | |
448 println(out, '\t</buildSpec>') | |
449 println(out, '\t<natures>') | |
450 println(out, '\t\t<nature>org.eclipse.jdt.core.javanature</nature>') | |
451 if exists(csConfig): | |
452 println(out, '\t\t<nature>net.sf.eclipsecs.core.CheckstyleNature</nature>') | |
453 println(out, '\t</natures>') | |
454 println(out, '</projectDescription>') | |
455 mx.update_file(join(p.dir, '.project'), out.getvalue()) | |
456 out.close() | |
457 | |
458 out = StringIO.StringIO() | |
459 settingsDir = join(p.dir, ".settings") | |
460 if not exists(settingsDir): | |
461 os.mkdir(settingsDir) | |
462 | |
463 myDir = dirname(__file__) | |
464 | |
465 with open(join(myDir, 'org.eclipse.jdt.core.prefs')) as f: | |
466 content = f.read() | |
467 mx.update_file(join(settingsDir, 'org.eclipse.jdt.core.prefs'), content) | |
468 | |
469 with open(join(myDir, 'org.eclipse.jdt.ui.prefs')) as f: | |
470 content = f.read() | |
471 mx.update_file(join(settingsDir, 'org.eclipse.jdt.ui.prefs'), content) | |
472 | 341 |
473 # Table of unit tests. | 342 # Table of unit tests. |
474 # Keys are project names, values are package name lists. | 343 # Keys are project names, values are package name lists. |
475 # All source files in the given (project,package) pairs are scanned for lines | 344 # All source files in the given (project,package) pairs are scanned for lines |
476 # containing '@Test'. These are then detemrined to be the classes defining | 345 # containing '@Test'. These are then detemrined to be the classes defining |
630 'specjvm2008': [specjvm2008, ''], | 499 'specjvm2008': [specjvm2008, ''], |
631 'example': [example, '[-v] example names...'], | 500 'example': [example, '[-v] example names...'], |
632 'gate' : [gate, ''], | 501 'gate' : [gate, ''], |
633 'bench' : [bench, ''], | 502 'bench' : [bench, ''], |
634 'unittest' : [unittest, '[filters...]'], | 503 'unittest' : [unittest, '[filters...]'], |
635 'vm': [vm, '[-options] class [args...]'], | 504 'vm': [vm, '[-options] class [args...]'] |
636 'ideinit': [ideinit, ''] | |
637 } | 505 } |
638 | 506 |
639 if (_vmSourcesAvailable): | 507 if (_vmSourcesAvailable): |
640 mx.add_argument('--product', action='store_const', dest='vmbuild', const='product', help='select the product VM') | 508 mx.add_argument('--product', action='store_const', dest='vmbuild', const='product', help='select the product VM') |
641 mx.add_argument('--debug', action='store_const', dest='vmbuild', const='debug', help='select the debug VM') | 509 mx.add_argument('--debug', action='store_const', dest='vmbuild', const='debug', help='select the debug VM') |