# HG changeset patch # User Christian Wimmer # Date 1349750772 25200 # Node ID f938212e56abbb34b3e12ea425983e7122b125be # Parent feb579677b58af44130a07d7ad4f004ecbedf0de Improvements of annotation processor functionality in mx script; allow javac to be run in debugger in order to debug annotation processor diff -r feb579677b58 -r f938212e56ab mxtool/mx.py --- a/mxtool/mx.py Mon Oct 08 19:34:32 2012 -0700 +++ b/mxtool/mx.py Mon Oct 08 19:46:12 2012 -0700 @@ -253,6 +253,14 @@ """ return [join(self.dir, s) for s in self.srcDirs] + def source_gen_dir(self): + """ + Get the directory in which source files generated by the annotation processor are found/placed. + """ + if self.native: + return None + return join(self.dir, 'src_gen') + def output_dir(self): """ Get the directory in which the class files of this project are found/placed. @@ -1255,6 +1263,7 @@ parser.add_argument('--source', dest='compliance', help='Java compliance level', default=str(javaCompliance)) parser.add_argument('--Wapi', action='store_true', dest='warnAPI', help='show warnings about using internal APIs') parser.add_argument('--projects', action='store', help='comma separated projects to build (omit to build all projects)') + parser.add_argument('--only', action='store', help='comma separated projects to build, without checking their dependencies (omit to build all projects)') parser.add_argument('--no-java', action='store_false', dest='java', help='do not build Java projects') parser.add_argument('--no-native', action='store_false', dest='native', help='do not build native projects') parser.add_argument('--jdt', help='Eclipse installation or path to ecj.jar for using the Eclipse batch compiler (default: ' + defaultEcjPath + ')', default=defaultEcjPath, metavar='') @@ -1284,7 +1293,12 @@ if args.projects is not None: projects = args.projects.split(',') - for p in sorted_deps(projects): + if args.only is not None: + sortedProjects = [project(name) for name in args.only.split(',')] + else: + sortedProjects = sorted_deps(projects) + + for p in sortedProjects: if p.native: if args.native: log('Calling GNU make {0}...'.format(p.dir)) @@ -1391,6 +1405,10 @@ argfile.write('\n'.join(javafilelist)) argfile.close() + javacArgs = [] + if java().debug_port is not None: + javacArgs += ['-J-Xdebug', '-J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=' + str(java().debug_port)] + if hasattr(p, 'annotationProcessors') and len(p.annotationProcessors) > 0: annotationProcessors = [] for apProject in p.annotationProcessors: @@ -1399,15 +1417,19 @@ abort("Project " + p + " specifies " + apProject + " as an annotation processor but " + apProject + " does not specifiy any annotation processor class") annotationProcessors += apClasses - apArgs = ['-processor', ",".join(annotationProcessors)] + genDir = p.source_gen_dir(); + if exists(genDir): + shutil.rmtree(genDir) + os.mkdir(genDir) + javacArgs += ['-processor', ",".join(annotationProcessors), "-s", genDir] else: - apArgs = [] + javacArgs += ['-proc:none'] toBeDeleted = [argfileName] try: if jdtJar is None: log('Compiling Java sources for {0} with javac...'.format(p.name)) - javacCmd = [java().javac, '-g', '-J-Xmx1g', '-source', args.compliance, '-classpath', cp, '-d', outputDir] + apArgs + ['@' + argfile.name] + javacCmd = [java().javac, '-g', '-J-Xmx1g', '-source', args.compliance, '-classpath', cp, '-d', outputDir] + javacArgs + ['@' + argfile.name] if not args.warnAPI: javacCmd.append('-XDignore.symbol.file') run(javacCmd) @@ -1416,7 +1438,7 @@ jdtArgs = [java().java, '-Xmx1g', '-jar', jdtJar, '-' + args.compliance, '-cp', cp, '-g', '-enableJavadoc', - '-d', outputDir] + apArgs + '-d', outputDir] + javacArgs jdtProperties = join(p.dir, '.settings', 'org.eclipse.jdt.core.prefs') if not exists(jdtProperties): # Try to fix a missing properties file by running eclipseinit @@ -1978,6 +2000,8 @@ with open(join(eclipseSettingsDir, name)) as f: content = f.read() content = content.replace('${javaCompliance}', str(p.javaCompliance)) + if hasattr(p, 'annotationProcessors') and len(p.annotationProcessors) > 0: + content = content.replace('org.eclipse.jdt.core.compiler.processAnnotations=disabled', 'org.eclipse.jdt.core.compiler.processAnnotations=enabled') update_file(join(settingsDir, name), content) if hasattr(p, 'annotationProcessors') and len(p.annotationProcessors) > 0: