Mercurial > hg > truffle
comparison mx/commands.py @ 10574:0cad5096735e
commands.py: Make sure _jdk returns an absolute path. Use _jdk and _jdksDir where necessary
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Fri, 28 Jun 2013 19:11:47 +0200 |
parents | 2f80624df8a2 |
children | a6c0ae38e05e |
comparison
equal
deleted
inserted
replaced
10573:ee1b82e8c1f4 | 10574:0cad5096735e |
---|---|
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 import json, textwrap | 34 import json, textwrap |
35 | 35 |
36 # This works because when mx loads this file, it makes sure __file__ gets an absolute path | |
36 _graal_home = dirname(dirname(__file__)) | 37 _graal_home = dirname(dirname(__file__)) |
37 | 38 |
38 """ Used to distinguish an exported GraalVM (see 'mx export'). """ | 39 """ Used to distinguish an exported GraalVM (see 'mx export'). """ |
39 _vmSourcesAvailable = exists(join(_graal_home, 'make')) and exists(join(_graal_home, 'src')) | 40 _vmSourcesAvailable = exists(join(_graal_home, 'make')) and exists(join(_graal_home, 'src')) |
40 | 41 |
266 if platform.system() == 'Windows': | 267 if platform.system() == 'Windows': |
267 return join(jdk, 'jre', 'lib', _arch(), 'jvm.cfg') | 268 return join(jdk, 'jre', 'lib', _arch(), 'jvm.cfg') |
268 return join(_vmLibDirInJdk(jdk), 'jvm.cfg') | 269 return join(_vmLibDirInJdk(jdk), 'jvm.cfg') |
269 | 270 |
270 def _jdksDir(): | 271 def _jdksDir(): |
271 if _vmdir: | 272 return os.path.abspath(_vmdir if _vmdir else join(_graal_home, 'jdk' + str(mx.java().version))) |
272 return _vmdir | 273 |
273 return join(_graal_home, 'jdk' + str(mx.java().version)) | 274 def _jdk(build='product', vmToCheck=None, create=False, installGraalJar=True): |
274 | |
275 def _jdk(build='product', vmToCheck=None, create=False): | |
276 """ | 275 """ |
277 Get the JDK into which Graal is installed, creating it first if necessary. | 276 Get the JDK into which Graal is installed, creating it first if necessary. |
278 """ | 277 """ |
279 jdk = join(_jdksDir(), build) | 278 jdk = join(_jdksDir(), build) |
280 srcJdk = mx.java().jdk | |
281 jdkContents = ['bin', 'include', 'jre', 'lib'] | |
282 if exists(join(srcJdk, 'db')): | |
283 jdkContents.append('db') | |
284 if mx.get_os() != 'windows' and exists(join(srcJdk, 'man')): | |
285 jdkContents.append('man') | |
286 if create: | 279 if create: |
280 srcJdk = mx.java().jdk | |
281 jdkContents = ['bin', 'include', 'jre', 'lib'] | |
282 if exists(join(srcJdk, 'db')): | |
283 jdkContents.append('db') | |
284 if mx.get_os() != 'windows' and exists(join(srcJdk, 'man')): | |
285 jdkContents.append('man') | |
287 if not exists(jdk): | 286 if not exists(jdk): |
288 mx.log('Creating ' + jdk + ' from ' + srcJdk) | 287 mx.log('Creating ' + jdk + ' from ' + srcJdk) |
289 os.makedirs(jdk) | 288 os.makedirs(jdk) |
290 for d in jdkContents: | 289 for d in jdkContents: |
291 src = join(srcJdk, d) | 290 src = join(srcJdk, d) |
332 else: | 331 else: |
333 if not exists(jdk): | 332 if not exists(jdk): |
334 vmOption = ' --vm ' + vmToCheck if vmToCheck else '' | 333 vmOption = ' --vm ' + vmToCheck if vmToCheck else '' |
335 mx.abort('The ' + build + ' VM has not been created - run "mx' + vmOption + ' build ' + build + '"') | 334 mx.abort('The ' + build + ' VM has not been created - run "mx' + vmOption + ' build ' + build + '"') |
336 | 335 |
337 _installGraalJarInJdks(mx.distribution('GRAAL')) | 336 if installGraalJar: |
337 _installGraalJarInJdks(mx.distribution('GRAAL')) | |
338 | 338 |
339 if vmToCheck is not None: | 339 if vmToCheck is not None: |
340 jvmCfg = _vmCfgInJdk(jdk) | 340 jvmCfg = _vmCfgInJdk(jdk) |
341 found = False | 341 found = False |
342 with open(jvmCfg) as f: | 342 with open(jvmCfg) as f: |
350 return jdk | 350 return jdk |
351 | 351 |
352 def _installGraalJarInJdks(graalDist): | 352 def _installGraalJarInJdks(graalDist): |
353 graalJar = graalDist.path | 353 graalJar = graalDist.path |
354 graalOptions = join(_graal_home, 'graal.options') | 354 graalOptions = join(_graal_home, 'graal.options') |
355 jdks = join(_graal_home, 'jdk' + str(mx.java().version)) | 355 jdks = _jdksDir() |
356 if exists(jdks): | 356 if exists(jdks): |
357 for e in os.listdir(jdks): | 357 for e in os.listdir(jdks): |
358 jreLibDir = join(jdks, e, 'jre', 'lib') | 358 jreLibDir = join(jdks, e, 'jre', 'lib') |
359 if exists(jreLibDir): | 359 if exists(jreLibDir): |
360 # do a copy and then a move to get atomic updating (on Unix) of graal.jar in the JRE | 360 # do a copy and then a move to get atomic updating (on Unix) of graal.jar in the JRE |
426 | 426 |
427 def jdkhome(args, vm=None): | 427 def jdkhome(args, vm=None): |
428 """print the JDK directory selected for the 'vm' command""" | 428 """print the JDK directory selected for the 'vm' command""" |
429 | 429 |
430 build = _vmbuild if _vmSourcesAvailable else 'product' | 430 build = _vmbuild if _vmSourcesAvailable else 'product' |
431 print join(_graal_home, 'jdk' + str(mx.java().version), build) | 431 print _jdk(build, installGraalJar=False) |
432 | 432 |
433 def buildvars(args): | 433 def buildvars(args): |
434 """Describes the variables that can be set by the -D option to the 'mx build' commmand""" | 434 """Describes the variables that can be set by the -D option to the 'mx build' commmand""" |
435 | 435 |
436 buildVars = { | 436 buildVars = { |