Mercurial > hg > graal-compiler
comparison mxtool/mx.py @ 22020:36a7ec14279d
moved unit test support from mx_graal.py to mx.py
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 18 Jun 2015 23:06:11 +0200 |
parents | 11ed27b2abe8 |
children | e942083c0fcc |
comparison
equal
deleted
inserted
replaced
22019:07cfd3d7072b | 22020:36a7ec14279d |
---|---|
31 Version 1.x supports a single suite of projects. | 31 Version 1.x supports a single suite of projects. |
32 | 32 |
33 Full documentation can be found at https://wiki.openjdk.java.net/display/Graal/The+mx+Tool | 33 Full documentation can be found at https://wiki.openjdk.java.net/display/Graal/The+mx+Tool |
34 """ | 34 """ |
35 | 35 |
36 import sys, os, errno, time, subprocess, shlex, types, StringIO, zipfile, signal, xml.sax.saxutils, tempfile, fnmatch, platform | 36 import sys |
37 if __name__ == '__main__': | |
38 # Rename this module as 'mx' so it is not re-executed when imported by other modules. | |
39 sys.modules['mx'] = sys.modules.pop('__main__') | |
40 | |
41 import os, errno, time, subprocess, shlex, types, StringIO, zipfile, signal, xml.sax.saxutils, tempfile, platform | |
37 import textwrap | 42 import textwrap |
38 import socket | 43 import socket |
39 import tarfile | 44 import tarfile |
40 import hashlib | 45 import hashlib |
41 import xml.parsers.expat | 46 import xml.parsers.expat |
42 import shutil, re, xml.dom.minidom | 47 import shutil, re, xml.dom.minidom |
43 import pipes | 48 import pipes |
44 import difflib | 49 import difflib |
50 import mx_unittest | |
45 from collections import Callable | 51 from collections import Callable |
46 from threading import Thread | 52 from threading import Thread |
47 from argparse import ArgumentParser, REMAINDER | 53 from argparse import ArgumentParser, REMAINDER |
48 from os.path import join, basename, dirname, exists, getmtime, isabs, expandvars, isdir, isfile | 54 from os.path import join, basename, dirname, exists, getmtime, isabs, expandvars, isdir, isfile |
49 | 55 |
97 _libs = dict() | 103 _libs = dict() |
98 _jreLibs = dict() | 104 _jreLibs = dict() |
99 _dists = dict() | 105 _dists = dict() |
100 _suites = dict() | 106 _suites = dict() |
101 _annotationProcessors = None | 107 _annotationProcessors = None |
108 _mx_suite = None | |
102 _primary_suite_path = None | 109 _primary_suite_path = None |
103 _primary_suite = None | 110 _primary_suite = None |
104 _opts = None | 111 _opts = None |
105 _extra_java_homes = [] | 112 _extra_java_homes = [] |
106 _default_java_home = None | 113 _default_java_home = None |
1037 try: | 1044 try: |
1038 self.requiredMxVersion = VersionSpec(suiteDict['mxversion']) | 1045 self.requiredMxVersion = VersionSpec(suiteDict['mxversion']) |
1039 except AssertionError as ae: | 1046 except AssertionError as ae: |
1040 abort('Exception while parsing "mxversion" in project file: ' + str(ae)) | 1047 abort('Exception while parsing "mxversion" in project file: ' + str(ae)) |
1041 | 1048 |
1042 libsMap = suiteDict['libraries'] | 1049 libsMap = suiteDict.get('libraries', {}) |
1043 jreLibsMap = suiteDict['jrelibraries'] | 1050 jreLibsMap = suiteDict.get('jrelibraries', {}) |
1044 projsMap = suiteDict['projects'] | 1051 projsMap = suiteDict.get('projects', {}) |
1045 distsMap = suiteDict['distributions'] | 1052 distsMap = suiteDict.get('distributions', {}) |
1046 | 1053 |
1047 def pop_list(attrs, name, context): | 1054 def pop_list(attrs, name, context): |
1048 v = attrs.pop(name, None) | 1055 v = attrs.pop(name, None) |
1049 if not v: | 1056 if not v: |
1050 return [] | 1057 return [] |
1703 deps = [] | 1710 deps = [] |
1704 for p in projects: | 1711 for p in projects: |
1705 p.all_deps(deps, includeLibs=includeLibs, includeJreLibs=includeJreLibs, includeAnnotationProcessors=includeAnnotationProcessors) | 1712 p.all_deps(deps, includeLibs=includeLibs, includeJreLibs=includeJreLibs, includeAnnotationProcessors=includeAnnotationProcessors) |
1706 return deps | 1713 return deps |
1707 | 1714 |
1715 def extract_VM_args(args, useDoubleDash=False, allowClasspath=False): | |
1716 """ | |
1717 Partitions 'args' into a leading sequence of HotSpot VM options and the rest. If | |
1718 'useDoubleDash' then 'args' is partititioned by the first instance of "--". If | |
1719 not 'allowClasspath' then mx aborts if "-cp" or "-classpath" is in 'args'. | |
1720 | |
1721 """ | |
1722 for i in range(len(args)): | |
1723 if useDoubleDash: | |
1724 if args[i] == '--': | |
1725 vmArgs = args[:i] | |
1726 remainder = args[i + 1:] | |
1727 return vmArgs, remainder | |
1728 else: | |
1729 if not args[i].startswith('-'): | |
1730 if i != 0 and (args[i - 1] == '-cp' or args[i - 1] == '-classpath'): | |
1731 if not allowClasspath: | |
1732 abort('Cannot supply explicit class path option') | |
1733 else: | |
1734 continue | |
1735 vmArgs = args[:i] | |
1736 remainder = args[i:] | |
1737 return vmArgs, remainder | |
1738 return args, [] | |
1739 | |
1708 class ArgParser(ArgumentParser): | 1740 class ArgParser(ArgumentParser): |
1709 # Override parent to append the list of available commands | 1741 # Override parent to append the list of available commands |
1710 def format_help(self): | 1742 def format_help(self): |
1711 return ArgumentParser.format_help(self) + _format_commands() | 1743 return ArgumentParser.format_help(self) + _format_commands() |
1712 | 1744 |
2051 def _find_jdk_in_candidates(candidates, versionCheck, warn=False, source=None): | 2083 def _find_jdk_in_candidates(candidates, versionCheck, warn=False, source=None): |
2052 filtered = _filtered_jdk_configs(candidates, versionCheck, warn, source) | 2084 filtered = _filtered_jdk_configs(candidates, versionCheck, warn, source) |
2053 if filtered: | 2085 if filtered: |
2054 return filtered[0] | 2086 return filtered[0] |
2055 return None | 2087 return None |
2056 | |
2057 | 2088 |
2058 def run_java(args, nonZeroIsFatal=True, out=None, err=None, cwd=None, addDefaultArgs=True, javaConfig=None): | 2089 def run_java(args, nonZeroIsFatal=True, out=None, err=None, cwd=None, addDefaultArgs=True, javaConfig=None): |
2059 if not javaConfig: | 2090 if not javaConfig: |
2060 javaConfig = java() | 2091 javaConfig = java() |
2061 return run(javaConfig.format_cmd(args, addDefaultArgs), nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd) | 2092 return run(javaConfig.format_cmd(args, addDefaultArgs), nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd) |
5001 """find directories corresponding to deleted Java projects and delete them""" | 5032 """find directories corresponding to deleted Java projects and delete them""" |
5002 if not is_interactive(): | 5033 if not is_interactive(): |
5003 log('fsckprojects command must be run in an interactive shell') | 5034 log('fsckprojects command must be run in an interactive shell') |
5004 return | 5035 return |
5005 hg = HgConfig() | 5036 hg = HgConfig() |
5037 projectDirs = [p.dir for suite in suites() for p in suite.projects] | |
5038 distIdeDirs = [d.get_ide_project_dir() for suite in suites() for d in suite.dists if d.get_ide_project_dir() is not None] | |
5006 for suite in suites(True): | 5039 for suite in suites(True): |
5007 projectDirs = [p.dir for p in suite.projects] | |
5008 distIdeDirs = [d.get_ide_project_dir() for d in suite.dists if d.get_ide_project_dir() is not None] | |
5009 for dirpath, dirnames, files in os.walk(suite.dir): | 5040 for dirpath, dirnames, files in os.walk(suite.dir): |
5010 if dirpath == suite.dir: | 5041 if dirpath == suite.dir: |
5011 # no point in traversing .hg, lib, or .workspace | 5042 # no point in traversing .hg, lib, or .workspace |
5012 dirnames[:] = [d for d in dirnames if d not in ['.hg', 'lib', '.workspace']] | 5043 dirnames[:] = [d for d in dirnames if d not in ['.hg', 'lib', '.workspace']] |
5013 elif dirpath in projectDirs: | 5044 elif dirpath in projectDirs: |
5014 # don't traverse subdirs of an existing project in this suite | 5045 # don't traverse subdirs of an existing project |
5015 dirnames[:] = [] | 5046 dirnames[:] = [] |
5016 elif dirpath in distIdeDirs: | 5047 elif dirpath in distIdeDirs: |
5017 # don't traverse subdirs of an existing distributions in this suite | 5048 # don't traverse subdirs of an existing distribution |
5018 dirnames[:] = [] | 5049 dirnames[:] = [] |
5019 else: | 5050 else: |
5020 projectConfigFiles = frozenset(['.classpath', '.project', 'nbproject']) | 5051 projectConfigFiles = frozenset(['.classpath', '.project', 'nbproject']) |
5021 indicators = projectConfigFiles.intersection(files) | 5052 indicators = projectConfigFiles.intersection(files) |
5022 if len(indicators) != 0: | 5053 if len(indicators) != 0: |
5023 indicators = [os.path.relpath(join(dirpath, i), suite.dir) for i in indicators] | 5054 indicators = [os.path.relpath(join(dirpath, i), suite.dir) for i in indicators] |
5024 indicatorsInHg = hg.locate(suite.dir, indicators) | 5055 indicatorsInHg = hg.locate(suite.dir, indicators) |
5025 # Only proceed if there are indicator files that are not under HG | 5056 # Only proceed if there are indicator files that are not under HG |
5026 if len(indicators) > len(indicatorsInHg): | 5057 if len(indicators) > len(indicatorsInHg): |
5027 if not is_interactive() or ask_yes_no(dirpath + ' looks like a removed project -- delete it', 'n'): | 5058 if ask_yes_no(dirpath + ' looks like a removed project -- delete it', 'n'): |
5028 shutil.rmtree(dirpath) | 5059 shutil.rmtree(dirpath) |
5029 log('Deleted ' + dirpath) | 5060 log('Deleted ' + dirpath) |
5030 | 5061 |
5031 def javadoc(args, parser=None, docDir='javadoc', includeDeps=True, stdDoclet=True): | 5062 def javadoc(args, parser=None, docDir='javadoc', includeDeps=True, stdDoclet=True): |
5032 """generate javadoc for some/all Java projects""" | 5063 """generate javadoc for some/all Java projects""" |
5667 'javadoc': [javadoc, '[options]'], | 5698 'javadoc': [javadoc, '[options]'], |
5668 'site': [site, '[options]'], | 5699 'site': [site, '[options]'], |
5669 'netbeansinit': [netbeansinit, ''], | 5700 'netbeansinit': [netbeansinit, ''], |
5670 'suites': [show_suites, ''], | 5701 'suites': [show_suites, ''], |
5671 'projects': [show_projects, ''], | 5702 'projects': [show_projects, ''], |
5703 'unittest' : [mx_unittest.unittest, '[unittest options] [--] [VM options] [filters...]', mx_unittest.unittestHelpSuffix], | |
5672 } | 5704 } |
5673 | 5705 |
5674 _argParser = ArgParser() | 5706 _argParser = ArgParser() |
5675 | 5707 |
5676 def _suitename(mxDir): | 5708 def _suitename(mxDir): |
5725 return mxDir | 5757 return mxDir |
5726 # backwards compatibility: search from path of this file | 5758 # backwards compatibility: search from path of this file |
5727 return _findPrimarySuiteMxDirFrom(dirname(__file__)) | 5759 return _findPrimarySuiteMxDirFrom(dirname(__file__)) |
5728 | 5760 |
5729 def main(): | 5761 def main(): |
5762 mxMxDir = _is_suite_dir(dirname(__file__)) | |
5763 assert mxMxDir | |
5764 global _mx_suite | |
5765 _mx_suite = _loadSuite(mxMxDir) | |
5766 | |
5730 primarySuiteMxDir = _findPrimarySuiteMxDir() | 5767 primarySuiteMxDir = _findPrimarySuiteMxDir() |
5731 if primarySuiteMxDir: | 5768 if primarySuiteMxDir: |
5732 global _primary_suite | 5769 global _primary_suite |
5733 _primary_suite = _loadSuite(primarySuiteMxDir, True) | 5770 _primary_suite = _loadSuite(primarySuiteMxDir, True) |
5734 else: | 5771 else: |
5783 version = VersionSpec("1.0") | 5820 version = VersionSpec("1.0") |
5784 | 5821 |
5785 currentUmask = None | 5822 currentUmask = None |
5786 | 5823 |
5787 if __name__ == '__main__': | 5824 if __name__ == '__main__': |
5788 # rename this module as 'mx' so it is not imported twice by the commands.py modules | |
5789 sys.modules['mx'] = sys.modules.pop('__main__') | |
5790 | |
5791 # Capture the current umask since there's no way to query it without mutating it. | 5825 # Capture the current umask since there's no way to query it without mutating it. |
5792 currentUmask = os.umask(0) | 5826 currentUmask = os.umask(0) |
5793 os.umask(currentUmask) | 5827 os.umask(currentUmask) |
5794 | 5828 |
5795 main() | 5829 main() |