changeset 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 ee1b82e8c1f4
children 97d280a879ff
files mx/commands.py
diffstat 1 files changed, 13 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mx/commands.py	Fri Jun 28 17:33:44 2013 +0200
+++ b/mx/commands.py	Fri Jun 28 19:11:47 2013 +0200
@@ -33,6 +33,7 @@
 import sanitycheck
 import json, textwrap
 
+# This works because when mx loads this file, it makes sure __file__ gets an absolute path
 _graal_home = dirname(dirname(__file__))
 
 """ Used to distinguish an exported GraalVM (see 'mx export'). """
@@ -268,22 +269,20 @@
     return join(_vmLibDirInJdk(jdk), 'jvm.cfg')
 
 def _jdksDir():
-    if _vmdir:
-        return _vmdir
-    return join(_graal_home, 'jdk' + str(mx.java().version))
+    return os.path.abspath(_vmdir if _vmdir else join(_graal_home, 'jdk' + str(mx.java().version)))
 
-def _jdk(build='product', vmToCheck=None, create=False):
+def _jdk(build='product', vmToCheck=None, create=False, installGraalJar=True):
     """
     Get the JDK into which Graal is installed, creating it first if necessary.
     """
     jdk = join(_jdksDir(), build)
-    srcJdk = mx.java().jdk
-    jdkContents = ['bin', 'include', 'jre', 'lib']
-    if exists(join(srcJdk, 'db')):
-        jdkContents.append('db')
-    if mx.get_os() != 'windows' and exists(join(srcJdk, 'man')):
-        jdkContents.append('man')
     if create:
+        srcJdk = mx.java().jdk
+        jdkContents = ['bin', 'include', 'jre', 'lib']
+        if exists(join(srcJdk, 'db')):
+            jdkContents.append('db')
+        if mx.get_os() != 'windows' and exists(join(srcJdk, 'man')):
+            jdkContents.append('man')
         if not exists(jdk):
             mx.log('Creating ' + jdk + ' from ' + srcJdk)
             os.makedirs(jdk)
@@ -334,7 +333,8 @@
             vmOption = ' --vm ' + vmToCheck if vmToCheck else ''
             mx.abort('The ' + build + ' VM has not been created - run "mx' + vmOption + ' build ' + build + '"')
             
-    _installGraalJarInJdks(mx.distribution('GRAAL'))
+    if installGraalJar:
+        _installGraalJarInJdks(mx.distribution('GRAAL'))
     
     if vmToCheck is not None:
         jvmCfg = _vmCfgInJdk(jdk)
@@ -352,7 +352,7 @@
 def _installGraalJarInJdks(graalDist):
     graalJar = graalDist.path
     graalOptions = join(_graal_home, 'graal.options')
-    jdks = join(_graal_home, 'jdk' + str(mx.java().version))
+    jdks = _jdksDir()
     if exists(jdks):
         for e in os.listdir(jdks):
             jreLibDir = join(jdks, e, 'jre', 'lib')
@@ -428,7 +428,7 @@
     """print the JDK directory selected for the 'vm' command"""
 
     build = _vmbuild if _vmSourcesAvailable else 'product'
-    print join(_graal_home, 'jdk' + str(mx.java().version), build)
+    print _jdk(build, installGraalJar=False)
 
 def buildvars(args):
     """Describes the variables that can be set by the -D option to the 'mx build' commmand"""