Mercurial > hg > graal-jvmci-8
comparison 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 |
comparison
equal
deleted
inserted
replaced
21521:107300758a4e | 21522:28cbfacd0518 |
---|---|
620 base = basename(path) | 620 base = basename(path) |
621 cachePath = join(cacheDir, base + '_' + sha1) | 621 cachePath = join(cacheDir, base + '_' + sha1) |
622 | 622 |
623 if not exists(cachePath) or sha1OfFile(cachePath) != sha1: | 623 if not exists(cachePath) or sha1OfFile(cachePath) != sha1: |
624 if exists(cachePath): | 624 if exists(cachePath): |
625 log('SHA1 of ' + cachePath + ' does not match expected value (' + sha1 + ') - re-downloading') | 625 log('SHA1 of ' + cachePath + ' does not match expected value (' + sha1 + ') - found ' + sha1OfFile(cachePath) + ' - re-downloading') |
626 print 'Downloading ' + ("sources " if sources else "") + name + ' from ' + str(urls) | 626 print 'Downloading ' + ("sources " if sources else "") + name + ' from ' + str(urls) |
627 download(cachePath, urls) | 627 download(cachePath, urls) |
628 | 628 |
629 d = dirname(path) | 629 d = dirname(path) |
630 if d != '' and not exists(d): | 630 if d != '' and not exists(d): |
1017 d = join(self.dir, subDir, name) | 1017 d = join(self.dir, subDir, name) |
1018 workingSets = attrs.pop('workingSets', None) | 1018 workingSets = attrs.pop('workingSets', None) |
1019 p = Project(self, name, srcDirs, deps, javaCompliance, workingSets, d) | 1019 p = Project(self, name, srcDirs, deps, javaCompliance, workingSets, d) |
1020 p.checkstyleProj = attrs.pop('checkstyle', name) | 1020 p.checkstyleProj = attrs.pop('checkstyle', name) |
1021 p.native = attrs.pop('native', '') == 'true' | 1021 p.native = attrs.pop('native', '') == 'true' |
1022 p.checkPackagePrefix = attrs.pop('checkPackagePrefix', 'true') == 'true' | |
1022 if not p.native and p.javaCompliance is None: | 1023 if not p.native and p.javaCompliance is None: |
1023 abort('javaCompliance property required for non-native project ' + name) | 1024 abort('javaCompliance property required for non-native project ' + name) |
1024 if len(ap) > 0: | 1025 if len(ap) > 0: |
1025 p._declaredAnnotationProcessors = ap | 1026 p._declaredAnnotationProcessors = ap |
1026 p.__dict__.update(attrs) | 1027 p.__dict__.update(attrs) |
2315 if _opts.java_dbg_port is not None: | 2316 if _opts.java_dbg_port is not None: |
2316 self.java_args += ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=' + str(_opts.java_dbg_port)] | 2317 self.java_args += ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=' + str(_opts.java_dbg_port)] |
2317 | 2318 |
2318 def _init_classpaths(self): | 2319 def _init_classpaths(self): |
2319 if not self._classpaths_initialized: | 2320 if not self._classpaths_initialized: |
2320 myDir = dirname(__file__) | 2321 _, binDir = _compile_mx_class('ClasspathDump', jdk=self) |
2321 outDir = join(dirname(__file__), '.jdk' + str(self.version)) | 2322 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('|')] |
2322 if not exists(outDir): | |
2323 os.makedirs(outDir) | |
2324 javaSource = join(myDir, 'ClasspathDump.java') | |
2325 javaClass = join(outDir, 'ClasspathDump.class') | |
2326 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): | |
2327 subprocess.check_call([self.javac, '-d', _cygpathU2W(outDir), _cygpathU2W(javaSource)], stderr=subprocess.PIPE, stdout=subprocess.PIPE) | |
2328 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('|')] | |
2329 if self.javaCompliance <= JavaCompliance('1.8'): | 2323 if self.javaCompliance <= JavaCompliance('1.8'): |
2330 # All 3 system properties accessed by ClasspathDump are expected to exist | 2324 # All 3 system properties accessed by ClasspathDump are expected to exist |
2331 if not self._bootclasspath or not self._extdirs or not self._endorseddirs: | 2325 if not self._bootclasspath or not self._extdirs or not self._endorseddirs: |
2332 warn("Could not find all classpaths: boot='" + str(self._bootclasspath) + "' extdirs='" + str(self._extdirs) + "' endorseddirs='" + str(self._endorseddirs) + "'") | 2326 warn("Could not find all classpaths: boot='" + str(self._bootclasspath) + "' extdirs='" + str(self._extdirs) + "' endorseddirs='" + str(self._endorseddirs) + "'") |
2333 self._bootclasspath = _filter_non_existant_paths(self._bootclasspath) | 2327 self._bootclasspath = _filter_non_existant_paths(self._bootclasspath) |
2534 if d != '' and not exists(d): | 2528 if d != '' and not exists(d): |
2535 os.makedirs(d) | 2529 os.makedirs(d) |
2536 | 2530 |
2537 assert not path.endswith(os.sep) | 2531 assert not path.endswith(os.sep) |
2538 | 2532 |
2539 myDir = dirname(__file__) | 2533 _, binDir = _compile_mx_class('URLConnectionDownload') |
2540 javaSource = join(myDir, 'URLConnectionDownload.java') | 2534 |
2541 javaClass = join(myDir, 'URLConnectionDownload.class') | |
2542 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): | |
2543 subprocess.check_call([java().javac, '-d', _cygpathU2W(myDir), _cygpathU2W(javaSource)]) | |
2544 verbose = [] | 2535 verbose = [] |
2545 if sys.stderr.isatty(): | 2536 if sys.stderr.isatty(): |
2546 verbose.append("-v") | 2537 verbose.append("-v") |
2547 if run([java().java, '-cp', _cygpathU2W(myDir), 'URLConnectionDownload', _cygpathU2W(path)] + verbose + urls, nonZeroIsFatal=False) == 0: | 2538 if run([java().java, '-cp', _cygpathU2W(binDir), 'URLConnectionDownload', _cygpathU2W(path)] + verbose + urls, nonZeroIsFatal=False) == 0: |
2548 return | 2539 return |
2549 | 2540 |
2550 abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' + | 2541 abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' + |
2551 '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually') | 2542 '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually') |
2552 | 2543 |
2766 | 2757 |
2767 projects = _projects_opt_limit_to_suites(projects_from_names(projectNames)) | 2758 projects = _projects_opt_limit_to_suites(projects_from_names(projectNames)) |
2768 # N.B. Limiting to a suite only affects the starting set of projects. Dependencies in other suites will still be compiled | 2759 # N.B. Limiting to a suite only affects the starting set of projects. Dependencies in other suites will still be compiled |
2769 sortedProjects = sorted_project_deps(projects, includeAnnotationProcessors=True) | 2760 sortedProjects = sorted_project_deps(projects, includeAnnotationProcessors=True) |
2770 | 2761 |
2771 if args.java: | 2762 if args.java and jdtJar: |
2772 ideinit([], refreshOnly=True, buildProcessorJars=False) | 2763 ideinit([], refreshOnly=True, buildProcessorJars=False) |
2773 | 2764 |
2774 tasks = {} | 2765 tasks = {} |
2775 updatedAnnotationProcessorDists = set() | 2766 updatedAnnotationProcessorDists = set() |
2776 for p in sortedProjects: | 2767 for p in sortedProjects: |
2944 if len(failed): | 2935 if len(failed): |
2945 for t in failed: | 2936 for t in failed: |
2946 log('Compiling {0} failed'.format(t.proj.name)) | 2937 log('Compiling {0} failed'.format(t.proj.name)) |
2947 abort('{0} Java compilation tasks failed'.format(len(failed))) | 2938 abort('{0} Java compilation tasks failed'.format(len(failed))) |
2948 | 2939 |
2949 if args.java: | 2940 if args.java and not args.only: |
2950 files = [] | 2941 files = [] |
2951 for dist in sorted_dists(): | 2942 for dist in sorted_dists(): |
2952 if dist not in updatedAnnotationProcessorDists: | 2943 if dist not in updatedAnnotationProcessorDists: |
2953 archive(['@' + dist.name]) | 2944 archive(['@' + dist.name]) |
2954 if args.check_distributions and not dist.isProcessorDistribution: | 2945 if args.check_distributions and not dist.isProcessorDistribution: |
3353 The exit code of this command reflects how many projects have non-canonical dependencies.""" | 3344 The exit code of this command reflects how many projects have non-canonical dependencies.""" |
3354 | 3345 |
3355 nonCanonical = [] | 3346 nonCanonical = [] |
3356 for s in suites(True): | 3347 for s in suites(True): |
3357 for p in s.projects: | 3348 for p in s.projects: |
3358 for pkg in p.defined_java_packages(): | 3349 if p.checkPackagePrefix: |
3359 if not pkg.startswith(p.name): | 3350 for pkg in p.defined_java_packages(): |
3360 abort('package in {0} does not have prefix matching project name: {1}'.format(p, pkg)) | 3351 if not pkg.startswith(p.name): |
3352 abort('package in {0} does not have prefix matching project name: {1}'.format(p, pkg)) | |
3361 | 3353 |
3362 ignoredDeps = set([name for name in p.deps if project(name, False) is not None]) | 3354 ignoredDeps = set([name for name in p.deps if project(name, False) is not None]) |
3363 for pkg in p.imported_java_packages(): | 3355 for pkg in p.imported_java_packages(): |
3364 for name in p.deps: | 3356 for name in p.deps: |
3365 dep = project(name, False) | 3357 dep = project(name, False) |
3449 continue | 3441 continue |
3450 sourceDirs = p.source_dirs() | 3442 sourceDirs = p.source_dirs() |
3451 | 3443 |
3452 config = join(project(p.checkstyleProj).dir, '.checkstyle_checks.xml') | 3444 config = join(project(p.checkstyleProj).dir, '.checkstyle_checks.xml') |
3453 if not exists(config): | 3445 if not exists(config): |
3454 logv('[No Checkstyle configuration foudn for {0} - skipping]'.format(p)) | 3446 logv('[No Checkstyle configuration found for {0} - skipping]'.format(p)) |
3455 continue | 3447 continue |
3456 | 3448 |
3457 # skip checking this Java project if its Java compliance level is "higher" than the configured JDK | 3449 # skip checking this Java project if its Java compliance level is "higher" than the configured JDK |
3458 jdk = java(p.javaCompliance) | 3450 jdk = java(p.javaCompliance) |
3459 assert jdk | 3451 assert jdk |
4155 launchOut = XMLDoc() | 4147 launchOut = XMLDoc() |
4156 consoleOn = 'true' if logToConsole else 'false' | 4148 consoleOn = 'true' if logToConsole else 'false' |
4157 launchOut.open('launchConfiguration', {'type' : 'org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType'}) | 4149 launchOut.open('launchConfiguration', {'type' : 'org.eclipse.ui.externaltools.ProgramBuilderLaunchConfigurationType'}) |
4158 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.core.capture_output', 'value': consoleOn}) | 4150 launchOut.element('booleanAttribute', {'key' : 'org.eclipse.debug.core.capture_output', 'value': consoleOn}) |
4159 launchOut.open('mapAttribute', {'key' : 'org.eclipse.debug.core.environmentVariables'}) | 4151 launchOut.open('mapAttribute', {'key' : 'org.eclipse.debug.core.environmentVariables'}) |
4160 launchOut.element('mapEntry', {'key' : 'JAVA_HOME', 'value' : _opts.java_home}) | 4152 launchOut.element('mapEntry', {'key' : 'JAVA_HOME', 'value' : _default_java_home.jdk}) |
4161 launchOut.element('mapEntry', {'key' : 'EXTRA_JAVA_HOMES', 'value' : _opts.extra_java_homes}) | 4153 launchOut.element('mapEntry', {'key' : 'EXTRA_JAVA_HOMES', 'value' : os.pathsep.join([extraJavaHome.jdk for extraJavaHome in _extra_java_homes])}) |
4162 launchOut.close('mapAttribute') | 4154 launchOut.close('mapAttribute') |
4163 | 4155 |
4164 if refresh: | 4156 if refresh: |
4165 if refreshFile is None: | 4157 if refreshFile is None: |
4166 refreshScope = '${project}' | 4158 refreshScope = '${project}' |
4429 out.open('condition', {'property' : 'no.deps'}) | 4421 out.open('condition', {'property' : 'no.deps'}) |
4430 out.element('equals', {'arg1' : '${no.dependencies}', 'arg2' : 'true'}) | 4422 out.element('equals', {'arg1' : '${no.dependencies}', 'arg2' : 'true'}) |
4431 out.close('condition') | 4423 out.close('condition') |
4432 | 4424 |
4433 out.close('target') | 4425 out.close('target') |
4434 out.open('target', {'name' : '-post-compile'}) | 4426 out.open('target', {'name' : 'compile'}) |
4435 out.open('exec', {'executable' : sys.executable}) | 4427 out.open('exec', {'executable' : sys.executable}) |
4436 out.element('env', {'key' : 'JAVA_HOME', 'value' : jdk.jdk}) | 4428 out.element('env', {'key' : 'JAVA_HOME', 'value' : jdk.jdk}) |
4437 out.element('arg', {'value' : os.path.abspath(__file__)}) | 4429 out.element('arg', {'value' : os.path.abspath(__file__)}) |
4438 out.element('arg', {'value' : 'archive'}) | 4430 out.element('arg', {'value' : 'build'}) |
4439 out.element('arg', {'value' : '@GRAAL'}) | 4431 out.element('arg', {'value' : '--only'}) |
4432 out.element('arg', {'value' : p.name}) | |
4433 out.element('arg', {'value' : '--force-javac'}) | |
4434 out.element('arg', {'value' : '--no-native'}) | |
4440 out.close('exec') | 4435 out.close('exec') |
4436 out.close('target') | |
4437 out.open('target', {'name' : 'jar', 'depends' : 'compile'}) | |
4441 out.close('target') | 4438 out.close('target') |
4442 out.close('project') | 4439 out.close('project') |
4443 update_file(join(p.dir, 'build.xml'), out.xml(indent='\t', newl='\n')) | 4440 update_file(join(p.dir, 'build.xml'), out.xml(indent='\t', newl='\n')) |
4444 if files: | 4441 if files: |
4445 files.append(join(p.dir, 'build.xml')) | 4442 files.append(join(p.dir, 'build.xml')) |
5435 _show_section('libraries', s.libs) | 5432 _show_section('libraries', s.libs) |
5436 _show_section('jrelibraries', s.jreLibs) | 5433 _show_section('jrelibraries', s.jreLibs) |
5437 _show_section('projects', s.projects) | 5434 _show_section('projects', s.projects) |
5438 _show_section('distributions', s.dists) | 5435 _show_section('distributions', s.dists) |
5439 | 5436 |
5437 def _compile_mx_class(javaClassName, classpath=None, jdk=None): | |
5438 myDir = dirname(__file__) | |
5439 binDir = join(myDir, 'bin' if not jdk else '.jdk' + str(jdk.version)) | |
5440 javaSource = join(myDir, javaClassName + '.java') | |
5441 javaClass = join(binDir, javaClassName + '.class') | |
5442 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): | |
5443 if not exists(binDir): | |
5444 os.mkdir(binDir) | |
5445 javac = jdk.javac if jdk else java().javac | |
5446 cmd = [javac, '-d', _cygpathU2W(binDir)] | |
5447 if classpath: | |
5448 cmd += ['-cp', _separatedCygpathU2W(binDir + os.pathsep + classpath)] | |
5449 cmd += [_cygpathU2W(javaSource)] | |
5450 try: | |
5451 subprocess.check_call(cmd) | |
5452 except subprocess.CalledProcessError: | |
5453 abort('failed to compile:' + javaSource) | |
5454 | |
5455 return (myDir, binDir) | |
5456 | |
5457 def checkcopyrights(args): | |
5458 '''run copyright check on the sources''' | |
5459 class CP(ArgumentParser): | |
5460 def format_help(self): | |
5461 return ArgumentParser.format_help(self) + self._get_program_help() | |
5462 | |
5463 def _get_program_help(self): | |
5464 help_output = subprocess.check_output([java().java, '-cp', _cygpathU2W(binDir), 'CheckCopyright', '--help']) | |
5465 return '\nother argumemnts preceded with --\n' + help_output | |
5466 | |
5467 myDir, binDir = _compile_mx_class('CheckCopyright') | |
5468 | |
5469 parser = CP(prog='mx checkcopyrights') | |
5470 | |
5471 parser.add_argument('--primary', action='store_true', help='limit checks to primary suite') | |
5472 parser.add_argument('remainder', nargs=REMAINDER, metavar='...') | |
5473 args = parser.parse_args(args) | |
5474 remove_doubledash(args.remainder) | |
5475 | |
5476 | |
5477 # ensure compiled form of code is up to date | |
5478 | |
5479 result = 0 | |
5480 # copyright checking is suite specific as each suite may have different overrides | |
5481 for s in suites(True): | |
5482 if args.primary and not s.primary: | |
5483 continue | |
5484 custom_copyrights = _cygpathU2W(join(s.mxDir, 'copyrights')) | |
5485 custom_args = [] | |
5486 if exists(custom_copyrights): | |
5487 custom_args = ['--custom-copyright-dir', custom_copyrights] | |
5488 rc = run([java().java, '-cp', _cygpathU2W(binDir), 'CheckCopyright', '--copyright-dir', _cygpathU2W(myDir)] + custom_args + args.remainder, cwd=s.dir, nonZeroIsFatal=False) | |
5489 result = result if rc == 0 else rc | |
5490 return result | |
5491 | |
5492 def remove_doubledash(args): | |
5493 if '--' in args: | |
5494 args.remove('--') | |
5495 | |
5440 def ask_yes_no(question, default=None): | 5496 def ask_yes_no(question, default=None): |
5441 """""" | 5497 """""" |
5442 assert not default or default == 'y' or default == 'n' | 5498 assert not default or default == 'y' or default == 'n' |
5443 if not is_interactive(): | 5499 if not is_interactive(): |
5444 if default: | 5500 if default: |
5478 _commands = { | 5534 _commands = { |
5479 'about': [about, ''], | 5535 'about': [about, ''], |
5480 'build': [build, '[options]'], | 5536 'build': [build, '[options]'], |
5481 'checkstyle': [checkstyle, ''], | 5537 'checkstyle': [checkstyle, ''], |
5482 'canonicalizeprojects': [canonicalizeprojects, ''], | 5538 'canonicalizeprojects': [canonicalizeprojects, ''], |
5539 'checkcopyrights': [checkcopyrights, '[options]'], | |
5483 'clean': [clean, ''], | 5540 'clean': [clean, ''], |
5484 'eclipseinit': [eclipseinit, ''], | 5541 'eclipseinit': [eclipseinit, ''], |
5485 'eclipseformat': [eclipseformat, ''], | 5542 'eclipseformat': [eclipseformat, ''], |
5486 'exportlibs': [exportlibs, ''], | 5543 'exportlibs': [exportlibs, ''], |
5487 'findclass': [findclass, ''], | 5544 'findclass': [findclass, ''], |