Mercurial > hg > truffle
comparison mxtool/mx.py @ 5701:d0a6e25de770
integrated mxtool changes from Maxine project
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 27 Jun 2012 12:46:30 +0200 |
parents | e9f7d16194a8 |
children | 6f2ccb483d96 |
comparison
equal
deleted
inserted
replaced
5700:12a34d1bcaa2 | 5701:d0a6e25de770 |
---|---|
48 Defines the projects and libraries in the suite and the | 48 Defines the projects and libraries in the suite and the |
49 dependencies between them. | 49 dependencies between them. |
50 | 50 |
51 commands.py | 51 commands.py |
52 Suite specific extensions to the commands available to mx. | 52 Suite specific extensions to the commands available to mx. |
53 This is only processed for the primary suite. | |
54 | 53 |
55 includes | 54 includes |
56 Other suites to be loaded. This is recursive. | 55 Other suites to be loaded. This is recursive. Each |
56 line in an includes file is a path to a suite directory. | |
57 | 57 |
58 env | 58 env |
59 A set of environment variable definitions. These override any | 59 A set of environment variable definitions. These override any |
60 existing environment variables. | 60 existing environment variables. |
61 | 61 |
292 self.includes = [] | 292 self.includes = [] |
293 self.commands = None | 293 self.commands = None |
294 self.primary = primary | 294 self.primary = primary |
295 mxDir = join(dir, 'mx') | 295 mxDir = join(dir, 'mx') |
296 self._load_env(mxDir) | 296 self._load_env(mxDir) |
297 if primary: | 297 self._load_commands(mxDir) |
298 self._load_commands(mxDir) | 298 self._load_includes(mxDir) |
299 | 299 |
300 def _load_projects(self, mxDir): | 300 def _load_projects(self, mxDir): |
301 libsMap = dict() | 301 libsMap = dict() |
302 projsMap = dict() | 302 projsMap = dict() |
303 projectsFile = join(mxDir, 'projects') | 303 projectsFile = join(mxDir, 'projects') |
364 def _load_commands(self, mxDir): | 364 def _load_commands(self, mxDir): |
365 commands = join(mxDir, 'commands.py') | 365 commands = join(mxDir, 'commands.py') |
366 if exists(commands): | 366 if exists(commands): |
367 # temporarily extend the Python path | 367 # temporarily extend the Python path |
368 sys.path.insert(0, mxDir) | 368 sys.path.insert(0, mxDir) |
369 | |
370 mod = __import__('commands') | 369 mod = __import__('commands') |
370 | |
371 sys.modules[join(mxDir, 'commands')] = sys.modules.pop('commands') | |
371 | 372 |
372 # revert the Python path | 373 # revert the Python path |
373 del sys.path[0] | 374 del sys.path[0] |
374 | 375 |
375 if not hasattr(mod, 'mx_init'): | 376 if not hasattr(mod, 'mx_init'): |
383 def _load_includes(self, mxDir): | 384 def _load_includes(self, mxDir): |
384 includes = join(mxDir, 'includes') | 385 includes = join(mxDir, 'includes') |
385 if exists(includes): | 386 if exists(includes): |
386 with open(includes) as f: | 387 with open(includes) as f: |
387 for line in f: | 388 for line in f: |
388 self.includes.append(expandvars_in_property(line.strip())) | 389 include = expandvars_in_property(line.strip()) |
390 self.includes.append(include) | |
391 _loadSuite(include, False) | |
389 | 392 |
390 def _load_env(self, mxDir): | 393 def _load_env(self, mxDir): |
391 e = join(mxDir, 'env') | 394 e = join(mxDir, 'env') |
392 if exists(e): | 395 if exists(e): |
393 with open(e) as f: | 396 with open(e) as f: |
397 key, value = line.split('=', 1) | 400 key, value = line.split('=', 1) |
398 os.environ[key.strip()] = expandvars_in_property(value.strip()) | 401 os.environ[key.strip()] = expandvars_in_property(value.strip()) |
399 | 402 |
400 def _post_init(self, opts): | 403 def _post_init(self, opts): |
401 mxDir = join(self.dir, 'mx') | 404 mxDir = join(self.dir, 'mx') |
402 self._load_includes(mxDir) | |
403 self._load_projects(mxDir) | 405 self._load_projects(mxDir) |
404 if self.mx_post_parse_cmd_line is not None: | 406 if hasattr(self, 'mx_post_parse_cmd_line'): |
405 self.mx_post_parse_cmd_line(opts) | 407 self.mx_post_parse_cmd_line(opts) |
406 for p in self.projects: | 408 for p in self.projects: |
407 existing = _projects.get(p.name) | 409 existing = _projects.get(p.name) |
408 if existing is not None: | 410 if existing is not None: |
409 abort('cannot override project ' + p.name + ' in ' + p.dir + " with project of the same name in " + existing.dir) | 411 abort('cannot override project ' + p.name + ' in ' + p.dir + " with project of the same name in " + existing.dir) |
1953 def ideinit(args, suite=None): | 1955 def ideinit(args, suite=None): |
1954 """(re)generate Eclipse and NetBeans project configurations""" | 1956 """(re)generate Eclipse and NetBeans project configurations""" |
1955 eclipseinit(args, suite) | 1957 eclipseinit(args, suite) |
1956 netbeansinit(args, suite) | 1958 netbeansinit(args, suite) |
1957 | 1959 |
1958 def javadoc(args): | 1960 def javadoc(args, parser=None, docDir='javadoc', includeDeps=True): |
1959 """generate javadoc for some/all Java projects""" | 1961 """generate javadoc for some/all Java projects""" |
1960 | 1962 |
1961 parser = ArgumentParser(prog='mx javadoc') | 1963 parser = ArgumentParser(prog='mx javadoc') if parser is None else parser |
1962 parser.add_argument('-d', '--base', action='store', help='base directory for output') | 1964 parser.add_argument('-d', '--base', action='store', help='base directory for output') |
1963 parser.add_argument('--unified', action='store_true', help='put javadoc in a single directory instead of one per project') | 1965 parser.add_argument('--unified', action='store_true', help='put javadoc in a single directory instead of one per project') |
1964 parser.add_argument('--force', action='store_true', help='(re)generate javadoc even if package-list file exists') | 1966 parser.add_argument('--force', action='store_true', help='(re)generate javadoc even if package-list file exists') |
1965 parser.add_argument('--projects', action='store', help='comma separated projects to process (omit to process all projects)') | 1967 parser.add_argument('--projects', action='store', help='comma separated projects to process (omit to process all projects)') |
1966 parser.add_argument('--argfile', action='store', help='name of file containing extra javadoc options') | 1968 parser.add_argument('--argfile', action='store', help='name of file containing extra javadoc options') |
1967 parser.add_argument('--arg', action='append', dest='extra_args', help='extra Javadoc arguments (e.g. --arg @-use)', metavar='@<arg>', default=[]) | 1969 parser.add_argument('--arg', action='append', dest='extra_args', help='extra Javadoc arguments (e.g. --arg @-use)', metavar='@<arg>', default=[]) |
1968 parser.add_argument('-m', '--memory', action='store', help='-Xmx value to pass to underlying JVM') | 1970 parser.add_argument('-m', '--memory', action='store', help='-Xmx value to pass to underlying JVM') |
1969 parser.add_argument('--wiki', action='store_true', help='generate Confluence Wiki format for package-info.java files') | |
1970 parser.add_argument('--packages', action='store', help='comma separated packages to process (omit to process all packages)') | 1971 parser.add_argument('--packages', action='store', help='comma separated packages to process (omit to process all packages)') |
1971 | 1972 |
1972 args = parser.parse_args(args) | 1973 args = parser.parse_args(args) |
1973 | 1974 |
1974 # build list of projects to be processed | 1975 # build list of projects to be processed |
1975 candidates = sorted_deps() | 1976 candidates = sorted_deps() |
1976 if args.projects is not None: | 1977 if args.projects is not None: |
1977 candidates = [project(name) for name in args.projects.split(',')] | 1978 candidates = [project(name) for name in args.projects.split(',')] |
1978 | 1979 |
1979 # optionally restrict packages within a project (most useful for wiki) | 1980 # optionally restrict packages within a project |
1980 packages = [] | 1981 packages = [] |
1981 if args.packages is not None: | 1982 if args.packages is not None: |
1982 packages = [name for name in args.packages.split(',')] | 1983 packages = [name for name in args.packages.split(',')] |
1983 | |
1984 # the WikiDoclet cannot see the -classpath argument passed to javadoc so we pass the | |
1985 # full list of projects as an explicit argument, thereby enabling it to map classes | |
1986 # to projects, which is needed to generate Wiki links to the source code. | |
1987 # There is no virtue in running the doclet on dependent projects as there are | |
1988 # no generated links between Wiki pages | |
1989 docletArgs = [] | |
1990 if args.wiki: | |
1991 docDir = 'wikidoc' | |
1992 toolsDir = project('com.oracle.max.tools').output_dir() | |
1993 baseDir = project('com.oracle.max.base').output_dir() | |
1994 dp = os.pathsep.join([toolsDir, baseDir]) | |
1995 project_list = ','.join(p.name for p in sorted_deps()) | |
1996 docletArgs = ['-docletpath', dp, '-doclet', 'com.oracle.max.tools.javadoc.wiki.WikiDoclet', '-projects', project_list] | |
1997 else: | |
1998 docDir = 'javadoc' | |
1999 | 1984 |
2000 def outDir(p): | 1985 def outDir(p): |
2001 if args.base is None: | 1986 if args.base is None: |
2002 return join(p.dir, docDir) | 1987 return join(p.dir, docDir) |
2003 return join(args.base, p.name, docDir) | 1988 return join(args.base, p.name, docDir) |
2004 | 1989 |
2005 def check_package_list(p): | 1990 def check_package_list(p): |
2006 if args.wiki: | 1991 return not exists(join(outDir(p), 'package-list')) |
2007 return True | |
2008 else: | |
2009 return not exists(join(outDir(p), 'package-list')) | |
2010 | 1992 |
2011 def assess_candidate(p, projects): | 1993 def assess_candidate(p, projects): |
2012 if p in projects: | 1994 if p in projects: |
2013 return False | 1995 return False |
2014 if args.force or args.unified or check_package_list(p): | 1996 if args.force or args.unified or check_package_list(p): |
2017 return False | 1999 return False |
2018 | 2000 |
2019 projects = [] | 2001 projects = [] |
2020 for p in candidates: | 2002 for p in candidates: |
2021 if not p.native: | 2003 if not p.native: |
2022 if not args.wiki: | 2004 if includeDeps: |
2023 deps = p.all_deps([], includeLibs=False, includeSelf=False) | 2005 deps = p.all_deps([], includeLibs=False, includeSelf=False) |
2024 for d in deps: | 2006 for d in deps: |
2025 assess_candidate(d, projects) | 2007 assess_candidate(d, projects) |
2026 if not assess_candidate(p, projects): | 2008 if not assess_candidate(p, projects): |
2027 log('[package-list file exists - skipping {0}]'.format(p.name)) | 2009 log('[package-list file exists - skipping {0}]'.format(p.name)) |
2055 links.append('-link') | 2037 links.append('-link') |
2056 links.append(os.path.relpath(depOut, out)) | 2038 links.append(os.path.relpath(depOut, out)) |
2057 cp = classpath(p.name, includeSelf=True) | 2039 cp = classpath(p.name, includeSelf=True) |
2058 sp = os.pathsep.join(p.source_dirs()) | 2040 sp = os.pathsep.join(p.source_dirs()) |
2059 log('Generating {2} for {0} in {1}'.format(p.name, out, docDir)) | 2041 log('Generating {2} for {0} in {1}'.format(p.name, out, docDir)) |
2060 run([java().javadoc, memory, '-classpath', cp, '-quiet', '-d', out, '-sourcepath', sp] + docletArgs + links + extraArgs + list(pkgs)) | 2042 run([java().javadoc, memory, '-classpath', cp, '-quiet', '-d', out, '-sourcepath', sp] + links + extraArgs + list(pkgs)) |
2061 log('Generated {2} for {0} in {1}'.format(p.name, out, docDir)) | 2043 log('Generated {2} for {0} in {1}'.format(p.name, out, docDir)) |
2062 else: | 2044 else: |
2063 pkgs = set() | 2045 pkgs = set() |
2064 sp = [] | 2046 sp = [] |
2065 names = [] | 2047 names = [] |
2073 if args.base is not None: | 2055 if args.base is not None: |
2074 out = join(args.base, docDir) | 2056 out = join(args.base, docDir) |
2075 cp = classpath() | 2057 cp = classpath() |
2076 sp = os.pathsep.join(sp) | 2058 sp = os.pathsep.join(sp) |
2077 log('Generating {2} for {0} in {1}'.format(', '.join(names), out, docDir)) | 2059 log('Generating {2} for {0} in {1}'.format(', '.join(names), out, docDir)) |
2078 run([java().javadoc, memory, '-classpath', cp, '-quiet', '-d', out, '-sourcepath', sp] + docletArgs + links + extraArgs + list(pkgs)) | 2060 run([java().javadoc, memory, '-classpath', cp, '-quiet', '-d', out, '-sourcepath', sp] + links + extraArgs + list(pkgs)) |
2079 log('Generated {2} for {0} in {1}'.format(', '.join(names), out, docDir)) | 2061 log('Generated {2} for {0} in {1}'.format(', '.join(names), out, docDir)) |
2080 | 2062 |
2081 def findclass(args): | 2063 def findclass(args): |
2082 """find all classes matching a given substring""" | 2064 """find all classes matching a given substring""" |
2083 | 2065 |