changeset 4145:9aee7df31417

Removed 'tests' command. Folded 'make' command into 'build' command. Renamed 'eclipseprojects' command to 'ideinit'
author Doug Simon <doug.simon@oracle.com>
date Mon, 19 Dec 2011 20:56:59 +0100
parents 34527a24bcf8
children 4eb5b2469b6f
files .hgignore mx/commands.py mxtool/mx.py
diffstat 3 files changed, 76 insertions(+), 107 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon Dec 19 18:31:09 2011 +0100
+++ b/.hgignore	Mon Dec 19 20:56:59 2011 +0100
@@ -4,7 +4,7 @@
 ^dist/
 ^java/
 ^lib/
-^jdk1.7.0/`
+^jdk1.7.0/
 ^java64/
 ^work/
 \.checkstyle$
--- a/mx/commands.py	Mon Dec 19 18:31:09 2011 +0100
+++ b/mx/commands.py	Mon Dec 19 20:56:59 2011 +0100
@@ -122,37 +122,12 @@
         config = benchmarks.get(bm)
         vm(vmOpts + ['Harness'] + config + [bm])
     
-def tests(args):
-    """run a selection of the Maxine JTT tests in Graal"""
-    
-    maxine = mx.check_get_env('MAXINE_HOME')
-    def jtt(name):
-        return join(maxine, 'com.oracle.max.vm', 'test', 'jtt', name)
-    
-    return vm(['-ea', '-esa', '-Xcomp', '-XX:+PrintCompilation', '-XX:CompileOnly=jtt'] + args +
-                       ['-Xbootclasspath/p:' + join(maxine, 'com.oracle.max.vm', 'bin'), 
-                        '-Xbootclasspath/p:' + join(maxine, 'com.oracle.max.base', 'bin'),
-                        'test.com.sun.max.vm.compiler.JavaTester',
-                        '-verbose=1', '-gen-run-scheme=false', '-run-scheme-package=all',
-                        jtt('bytecode'),
-                        jtt('except'), 
-                        jtt('jdk'), 
-                        jtt('hotpath'), 
-                        jtt('jdk'), 
-                        jtt('lang'), 
-                        jtt('loop'), 
-                        jtt('micro'), 
-                        jtt('optimize'), 
-                        jtt('reflect'), 
-                        jtt('threads'), 
-                        jtt('hotspot')])
-
-
 def _download_and_extract_targz_jdk7(url, dst):
     assert url.endswith('.tar.gz')
     dl = join(_graal_home, 'jdk7.tar.gz')
     try:
         if not exists(dl):
+            mx.log('Downloading ' + url)
             mx.download(dl, [url])
         tmp = join(_graal_home, 'tmp')
         if not exists(tmp):
@@ -172,7 +147,7 @@
 def _jdk7(build='product', create=False):
     jdk7 = os.environ.get('JDK7')
     if jdk7 is None:
-        jdk7 = join(_graal_home, 'jdk7')
+        jdk7 = join(_graal_home, 'jdk1.7.0')
         if not exists(jdk7):
             # Try to download it
             if mx.get_os() == 'linux':
@@ -200,11 +175,13 @@
     else:
         mx.abort('Unknown build type: ' + build)
     
-def make(args):
-    """builds the GraalVM binary
+def build(args):
+    """builds the GraalVM binary and compiles the Graal classes
     
     The optional argument specifies what type of VM to build."""
 
+    mx.build([])
+
     def fix_jvm_cfg(jdk):
         jvmCfg = join(jdk, 'jre', 'lib', 'amd64', 'jvm.cfg')
         found = False
@@ -243,14 +220,14 @@
 def vm(args, vm='-graal'):
     """run the GraalVM"""
   
-    build = mx.vmbuild
-    if mx.java_dbg:
+    build = _vmbuild
+    if mx.java().debug:
         args = ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] + args
-    os.environ['GRAAL'] = join(mx.check_get_env('GRAAL_HOME'), 'graal')
+    os.environ['GRAAL'] = join(_graal_home, 'graal')
     exe = join(_jdk7(build), 'bin', mx.exe_suffix('java'))
     return mx.run([exe, vm] + args)
 
-def eclipseprojects(args):
+def ideinit(args):
     """(re)generate Eclipse project configurations
 
     The exit code of this command reflects how many files were updated."""
@@ -407,13 +384,12 @@
     mx.add_argument('--fastdebug', action='store_const', dest='vmbuild', const='fastdebug', help='select the fast debug VM')
     mx.add_argument('--optimized', action='store_const', dest='vmbuild', const='optimized', help='select the optimized VM')
     commands = {
+        'build': [build, '[product|debug|fastdebug|optimized]'],
         'dacapo': [dacapo, '[benchmark] [VM options]'],
         'example': [example, '[-v] example names...'],
         'clean': [clean, ''],
-        'make': [make, '[product|debug|fastdebug|optimized]'],
-        'tests': [tests, ''],
         'vm': [vm, '[-options] class [args...]'],
-	    'eclipseprojects': [eclipseprojects, ''],
+	    'ideinit': [ideinit, ''],
     }
     mx.commands.update(commands)
 
--- a/mxtool/mx.py	Mon Dec 19 18:31:09 2011 +0100
+++ b/mxtool/mx.py	Mon Dec 19 20:56:59 2011 +0100
@@ -31,29 +31,31 @@
 # as well as making it simple to run commands
 # (like hg is the interface to the Mercurial commands).
 #
-# When launched, mx looks for a mx configuration (i.e. a directory named 'mx') 
-# in the current working directory. This is the primary mx configuration. Any
-# other mx configurations are included mx configurations.
+# The organizing principle of mx is a project suite. A suite is a directory
+# containing one or more projects. It's not coincidental that this closely
+# matches the layout of one or more projects in a Mercurial repository.
+# The configuration information for a suite lives in an 'mx' sub-directory
+# at the top level of the suite. 
 #
-# If an mx configuration exists, then the following files in the configuration
-# are processed (if they exist):
+# When launched, mx treats the current working directory as a suite.
+# This is the primary suite. All other suites are called included suites.
+#
+# The configuration files (i.e. in the 'mx' sub-directory) of a suite are:
 #
-#   projects    - Lists projects, libraries and dependencies between them
-#   commands.py - Extensions to the commands launchable by mx. This is only processed
-#                 for the primary mx configuration.
-#   includes    - Other directories containing mx configurations to be loaded.
-#                 This is a recursive action. 
+#   projects    - Defines the projects and libraries in the suite and the dependencies between them
+#   commands.py - Suite specific extensions to the commands available to mx. This is only processed
+#                 for the primary suite.
+#   includes    - Other suites to be loaded. This is a recursive. 
 #   env         - A set of environment variable definitions.
 #
-# The MX_INCLUDES environment variable can also be used to specify
-# other directories containing mx configurations.
+# The MX_INCLUDES environment variable can also be used to specify other suites.
 # This value of this variable has the same format as a Java class path.
 #
 # The includes and env files are typically not put under version control
-# as they usually contain local filesystem paths.
+# as they usually contain local file-system paths.
 #
 # The projects file is like the pom.xml file from Maven except that
-# it is in a properties file format instead of XML. Each non-comment line
+# it is a properties file (not XML). Each non-comment line
 # in the file specifies an attribute of a project or library. The main 
 # difference between a project and a library is that the former contains
 # source code built by the mx tool where as the latter is an external
@@ -105,11 +107,7 @@
 _projects = dict()
 _libs = dict()
 _suites = dict()
-
-""" Options parsed from the command line. """
 _opts = None
-
-""" Prefix for a Java command. """
 _java = None
 
 """
@@ -145,6 +143,10 @@
         self.dir = dir
         
     def all_deps(self, deps, includeLibs):
+        """
+        Add the transitive set of dependencies for this project, including
+        libraries if 'includeLibs' is true, to the 'deps' list.
+        """
         if self in deps:
             return deps
         for name in self.deps:
@@ -191,13 +193,13 @@
 
     def source_dirs(self):
         """
-        Get the directories in whihc the sources of this project are found.
+        Get the directories in which the sources of this project are found.
         """
         return [join(self.dir, s) for s in self.srcDirs]
         
     def output_dir(self):
         """
-        Get the directory in which the class files of this project are found.
+        Get the directory in which the class files of this project are found/placed.
         """
         if self.native:
             return None
@@ -340,6 +342,9 @@
             self._load_commands(mxDir)
         
 def get_os():
+    """
+    Get a canonical form of sys.platform.
+    """
     if sys.platform.startswith('darwin'):
         return 'darwin'
     elif sys.platform.startswith('linux'):
@@ -498,22 +503,15 @@
         msg += ' {0:<20} {1}\n'.format(cmd, doc.split('\n', 1)[0])
     return msg + '\n'
 
-def java_home():
-    return _opts.java_home
-
-def java_exe():
-    return exe_suffix(_opts.java)
+def java():
+    """
+    Get a JavaConfig object containing Java commands launch details.
+    """
+    assert _java is not None
+    return _java
 
-def java_args():
-    init_java()
-    return _opts.java_args
-
-def format_java_cmd(args):
-    init_java()
-    return _java + args
-    
 def run_java(args, nonZeroIsFatal=True, out=None, err=None, cwd=None):
-    return run(format_java_cmd(args), nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd)
+    return run(_java.format_cmd(args), nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd)
 
 def run(args, nonZeroIsFatal=True, out=None, err=None, cwd=None):
     """
@@ -571,46 +569,40 @@
         return name + '.exe'
     return name
 
-def init_java():
-    """
-    Lazy initialization and preprocessing of this object's fields before running a Java command.
-    """
-    global _java
-    if _java is not None:
-        return
+"""
+A JavaConfig object encapsulates info on how Java commands are run.
+"""
+class JavaConfig:
+    def __init__(self, opts):
+        self.jdk = opts.java_home
+        self.debug = opts.java_dbg
+        self.java =  exe_suffix(join(self.jdk, 'bin', 'java'))
+        self.javac = exe_suffix(join(self.jdk, 'bin', 'javac'))
+        self.javap = exe_suffix(join(self.jdk, 'bin', 'javap'))
 
-    def delAtAndSplit(s):
-        return shlex.split(s.lstrip('@'))
-
-    _opts.java_args = delAtAndSplit(_opts.java_args)
-    _opts.java_args_pfx = sum(map(delAtAndSplit, _opts.java_args_pfx), [])
-    _opts.java_args_sfx = sum(map(delAtAndSplit, _opts.java_args_sfx), [])
-    
-    # Prepend the -d64 VM option only if the java command supports it
-    output = ''
-    java = _opts.java
-    try:
+        def delAtAndSplit(s):
+            return shlex.split(s.lstrip('@'))
         
-        output = subprocess.check_output([java, '-d64', '-version'], stderr=subprocess.STDOUT)
-        _opts.java_args = ['-d64'] + _opts.java_args
-    except subprocess.CalledProcessError as e:
+        self.java_args = delAtAndSplit(_opts.java_args)
+        self.java_args_pfx = sum(map(delAtAndSplit, _opts.java_args_pfx), [])
+        self.java_args_sfx = sum(map(delAtAndSplit, _opts.java_args_sfx), [])
+        
+        # Prepend the -d64 VM option only if the java command supports it
         try:
-            output = subprocess.check_output([java, '-version'], stderr=subprocess.STDOUT)
+            subprocess.check_output([self.java, '-d64', '-version'], stderr=subprocess.STDOUT)
+            self.java_args = ['-d64'] + self.java_args
         except subprocess.CalledProcessError as e:
-            print e.output
-            abort(e.returncode)
+            try:
+                subprocess.check_output([self.java, '-version'], stderr=subprocess.STDOUT)
+            except subprocess.CalledProcessError as e:
+                print e.output
+                abort(e.returncode)
+        
+        if self.debug:
+            self.java_args += ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000']
 
-    output = output.split()
-    assert output[0] == 'java' or output[0] == 'openjdk'
-    assert output[1] == 'version'
-    version = output[2]
-    if not version.startswith('"1.6') and not version.startswith('"1.7'):
-        abort('Requires Java version 1.6 or 1.7, got version ' + version)
-
-    if _opts.java_dbg:
-        _opts.java_args += ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000']
-        
-    _java = [java] + _opts.java_args_pfx + _opts.java_args + _opts.java_args_sfx 
+    def format_cmd(self, args):
+        return [self.java] + self.java_args_pfx + self.java_args + self.java_args_sfx + args
     
 def _default_java_home():
     javaHome = os.getenv('JAVA_HOME')
@@ -1135,8 +1127,9 @@
         _loadSuite(os.getcwd(), True)
             
     opts, commandAndArgs = _argParser._parse_cmd_line()
-    global _opts
+    global _opts, _java
     _opts = opts
+    _java = JavaConfig(opts)
     
     if len(commandAndArgs) == 0:
         _argParser.print_help()