Mercurial > hg > graal-jvmci-8
diff mxtool/mx.py @ 21522:28cbfacd0518
Merge
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Thu, 28 May 2015 17:44:05 +0200 |
parents | b426469fadb7 12e3d0dfffeb |
children | 60154926b513 |
line wrap: on
line diff
--- a/mxtool/mx.py Thu May 28 16:54:14 2015 +0200 +++ b/mxtool/mx.py Thu May 28 17:44:05 2015 +0200 @@ -622,7 +622,7 @@ if not exists(cachePath) or sha1OfFile(cachePath) != sha1: if exists(cachePath): - log('SHA1 of ' + cachePath + ' does not match expected value (' + sha1 + ') - re-downloading') + log('SHA1 of ' + cachePath + ' does not match expected value (' + sha1 + ') - found ' + sha1OfFile(cachePath) + ' - re-downloading') print 'Downloading ' + ("sources " if sources else "") + name + ' from ' + str(urls) download(cachePath, urls) @@ -1019,6 +1019,7 @@ p = Project(self, name, srcDirs, deps, javaCompliance, workingSets, d) p.checkstyleProj = attrs.pop('checkstyle', name) p.native = attrs.pop('native', '') == 'true' + p.checkPackagePrefix = attrs.pop('checkPackagePrefix', 'true') == 'true' if not p.native and p.javaCompliance is None: abort('javaCompliance property required for non-native project ' + name) if len(ap) > 0: @@ -2317,15 +2318,8 @@ def _init_classpaths(self): if not self._classpaths_initialized: - myDir = dirname(__file__) - outDir = join(dirname(__file__), '.jdk' + str(self.version)) - if not exists(outDir): - os.makedirs(outDir) - javaSource = join(myDir, 'ClasspathDump.java') - javaClass = join(outDir, 'ClasspathDump.class') - if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): - subprocess.check_call([self.javac, '-d', _cygpathU2W(outDir), _cygpathU2W(javaSource)], stderr=subprocess.PIPE, stdout=subprocess.PIPE) - self._bootclasspath, self._extdirs, self._endorseddirs = [x if x != 'null' else None for x in subprocess.check_output([self.java, '-cp', _cygpathU2W(outDir), 'ClasspathDump'], stderr=subprocess.PIPE).split('|')] + _, binDir = _compile_mx_class('ClasspathDump', jdk=self) + self._bootclasspath, self._extdirs, self._endorseddirs = [x if x != 'null' else None for x in subprocess.check_output([self.java, '-cp', _cygpathU2W(binDir), 'ClasspathDump'], stderr=subprocess.PIPE).split('|')] if self.javaCompliance <= JavaCompliance('1.8'): # All 3 system properties accessed by ClasspathDump are expected to exist if not self._bootclasspath or not self._extdirs or not self._endorseddirs: @@ -2536,15 +2530,12 @@ assert not path.endswith(os.sep) - myDir = dirname(__file__) - javaSource = join(myDir, 'URLConnectionDownload.java') - javaClass = join(myDir, 'URLConnectionDownload.class') - if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): - subprocess.check_call([java().javac, '-d', _cygpathU2W(myDir), _cygpathU2W(javaSource)]) + _, binDir = _compile_mx_class('URLConnectionDownload') + verbose = [] if sys.stderr.isatty(): verbose.append("-v") - if run([java().java, '-cp', _cygpathU2W(myDir), 'URLConnectionDownload', _cygpathU2W(path)] + verbose + urls, nonZeroIsFatal=False) == 0: + if run([java().java, '-cp', _cygpathU2W(binDir), 'URLConnectionDownload', _cygpathU2W(path)] + verbose + urls, nonZeroIsFatal=False) == 0: return abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' + @@ -2768,7 +2759,7 @@ # N.B. Limiting to a suite only affects the starting set of projects. Dependencies in other suites will still be compiled sortedProjects = sorted_project_deps(projects, includeAnnotationProcessors=True) - if args.java: + if args.java and jdtJar: ideinit([], refreshOnly=True, buildProcessorJars=False) tasks = {} @@ -2946,7 +2937,7 @@ log('Compiling {0} failed'.format(t.proj.name)) abort('{0} Java compilation tasks failed'.format(len(failed))) - if args.java: + if args.java and not args.only: files = [] for dist in sorted_dists(): if dist not in updatedAnnotationProcessorDists: @@ -3355,9 +3346,10 @@ nonCanonical = [] for s in suites(True): for p in s.projects: - for pkg in p.defined_java_packages(): - if not pkg.startswith(p.name): - abort('package in {0} does not have prefix matching project name: {1}'.format(p, pkg)) + if p.checkPackagePrefix: + for pkg in p.defined_java_packages(): + if not pkg.startswith(p.name): + abort('package in {0} does not have prefix matching project name: {1}'.format(p, pkg)) ignoredDeps = set([name for name in p.deps if project(name, False) is not None]) for pkg in p.imported_java_packages(): @@ -3451,7 +3443,7 @@ config = join(project(p.checkstyleProj).dir, '.checkstyle_checks.xml') if not exists(config): - logv('[No Checkstyle configuration foudn for {0} - skipping]'.format(p)) + logv('[No Checkstyle configuration found for {0} - skipping]'.format(p)) continue # skip checking this Java project if its Java compliance level is "higher" than the configured JDK @@ -4157,8 +4149,8 @@ launchOut.open('launchConfiguration', {'type' : 'org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType'}) launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.core.capture_output', 'value': consoleOn}) launchOut.open('mapAttribute', {'key' : 'org.eclipse.debug.core.environmentVariables'}) - launchOut.element('mapEntry', {'key' : 'JAVA_HOME', 'value' : _opts.java_home}) - launchOut.element('mapEntry', {'key' : 'EXTRA_JAVA_HOMES', 'value' : _opts.extra_java_homes}) + launchOut.element('mapEntry', {'key' : 'JAVA_HOME', 'value' : _default_java_home.jdk}) + launchOut.element('mapEntry', {'key' : 'EXTRA_JAVA_HOMES', 'value' : os.pathsep.join([extraJavaHome.jdk for extraJavaHome in _extra_java_homes])}) launchOut.close('mapAttribute') if refresh: @@ -4431,14 +4423,19 @@ out.close('condition') out.close('target') - out.open('target', {'name' : '-post-compile'}) + out.open('target', {'name' : 'compile'}) out.open('exec', {'executable' : sys.executable}) out.element('env', {'key' : 'JAVA_HOME', 'value' : jdk.jdk}) out.element('arg', {'value' : os.path.abspath(__file__)}) - out.element('arg', {'value' : 'archive'}) - out.element('arg', {'value' : '@GRAAL'}) + out.element('arg', {'value' : 'build'}) + out.element('arg', {'value' : '--only'}) + out.element('arg', {'value' : p.name}) + out.element('arg', {'value' : '--force-javac'}) + out.element('arg', {'value' : '--no-native'}) out.close('exec') out.close('target') + out.open('target', {'name' : 'jar', 'depends' : 'compile'}) + out.close('target') out.close('project') update_file(join(p.dir, 'build.xml'), out.xml(indent='\t', newl='\n')) if files: @@ -5437,6 +5434,65 @@ _show_section('projects', s.projects) _show_section('distributions', s.dists) +def _compile_mx_class(javaClassName, classpath=None, jdk=None): + myDir = dirname(__file__) + binDir = join(myDir, 'bin' if not jdk else '.jdk' + str(jdk.version)) + javaSource = join(myDir, javaClassName + '.java') + javaClass = join(binDir, javaClassName + '.class') + if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): + if not exists(binDir): + os.mkdir(binDir) + javac = jdk.javac if jdk else java().javac + cmd = [javac, '-d', _cygpathU2W(binDir)] + if classpath: + cmd += ['-cp', _separatedCygpathU2W(binDir + os.pathsep + classpath)] + cmd += [_cygpathU2W(javaSource)] + try: + subprocess.check_call(cmd) + except subprocess.CalledProcessError: + abort('failed to compile:' + javaSource) + + return (myDir, binDir) + +def checkcopyrights(args): + '''run copyright check on the sources''' + class CP(ArgumentParser): + def format_help(self): + return ArgumentParser.format_help(self) + self._get_program_help() + + def _get_program_help(self): + help_output = subprocess.check_output([java().java, '-cp', _cygpathU2W(binDir), 'CheckCopyright', '--help']) + return '\nother argumemnts preceded with --\n' + help_output + + myDir, binDir = _compile_mx_class('CheckCopyright') + + parser = CP(prog='mx checkcopyrights') + + parser.add_argument('--primary', action='store_true', help='limit checks to primary suite') + parser.add_argument('remainder', nargs=REMAINDER, metavar='...') + args = parser.parse_args(args) + remove_doubledash(args.remainder) + + + # ensure compiled form of code is up to date + + result = 0 + # copyright checking is suite specific as each suite may have different overrides + for s in suites(True): + if args.primary and not s.primary: + continue + custom_copyrights = _cygpathU2W(join(s.mxDir, 'copyrights')) + custom_args = [] + if exists(custom_copyrights): + custom_args = ['--custom-copyright-dir', custom_copyrights] + rc = run([java().java, '-cp', _cygpathU2W(binDir), 'CheckCopyright', '--copyright-dir', _cygpathU2W(myDir)] + custom_args + args.remainder, cwd=s.dir, nonZeroIsFatal=False) + result = result if rc == 0 else rc + return result + +def remove_doubledash(args): + if '--' in args: + args.remove('--') + def ask_yes_no(question, default=None): """""" assert not default or default == 'y' or default == 'n' @@ -5480,6 +5536,7 @@ 'build': [build, '[options]'], 'checkstyle': [checkstyle, ''], 'canonicalizeprojects': [canonicalizeprojects, ''], + 'checkcopyrights': [checkcopyrights, '[options]'], 'clean': [clean, ''], 'eclipseinit': [eclipseinit, ''], 'eclipseformat': [eclipseformat, ''],