changeset 4247:3f6c6e61614e

Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
author Doug Simon <doug.simon@oracle.com>
date Mon, 09 Jan 2012 14:12:53 +0100
parents b019b2ebe03e
children c580db4d6f6f
files mx/commands.py mxtool/mx.py
diffstat 2 files changed, 77 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/mx/commands.py	Sat Jan 07 16:05:07 2012 -0800
+++ b/mx/commands.py	Mon Jan 09 14:12:53 2012 +0100
@@ -40,7 +40,7 @@
 
 def clean(args):
     """cleans the GraalVM source tree"""
-    opts = mx.clean(args)
+    opts = mx.clean(args, parser=ArgumentParser(prog='mx clean'))
     if opts.native:
         os.environ.update(ARCH_DATA_MODEL='64', LANG='C', HOTSPOT_BUILD_JOBS='16')
         mx.run([mx.gmake_cmd(), 'clean'], cwd=join(_graal_home, 'make'))
@@ -585,7 +585,12 @@
                 if not test.test('-graal'):
                     t.abort(test.group + ' ' + test.name + ' Failed')
                 t.stop()
+    except KeyboardInterrupt:
+        total.abort(1)
+    
     except Exception as e:
+        import traceback
+        traceback.print_exc()
         total.abort(str(e))
 
     total.stop()
--- a/mxtool/mx.py	Sat Jan 07 16:05:07 2012 -0800
+++ b/mxtool/mx.py	Mon Jan 09 14:12:53 2012 +0100
@@ -45,12 +45,9 @@
 #   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. 
+#   includes    - Other suites to be loaded. This is recursive. 
 #   env         - A set of environment variable definitions.
 #
-# 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 file-system paths.
 #
@@ -902,13 +899,20 @@
                 if dep.name in built:
                     mustBuild = True
             
+        javafilelist = []
+        nonjavafilelistdst = []
         for sourceDir in sourceDirs:
-            javafilelist = []
-            nonjavafilelist = []
             for root, _, files in os.walk(sourceDir):
                 javafiles = [join(root, name) for name in files if name.endswith('.java') and name != 'package-info.java']
                 javafilelist += javafiles
-                nonjavafilelist += [join(root, name) for name in files if not name.endswith('.java')]
+                
+                # Copy all non Java resources
+                nonjavafilelist = [join(root, name) for name in files if not name.endswith('.java')]
+                for src in nonjavafilelist:
+                    dst = join(outputDir, src[len(sourceDir) + 1:])
+                    if exists(dirname(dst)) and (not exists(dst) or os.path.getmtime(dst) != os.path.getmtime(src)):
+                        shutil.copyfile(src, dst)
+                
                 if not mustBuild:
                     for javafile in javafiles:
                         classfile = outputDir + javafile[len(sourceDir):-len('java')] + 'class'
@@ -916,65 +920,62 @@
                             mustBuild = True
                             break
                 
-            if not mustBuild:
-                log('[all class files in {0} are up to date - skipping]'.format(sourceDir))
-                continue
-                
-            if len(javafilelist) == 0:
-                log('[no Java sources in {0} - skipping]'.format(sourceDir))
-                continue
-
-            built.add(p.name)
-
-            argfileName = join(p.dir, 'javafilelist.txt')
-            argfile = open(argfileName, 'wb')
-            argfile.write('\n'.join(javafilelist))
-            argfile.close()
+        if not mustBuild:
+            log('[all class files for {0} are up to date - skipping]'.format(p.name))
+            continue
             
-            try:
-                if jdtJar is None:
-                    log('Compiling Java sources in {0} with javac...'.format(sourceDir))
-                    errFilt = None
-                    if not args.warnAPI:
-                        class Filter:
-                            """
-                            Class to errFilt the 'is Sun proprietary API and may be removed in a future release'
-                            warning when compiling the VM classes.
-                            
-                            """
-                            def __init__(self):
-                                self.c = 0
-                            
-                            def eat(self, line):
-                                if 'proprietary API' in line:
-                                    self.c = 2
-                                elif self.c != 0:
-                                    self.c -= 1
-                                else:
-                                    log(line.rstrip())
-                        errFilt=Filter().eat
+        if len(javafilelist) == 0:
+            log('[no Java sources for {0} - skipping]'.format(p.name))
+            continue
+
+        built.add(p.name)
+
+        argfileName = join(p.dir, 'javafilelist.txt')
+        argfile = open(argfileName, 'wb')
+        argfile.write('\n'.join(javafilelist))
+        argfile.close()
+        
+        try:
+            if jdtJar is None:
+                log('Compiling Java sources for {0} with javac...'.format(p.name))
+                errFilt = None
+                if not args.warnAPI:
+                    class Filter:
+                        """
+                        Class to errFilt the 'is Sun proprietary API and may be removed in a future release'
+                        warning when compiling the VM classes.
+                        
+                        """
+                        def __init__(self):
+                            self.c = 0
                         
-                    run([java().javac, '-g', '-J-Xmx1g', '-source', args.compliance, '-classpath', cp, '-d', outputDir, '@' + argfile.name], err=errFilt)
-                else:
-                    log('Compiling Java sources in {0} with JDT...'.format(sourceDir))
-                    jdtProperties = join(p.dir, '.settings', 'org.eclipse.jdt.core.prefs')
-                    if not exists(jdtProperties):
-                        raise SystemError('JDT properties file {0} not found'.format(jdtProperties))
-                    run([java().java, '-Xmx1g', '-jar', jdtJar,
-                             '-properties', jdtProperties,
-                             '-' + args.compliance,
-                             '-cp', cp, '-g',
-                             '-warn:-unusedImport,-unchecked',
-                             '-d', outputDir, '@' + argfile.name])
-            finally:
-                os.remove(argfileName)
-                        
-                
-            for name in nonjavafilelist:
-                dst = join(outputDir, name[len(sourceDir) + 1:])
-                if exists(dirname(dst)):
-                    shutil.copyfile(name, dst)
-    return args
+                        def eat(self, line):
+                            if 'proprietary API' in line:
+                                self.c = 2
+                            elif self.c != 0:
+                                self.c -= 1
+                            else:
+                                log(line.rstrip())
+                    errFilt=Filter().eat
+                    
+                run([java().javac, '-g', '-J-Xmx1g', '-source', args.compliance, '-classpath', cp, '-d', outputDir, '@' + argfile.name], err=errFilt)
+            else:
+                log('Compiling Java sources for {0} with JDT...'.format(p.name))
+                jdtProperties = join(p.dir, '.settings', 'org.eclipse.jdt.core.prefs')
+                if not exists(jdtProperties):
+                    raise SystemError('JDT properties file {0} not found'.format(jdtProperties))
+                run([java().java, '-Xmx1g', '-jar', jdtJar,
+                         '-properties', jdtProperties,
+                         '-' + args.compliance,
+                         '-cp', cp, '-g',
+                         '-warn:-unusedImport,-unchecked',
+                         '-d', outputDir, '@' + argfile.name])
+        finally:
+            os.remove(argfileName)
+                    
+    if suppliedParser:
+        return args
+    return None
 
 def canonicalizeprojects(args):
     """process all project files to canonicalize the dependencies
@@ -1122,8 +1123,10 @@
     Removes all files created by a build, including Java class files, executables, and
     generated images.
     """
+
+    suppliedParser = parser is not None
     
-    parser = parser if parser is not None else ArgumentParser(prog='mx build');
+    parser = parser if suppliedParser else ArgumentParser(prog='mx build');
     parser.add_argument('--no-native', action='store_false', dest='native', help='do not clean native projects')
     parser.add_argument('--no-java', action='store_false', dest='java', help='do not clean Java projects')
 
@@ -1139,7 +1142,9 @@
                 if outputDir != '' and exists(outputDir):
                     log('Removing {0}...'.format(outputDir))
                     shutil.rmtree(outputDir)
-    return args
+                    
+    if suppliedParser:
+        return args
     
 def help_(args):
     """show help for a given command
@@ -1219,13 +1224,6 @@
 _argParser = ArgParser()
 
 def main():
-    MX_INCLUDES = os.environ.get('MX_INCLUDES', None)
-    if MX_INCLUDES is not None:
-        for path in MX_INCLUDES.split(os.pathsep):
-            d = join(path, 'mx')
-            if exists(d) and isdir(d):
-                _loadSuite(path)
-                
     cwdMxDir = join(os.getcwd(), 'mx')
     if exists(cwdMxDir) and isdir(cwdMxDir):
         _loadSuite(os.getcwd(), True)