annotate mxtool/mx.py @ 4144:34527a24bcf8

Adopted mxtool changes.
author Doug Simon <doug.simon@oracle.com>
date Mon, 19 Dec 2011 18:31:09 +0100
parents 3e2e8b8abdaf
children 9aee7df31417
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 #!/usr/bin/python
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 # ----------------------------------------------------------------------------------------------------
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 # Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 # This code is free software; you can redistribute it and/or modify it
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 # under the terms of the GNU General Public License version 2 only, as
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 # published by the Free Software Foundation.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 # This code is distributed in the hope that it will be useful, but WITHOUT
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 # version 2 for more details (a copy is included in the LICENSE file that
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 # accompanied this code).
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 # You should have received a copy of the GNU General Public License version
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 # 2 along with this work; if not, write to the Free Software Foundation,
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
23 # or visit www.oracle.com if you need additional information or have any
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24 # questions.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26 # ----------------------------------------------------------------------------------------------------
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
27 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28 # mx is a command line tool inspired by mvn (http://maven.apache.org/)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29 # and hg (http://mercurial.selenic.com/). It includes a mechanism for
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30 # managing the dependencies between a set of projects (like Maven)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31 # as well as making it simple to run commands
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32 # (like hg is the interface to the Mercurial commands).
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 # When launched, mx looks for a mx configuration (i.e. a directory named 'mx')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 # in the current working directory. This is the primary mx configuration. Any
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36 # other mx configurations are included mx configurations.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
38 # If an mx configuration exists, then the following files in the configuration
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
39 # are processed (if they exist):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
41 # projects - Lists projects, libraries and dependencies between them
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42 # commands.py - Extensions to the commands launchable by mx. This is only processed
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
43 # for the primary mx configuration.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 # includes - Other directories containing mx configurations to be loaded.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45 # This is a recursive action.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46 # env - A set of environment variable definitions.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48 # The MX_INCLUDES environment variable can also be used to specify
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
49 # other directories containing mx configurations.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
50 # This value of this variable has the same format as a Java class path.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
51 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
52 # The includes and env files are typically not put under version control
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
53 # as they usually contain local filesystem paths.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
54 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
55 # The projects file is like the pom.xml file from Maven except that
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
56 # it is in a properties file format instead of XML. Each non-comment line
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
57 # in the file specifies an attribute of a project or library. The main
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
58 # difference between a project and a library is that the former contains
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59 # source code built by the mx tool where as the latter is an external
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
60 # dependency. The format of the projects file is
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
61 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
62 # Library specification format:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
63 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
64 # library@<name>@<prop>=<value>
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
65 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
66 # Built-in library properties (* = required):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
67 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
68 # *path: the file system path for the library to appear on a class path
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69 # urls: a comma seperated list of URLs from which the library can be downloaded
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
70 # optional: if "true" then this library will be omitted from a class path if it doesn't exist on the file system and no URLs are specified
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 # Project specification format:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
74 # project@<name>@<prop>=<value>
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
75 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
76 # The name of a project also denotes the directory it is in.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
77 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
78 # Built-in project properties:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
79 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
80 # *sourceDirs: a comma separated list of source directoriy names (relative to the project directory)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
81 # dependencies: a comma separated list of the libraries and project the project depends upon (transitive dependencies may be omitted)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
82 # checkstyle: the project whose Checkstyle configuration (i.e. <project>/.checkstyle_checks.xml) is used
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
83 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
84 # Other properties can be specified for projects and libraries for use by extension commands.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
85 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
86 # Values can use environment variables with Bash syntax (e.g. ${HOME}).
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
87
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
88 import sys
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
89 import os
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
90 import subprocess
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
91 from collections import Callable
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
92 from threading import Thread
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
93 from argparse import ArgumentParser, REMAINDER
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
94 from os.path import join, dirname, exists, getmtime, isabs, expandvars, isdir
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
95 import shlex
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
96 import types
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
97 import urllib2
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
98 import contextlib
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
99 import StringIO
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
100 import zipfile
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
101 import shutil, fnmatch, re, xml.dom.minidom
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
102
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
103 DEFAULT_JAVA_ARGS = '-ea -Xss2m -Xmx1g'
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
104
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
105 _projects = dict()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
106 _libs = dict()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
107 _suites = dict()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
108
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
109 """ Options parsed from the command line. """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
110 _opts = None
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
111
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
112 """ Prefix for a Java command. """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
113 _java = None
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
114
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
115 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
116 A dependency is a library or project specified in a suite.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
117 """
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
118 class Dependency:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
119 def __init__(self, suite, name):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
120 self.name = name
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
121 self.suite = suite
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
122
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
123 def __str__(self):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
124 return self.name
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
125
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
126 def __eq__(self, other):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
127 return self.name == other.name
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
128
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
129 def __ne__(self, other):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
130 return self.name != other.name
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
131
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
132 def __hash__(self):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
133 return hash(self.name)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
134
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
135 def isLibrary(self):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
136 return isinstance(self, Library)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
137
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
138 class Project(Dependency):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
139 def __init__(self, suite, name, srcDirs, deps, dir):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
140 Dependency.__init__(self, suite, name)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
141 self.srcDirs = srcDirs
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
142 self.deps = deps
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
143 self.checkstyleProj = name
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
144 self.native = False
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
145 self.dir = dir
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
146
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
147 def all_deps(self, deps, includeLibs):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
148 if self in deps:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
149 return deps
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
150 for name in self.deps:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
151 assert name != self.name
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
152 dep = _libs.get(name, None)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
153 if dep is not None:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
154 if includeLibs and not dep in deps:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
155 deps.append(dep)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
156 else:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
157 dep = project(name)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
158 if not dep in deps:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
159 dep.all_deps(deps, includeLibs)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
160 if not self in deps:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
161 deps.append(self)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
162 return deps
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
163
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
164 def _compute_max_dep_distances(self, name, distances, dist):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
165 currentDist = distances.get(name);
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
166 if currentDist is None or currentDist < dist:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
167 distances[name] = dist
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
168 p = project(name, False)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
169 if p is not None:
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
170 for dep in p.deps:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
171 self._compute_max_dep_distances(dep, distances, dist + 1)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
172
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
173 def canonical_deps(self):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
174 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
175 Get the dependencies of this project that are not recursive (i.e. cannot be reached
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
176 via other dependencies).
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
177 """
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
178 distances = dict()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
179 result = set()
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
180 self._compute_max_dep_distances(self.name, distances, 0)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
181 for n,d in distances.iteritems():
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
182 assert d > 0 or n == self.name
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
183 if d == 1:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
184 result.add(n)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
185
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
186
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
187 if len(result) == len(self.deps) and frozenset(self.deps) == result:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
188 return self.deps
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
189 return result;
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
190
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
191
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
192 def source_dirs(self):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
193 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
194 Get the directories in whihc the sources of this project are found.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
195 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
196 return [join(self.dir, s) for s in self.srcDirs]
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
197
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
198 def output_dir(self):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
199 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
200 Get the directory in which the class files of this project are found.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
201 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
202 if self.native:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
203 return None
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
204 return join(self.dir, 'bin')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
205
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
206 def append_to_classpath(self, cp, resolve):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
207 if not self.native:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
208 cp.append(self.output_dir())
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
209
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
210 class Library(Dependency):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
211 def __init__(self, suite, name, path, mustExist, urls):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
212 Dependency.__init__(self, suite, name)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
213 self.path = path
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
214 self.urls = urls
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
215 self.mustExist = mustExist
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
216
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
217 def get_path(self, resolve):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
218 path = self.path
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
219 if not isabs(path):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
220 path = join(self.suite.dir, path)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
221 if resolve and self.mustExist and not exists(path):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
222 assert not len(self.urls) == 0, 'cannot find required library ' + self.name + " " + path;
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
223 download(path, self.urls)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
224 return path
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
225
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
226 def append_to_classpath(self, cp, resolve):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
227 path = self.get_path(resolve)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
228 if exists(path) or not resolve:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
229 cp.append(path)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
230
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
231 class Suite:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
232 def __init__(self, dir, primary):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
233 self.dir = dir
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
234 self.projects = []
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
235 self.libs = []
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
236 self.includes = []
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
237 self.commands = None
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
238 self._load(join(dir, 'mx'), primary=primary)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
239
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
240 def _load_projects(self, mxDir):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
241 libsMap = dict()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
242 projsMap = dict()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
243 projectsFile = join(mxDir, 'projects')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
244 if not exists(projectsFile):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
245 return
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
246 with open(projectsFile) as f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
247 for line in f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
248 line = line.strip()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
249 if len(line) != 0 and line[0] != '#':
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
250 key, value = line.split('=', 1)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
251
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
252 parts = key.split('@')
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
253
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
254 if len(parts) == 2:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
255 pass
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
256 if len(parts) != 3:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
257 abort('Property name does not have 3 parts separated by "@": ' + key)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
258 kind, name, attr = parts
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
259 if kind == 'project':
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
260 m = projsMap
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
261 elif kind == 'library':
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
262 m = libsMap
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
263 else:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
264 abort('Property name does not start with "project@" or "library@": ' + key)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
265
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
266 attrs = m.get(name)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
267 if attrs is None:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
268 attrs = dict()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
269 m[name] = attrs
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
270 value = expandvars_in_property(value)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
271 attrs[attr] = value
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
272
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
273 def pop_list(attrs, name):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
274 v = attrs.pop(name, None)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
275 if v is None or len(v.strip()) == 0:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
276 return []
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
277 return [n.strip() for n in v.split(',')]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
278
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
279 for name, attrs in projsMap.iteritems():
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
280 srcDirs = pop_list(attrs, 'sourceDirs')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
281 deps = pop_list(attrs, 'dependencies')
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
282 subDir = attrs.pop('subDir', None);
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
283 if subDir is None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
284 dir = join(self.dir, name)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
285 else:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
286 dir = join(self.dir, subDir, name)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
287 p = Project(self, name, srcDirs, deps, dir)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
288 p.checkstyleProj = attrs.pop('checkstyle', name)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
289 p.native = attrs.pop('native', '') == 'true'
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
290 p.__dict__.update(attrs)
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
291 self.projects.append(p)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
292
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
293 for name, attrs in libsMap.iteritems():
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
294 path = attrs['path']
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
295 mustExist = attrs.pop('optional', 'false') != 'true'
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
296 urls = pop_list(attrs, 'urls')
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
297 l = Library(self, name, path, mustExist, urls)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
298 l.__dict__.update(attrs)
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
299 self.libs.append(l)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
300
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
301 def _load_commands(self, mxDir):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
302 commands = join(mxDir, 'commands.py')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
303 if exists(commands):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
304 # temporarily extend the Python path
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
305 sys.path.insert(0, mxDir)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
306
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
307 mod = __import__('commands')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
308
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
309 # revert the Python path
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
310 del sys.path[0]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
311
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
312 if not hasattr(mod, 'mx_init'):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
313 abort(commands + ' must define an mx_init(env) function')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
314
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
315 mod.mx_init()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
316 self.commands = mod
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
317
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
318 def _load_includes(self, mxDir):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
319 includes = join(mxDir, 'includes')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
320 if exists(includes):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
321 with open(includes) as f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
322 for line in f:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
323 self.includes.append(expandvars_in_property(line.strip()))
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
324
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
325 def _load_env(self, mxDir):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
326 e = join(mxDir, 'env')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
327 if exists(e):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
328 with open(e) as f:
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
329 for line in f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
330 line = line.strip()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
331 if len(line) != 0 and line[0] != '#':
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
332 key, value = line.split('=', 1)
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
333 os.environ[key.strip()] = expandvars_in_property(value.strip())
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
334
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
335 def _load(self, mxDir, primary):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
336 self._load_includes(mxDir)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
337 self._load_projects(mxDir)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
338 self._load_env(mxDir)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
339 if primary:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
340 self._load_commands(mxDir)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
341
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
342 def get_os():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
343 if sys.platform.startswith('darwin'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
344 return 'darwin'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
345 elif sys.platform.startswith('linux'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
346 return 'linux'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
347 elif sys.platform.startswith('sunos'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
348 return 'solaris'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
349 elif sys.platform.startswith('win32') or sys.platform.startswith('cygwin'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
350 return 'windows'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
351 else:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
352 abort('Unknown operating system ' + sys.platform)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
353
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
354 def _loadSuite(dir, primary=False):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
355 mxDir = join(dir, 'mx')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
356 if not exists(mxDir) or not isdir(mxDir):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
357 return
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
358 if not _suites.has_key(dir):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
359 suite = Suite(dir, primary)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
360 _suites[dir] = suite
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
361 for p in suite.projects:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
362 existing = _projects.get(p.name)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
363 if existing is not None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
364 abort('cannot override project ' + p.name + ' in ' + p.dir + " with project of the same name in " + existing.dir)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
365 _projects[p.name] = p
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
366 for l in suite.libs:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
367 existing = _libs.get(l.name)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
368 if existing is not None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
369 abort('cannot redefine library ' + l.name)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
370 _libs[l.name] = l
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
371
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
372 def suites():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
373 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
374 Get the list of all loaded suites.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
375 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
376 return _suites.values()
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
377
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
378 def projects():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
379 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
380 Get the list of all loaded projects.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
381 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
382 return _projects.values()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
383
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
384 def project(name, fatalIfMissing=True):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
385 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
386 Get the project for a given name. This will abort if the named project does
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
387 not exist and 'fatalIfMissing' is true.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
388 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
389 p = _projects.get(name)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
390 if p is None and fatalIfMissing:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
391 abort('project named ' + name + ' not found')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
392 return p
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
393
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
394 def library(name, fatalIfMissing=True):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
395 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
396 Gets the library for a given name. This will abort if the named library does
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
397 not exist and 'fatalIfMissing' is true.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
398 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
399 l = _libs.get(name)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
400 if l is None and fatalIfMissing:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
401 abort('library named ' + name + ' not found')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
402 return l
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
403
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
404 def _as_classpath(deps, resolve):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
405 cp = []
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
406 if _opts.cp_prefix is not None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
407 cp = [_opts.cp_prefix]
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
408 for d in deps:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
409 d.append_to_classpath(cp, resolve)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
410 if _opts.cp_suffix is not None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
411 cp += [_opts.cp_suffix]
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
412 return os.pathsep.join(cp)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
413
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
414 def classpath(names=None, resolve=True):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
415 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
416 Get the class path for a list of given projects, resolving each entry in the
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
417 path (e.g. downloading a missing library) if 'resolve' is true.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
418 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
419 if names is None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
420 return _as_classpath(sorted_deps(True), resolve)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
421 deps = []
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
422 if isinstance(names, types.StringTypes):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
423 project(names).all_deps(deps, True)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
424 else:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
425 for n in names:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
426 project(n).all_deps(deps, True)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
427 return _as_classpath(deps, resolve)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
428
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
429 def sorted_deps(includeLibs=False):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
430 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
431 Gets the loaded projects and libraries sorted such that dependencies
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
432 are before the projects that depend on them. Unless 'includeLibs' is
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
433 true, libraries are omitted from the result.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
434 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
435 deps = []
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
436 for p in _projects.itervalues():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
437 p.all_deps(deps, includeLibs)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
438 return deps
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
439
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
440 class ArgParser(ArgumentParser):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
441
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
442 # Override parent to append the list of available commands
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
443 def format_help(self):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
444 return ArgumentParser.format_help(self) + _format_commands()
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
445
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
446
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
447 def __init__(self):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
448 self.java_initialized = False
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
449 ArgumentParser.__init__(self, prog='mx')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
450
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
451 self.add_argument('-v', action='store_true', dest='verbose', help='enable verbose output')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
452 self.add_argument('-d', action='store_true', dest='java_dbg', help='make Java processes wait on port 8000 for a debugger')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
453 self.add_argument('--cp-pfx', dest='cp_prefix', help='class path prefix', metavar='<arg>')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
454 self.add_argument('--cp-sfx', dest='cp_suffix', help='class path suffix', metavar='<arg>')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
455 self.add_argument('--J', dest='java_args', help='Java VM arguments (e.g. --J @-dsa)', metavar='@<args>', default=DEFAULT_JAVA_ARGS)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
456 self.add_argument('--Jp', action='append', dest='java_args_pfx', help='prefix Java VM arguments (e.g. --Jp @-dsa)', metavar='@<args>', default=[])
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
457 self.add_argument('--Ja', action='append', dest='java_args_sfx', help='suffix Java VM arguments (e.g. --Ja @-dsa)', metavar='@<args>', default=[])
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
458 self.add_argument('--user-home', help='users home directory', metavar='<path>', default=os.path.expanduser('~'))
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
459 self.add_argument('--java-home', help='JDK installation directory (must be JDK 6 or later)', metavar='<path>', default=_default_java_home())
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
460
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
461 def _parse_cmd_line(self, args=None):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
462 if args is None:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
463 args = sys.argv[1:]
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
464
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
465 self.add_argument('commandAndArgs', nargs=REMAINDER, metavar='command args...')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
466
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
467 opts = self.parse_args()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
468
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
469 if opts.java_home is None or opts.java_home == '':
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
470 abort('Could not find Java home. Use --java-home option or ensure JAVA_HOME environment variable is set.')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
471
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
472 if opts.user_home is None or opts.user_home == '':
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
473 abort('Could not find user home. Use --user-home option or ensure HOME environment variable is set.')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
474
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
475 os.environ['JAVA_HOME'] = opts.java_home
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
476 os.environ['HOME'] = opts.user_home
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
477
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
478 opts.java = join(opts.java_home, 'bin', 'java')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
479 opts.javac = join(opts.java_home, 'bin', 'javac')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
480 opts.javap = join(opts.java_home, 'bin', 'javap')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
481
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
482 commandAndArgs = opts.__dict__.pop('commandAndArgs')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
483
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
484 for s in suites():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
485 mod = s.commands
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
486 if hasattr(mod is not None and mod, 'mx_post_parse_cmd_line'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
487 mod.mx_post_parse_cmd_line(opts)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
488
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
489 return opts, commandAndArgs
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
490
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
491 def _format_commands():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
492 msg = '\navailable commands:\n\n'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
493 for cmd in sorted(commands.iterkeys()):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
494 c, _ = commands[cmd][:2]
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
495 doc = c.__doc__
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
496 if doc is None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
497 doc = ''
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
498 msg += ' {0:<20} {1}\n'.format(cmd, doc.split('\n', 1)[0])
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
499 return msg + '\n'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
500
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
501 def java_home():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
502 return _opts.java_home
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
503
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
504 def java_exe():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
505 return exe_suffix(_opts.java)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
506
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
507 def java_args():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
508 init_java()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
509 return _opts.java_args
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
510
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
511 def format_java_cmd(args):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
512 init_java()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
513 return _java + args
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
514
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
515 def run_java(args, nonZeroIsFatal=True, out=None, err=None, cwd=None):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
516 return run(format_java_cmd(args), nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
517
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
518 def run(args, nonZeroIsFatal=True, out=None, err=None, cwd=None):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
519 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
520 Run a command in a subprocess, wait for it to complete and return the exit status of the process.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
521 If the exit status is non-zero and `nonZeroIsFatal` is true, then the program is exited with
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
522 the same exit status.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
523 Each line of the standard output and error streams of the subprocess are redirected to the
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
524 provided out and err functions if they are not None.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
525 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
526
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
527 assert isinstance(args, types.ListType), "'args' must be a list: " + str(args)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
528 for arg in args:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
529 assert isinstance(arg, types.StringTypes), 'argument is not a string: ' + str(arg)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
530
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
531 if _opts.verbose:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
532 log(' '.join(args))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
533
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
534 try:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
535 if out is None and err is None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
536 retcode = subprocess.call(args, cwd=cwd)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
537 else:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
538 def redirect(stream, f):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
539 for line in iter(stream.readline, ''):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
540 f(line)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
541 stream.close()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
542 p = subprocess.Popen(args, cwd=cwd, stdout=None if out is None else subprocess.PIPE, stderr=None if err is None else subprocess.PIPE)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
543 if out is not None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
544 t = Thread(target=redirect, args=(p.stdout, out))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
545 t.daemon = True # thread dies with the program
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
546 t.start()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
547 if err is not None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
548 t = Thread(target=redirect, args=(p.stderr, err))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
549 t.daemon = True # thread dies with the program
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
550 t.start()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
551 retcode = p.wait()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
552 except OSError as e:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
553 log('Error executing \'' + ' '.join(args) + '\': ' + str(e))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
554 if _opts.verbose:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
555 raise e
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
556 abort(e.errno)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
557
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
558
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
559 if retcode and nonZeroIsFatal:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
560 if _opts.verbose:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
561 raise subprocess.CalledProcessError(retcode, ' '.join(args))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
562 abort(retcode)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
563
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
564 return retcode
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
565
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
566 def exe_suffix(name):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
567 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
568 Gets the platform specific suffix for an executable
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
569 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
570 if os == 'windows':
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
571 return name + '.exe'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
572 return name
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
573
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
574 def init_java():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
575 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
576 Lazy initialization and preprocessing of this object's fields before running a Java command.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
577 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
578 global _java
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
579 if _java is not None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
580 return
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
581
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
582 def delAtAndSplit(s):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
583 return shlex.split(s.lstrip('@'))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
584
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
585 _opts.java_args = delAtAndSplit(_opts.java_args)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
586 _opts.java_args_pfx = sum(map(delAtAndSplit, _opts.java_args_pfx), [])
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
587 _opts.java_args_sfx = sum(map(delAtAndSplit, _opts.java_args_sfx), [])
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
588
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
589 # Prepend the -d64 VM option only if the java command supports it
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
590 output = ''
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
591 java = _opts.java
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
592 try:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
593
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
594 output = subprocess.check_output([java, '-d64', '-version'], stderr=subprocess.STDOUT)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
595 _opts.java_args = ['-d64'] + _opts.java_args
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
596 except subprocess.CalledProcessError as e:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
597 try:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
598 output = subprocess.check_output([java, '-version'], stderr=subprocess.STDOUT)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
599 except subprocess.CalledProcessError as e:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
600 print e.output
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
601 abort(e.returncode)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
602
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
603 output = output.split()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
604 assert output[0] == 'java' or output[0] == 'openjdk'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
605 assert output[1] == 'version'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
606 version = output[2]
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
607 if not version.startswith('"1.6') and not version.startswith('"1.7'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
608 abort('Requires Java version 1.6 or 1.7, got version ' + version)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
609
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
610 if _opts.java_dbg:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
611 _opts.java_args += ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000']
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
612
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
613 _java = [java] + _opts.java_args_pfx + _opts.java_args + _opts.java_args_sfx
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
614
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
615 def _default_java_home():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
616 javaHome = os.getenv('JAVA_HOME')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
617 if javaHome is None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
618 if exists('/usr/lib/java/java-6-sun'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
619 javaHome = '/usr/lib/java/java-6-sun'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
620 elif exists('/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
621 javaHome = '/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
622 elif exists('/usr/jdk/latest'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
623 javaHome = '/usr/jdk/latest'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
624 return javaHome
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
625
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
626 def check_get_env(key):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
627 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
628 Gets an environment variable, aborting with a useful message if it is not set.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
629 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
630 value = os.environ.get(key)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
631 if value is None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
632 abort('Required environment variable ' + key + ' must be set')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
633 return value
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
634
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
635 def log(msg=None):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
636 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
637 Write a message to the console.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
638 All script output goes through this method thus allowing a subclass
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
639 to redirect it.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
640 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
641 if msg is None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
642 print
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
643 else:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
644 print msg
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
645
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
646 def expand_project_in_class_path_arg(cpArg):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
647 cp = []
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
648 for part in cpArg.split(os.pathsep):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
649 if part.startswith('@'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
650 cp += classpath(part[1:]).split(os.pathsep)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
651 else:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
652 cp.append(part)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
653 return os.pathsep.join(cp)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
654
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
655 def expand_project_in_args(args):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
656 for i in range(len(args)):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
657 if args[i] == '-cp' or args[i] == '-classpath':
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
658 if i + 1 < len(args):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
659 args[i + 1] = expand_project_in_class_path_arg(args[i + 1])
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
660 return
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
661
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
662
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
663 def gmake_cmd():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
664 for a in ['make', 'gmake', 'gnumake']:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
665 try:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
666 output = subprocess.check_output([a, '--version'])
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
667 if 'GNU' in output:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
668 return a;
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
669 except:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
670 pass
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
671 abort('Could not find a GNU make executable on the current path.')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
672
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
673 def expandvars_in_property(value):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
674 result = expandvars(value)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
675 if '$' in result or '%' in result:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
676 abort('Property contains an undefined environment variable: ' + value)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
677 return result
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
678
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
679
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
680 def abort(codeOrMessage):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
681 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
682 Aborts the program with a SystemExit exception.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
683 If 'codeOrMessage' is a plain integer, it specifies the system exit status;
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
684 if it is None, the exit status is zero; if it has another type (such as a string),
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
685 the object's value is printed and the exit status is one.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
686 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
687 raise SystemExit(codeOrMessage)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
688
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
689 def download(path, urls, verbose=False):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
690 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
691 Attempts to downloads content for each URL in a list, stopping after the first successful download.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
692 If the content cannot be retrieved from any URL, the program is aborted. The downloaded content
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
693 is written to the file indicated by 'path'.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
694 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
695 d = dirname(path)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
696 if d != '' and not exists(d):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
697 os.makedirs(d)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
698
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
699 def url_open(url):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
700 userAgent = 'Mozilla/5.0 (compatible)'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
701 headers = { 'User-Agent' : userAgent }
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
702 req = urllib2.Request(url, headers=headers)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
703 return urllib2.urlopen(req);
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
704
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
705 for url in urls:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
706 try:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
707 if (verbose):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
708 log('Downloading ' + url + ' to ' + path)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
709 if url.startswith('zip:') or url.startswith('jar:'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
710 i = url.find('!/')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
711 if i == -1:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
712 abort('Zip or jar URL does not contain "!/": ' + url)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
713 url, _, entry = url[len('zip:'):].partition('!/')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
714 with contextlib.closing(url_open(url)) as f:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
715 data = f.read()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
716 zipdata = StringIO.StringIO(f.read())
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
717
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
718 zf = zipfile.ZipFile(zipdata, 'r')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
719 data = zf.read(entry)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
720 with open(path, 'w') as f:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
721 f.write(data)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
722 else:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
723 with contextlib.closing(url_open(url)) as f:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
724 data = f.read()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
725 with open(path, 'w') as f:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
726 f.write(data)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
727 return
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
728 except IOError as e:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
729 log('Error reading from ' + url + ': ' + str(e))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
730 except zipfile.BadZipfile as e:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
731 log('Error in zip file downloaded from ' + url + ': ' + str(e))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
732
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
733 # now try it with Java - urllib2 does not handle meta refreshes which are used by Sourceforge
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
734 myDir = dirname(__file__)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
735
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
736 javaSource = join(myDir, 'URLConnectionDownload.java')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
737 javaClass = join(myDir, 'URLConnectionDownload.class')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
738 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
739 subprocess.check_call([_opts.javac, '-d', myDir, javaSource])
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
740 if run([_opts.java, '-cp', myDir, 'URLConnectionDownload', path] + urls) != 0:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
741 abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' +
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
742 '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
743
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
744 def update_file(path, content):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
745 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
746 Updates a file with some given content if the content differs from what's in
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
747 the file already. The return value indicates if the file was updated.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
748 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
749 existed = exists(path)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
750 try:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
751 old = None
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
752 if existed:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
753 with open(path, 'rb') as f:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
754 old = f.read()
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
755
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
756 if old == content:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
757 return False
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
758
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
759 with open(path, 'wb') as f:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
760 f.write(content)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
761
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
762 log(('modified ' if existed else 'created ') + path)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
763 return True;
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
764 except IOError as e:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
765 abort('Error while writing to ' + path + ': ' + str(e));
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
766
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
767 # Builtin commands
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
768
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
769 def build(args):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
770 """compile the Java and C sources, linking the latter
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
771
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
772 Compile all the Java source code using the appropriate compilers
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
773 and linkers for the various source code types."""
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
774
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
775 parser = ArgumentParser(prog='mx build');
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
776 parser.add_argument('-f', action='store_true', dest='force', help='force compilation even if class files are up to date')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
777 parser.add_argument('-c', action='store_true', dest='clean', help='removes existing build output')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
778 parser.add_argument('--no-native', action='store_false', dest='native', help='do not build com.oracle.max.vm.native')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
779 parser.add_argument('--jdt', help='Eclipse installation or path to ecj.jar for using the Eclipse batch compiler instead of javac', metavar='<path>')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
780
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
781 args = parser.parse_args(args)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
782
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
783 jdtJar = None
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
784 if args.jdt is not None:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
785 if args.jdt.endswith('.jar'):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
786 jdtJar=args.jdt
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
787 elif isdir(args.jdt):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
788 plugins = join(args.jdt, 'plugins')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
789 choices = [f for f in os.listdir(plugins) if fnmatch.fnmatch(f, 'org.eclipse.jdt.core_*.jar')]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
790 if len(choices) != 0:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
791 jdtJar = join(plugins, sorted(choices, reverse=True)[0])
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
792
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
793 built = set()
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
794 for p in sorted_deps():
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
795
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
796 if p.native:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
797 log('Compiling C sources in {0}...'.format(p.dir))
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
798
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
799 if args.clean:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
800 run([gmake_cmd(), 'clean'], cwd=p.dir)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
801
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
802 run([gmake_cmd()], cwd=p.dir)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
803 built.add(p.name)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
804 continue
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
805
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
806 outputDir = p.output_dir()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
807 if exists(outputDir):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
808 if args.clean:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
809 log('Cleaning {0}...'.format(outputDir))
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
810 shutil.rmtree(outputDir)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
811 os.mkdir(outputDir)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
812 else:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
813 os.mkdir(outputDir)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
814
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
815 cp = classpath(p.name)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
816 sourceDirs = p.source_dirs()
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
817 mustBuild = args.force
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
818 if not mustBuild:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
819 for dep in p.all_deps([], False):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
820 if dep.name in built:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
821 mustBuild = True
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
822
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
823 for sourceDir in sourceDirs:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
824 javafilelist = []
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
825 nonjavafilelist = []
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
826 for root, _, files in os.walk(sourceDir):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
827 javafiles = [join(root, name) for name in files if name.endswith('.java') and name != 'package-info.java']
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
828 javafilelist += javafiles
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
829 nonjavafilelist += [join(root, name) for name in files if not name.endswith('.java')]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
830 if not mustBuild:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
831 for javafile in javafiles:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
832 classfile = outputDir + javafile[len(sourceDir):-len('java')] + 'class'
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
833 if not exists(classfile) or os.path.getmtime(javafile) > os.path.getmtime(classfile):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
834 mustBuild = True
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
835 break
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
836
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
837 if not mustBuild:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
838 log('[all class files in {0} are up to date - skipping]'.format(sourceDir))
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
839 continue
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
840
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
841 if len(javafilelist) == 0:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
842 log('[no Java sources in {0} - skipping]'.format(sourceDir))
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
843 continue
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
844
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
845 built.add(p.name)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
846
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
847 argfileName = join(p.dir, 'javafilelist.txt')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
848 argfile = open(argfileName, 'w')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
849 argfile.write('\n'.join(javafilelist))
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
850 argfile.close()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
851
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
852 try:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
853 if jdtJar is None:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
854 log('Compiling Java sources in {0} with javac...'.format(sourceDir))
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
855
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
856 class Filter:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
857 """
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
858 Class to filter the 'is Sun proprietary API and may be removed in a future release'
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
859 warning when compiling the VM classes.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
860
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
861 """
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
862 def __init__(self):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
863 self.c = 0
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
864
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
865 def eat(self, line):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
866 if 'Sun proprietary API' in line:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
867 self.c = 2
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
868 elif self.c != 0:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
869 self.c -= 1
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
870 else:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
871 print line.rstrip()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
872
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
873 run([_opts.javac, '-g', '-J-Xmx1g', '-classpath', cp, '-d', outputDir, '@' + argfile.name], err=Filter().eat)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
874 else:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
875 log('Compiling Java sources in {0} with JDT...'.format(sourceDir))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
876 jdtProperties = join(p.dir, '.settings', 'org.eclipse.jdt.core.prefs')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
877 if not exists(jdtProperties):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
878 raise SystemError('JDT properties file {0} not found'.format(jdtProperties))
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
879 run([_opts.java, '-Xmx1g', '-jar', jdtJar, '-1.6', '-cp', cp, '-g',
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
880 '-properties', jdtProperties,
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
881 '-warn:-unusedImport,-unchecked',
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
882 '-d', outputDir, '@' + argfile.name])
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
883 finally:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
884 os.remove(argfileName)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
885
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
886
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
887 for name in nonjavafilelist:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
888 dst = join(outputDir, name[len(sourceDir) + 1:])
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
889 if exists(dirname(dst)):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
890 shutil.copyfile(name, dst)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
891
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
892 def canonicalizeprojects(args):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
893 """process all project files to canonicalize the dependencies
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
894
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
895 The exit code of this command reflects how many files were updated."""
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
896
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
897 changedFiles = 0
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
898 for s in suites():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
899 projectsFile = join(s.dir, 'mx', 'projects')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
900 if not exists(projectsFile):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
901 continue
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
902 with open(projectsFile) as f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
903 out = StringIO.StringIO()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
904 pattern = re.compile('project@([^@]+)@dependencies=.*')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
905 for line in f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
906 line = line.strip()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
907 m = pattern.match(line)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
908 if m is None:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
909 out.write(line + '\n')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
910 else:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
911 p = project(m.group(1))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
912 out.write('project@' + m.group(1) + '@dependencies=' + ','.join(p.canonical_deps()) + '\n')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
913 content = out.getvalue()
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
914 if update_file(projectsFile, content):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
915 changedFiles += 1
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
916 return changedFiles;
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
917
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
918 def checkstyle(args):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
919 """run Checkstyle on the Java sources
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
920
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
921 Run Checkstyle over the Java sources. Any errors or warnings
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
922 produced by Checkstyle result in a non-zero exit code.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
923
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
924 If no projects are given, then all Java projects are checked."""
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
925
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
926 for p in sorted_deps():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
927 if p.native:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
928 continue
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
929 sourceDirs = p.source_dirs()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
930 dotCheckstyle = join(p.dir, '.checkstyle')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
931
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
932 if not exists(dotCheckstyle):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
933 continue
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
934
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
935 for sourceDir in sourceDirs:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
936 javafilelist = []
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
937 for root, _, files in os.walk(sourceDir):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
938 javafilelist += [join(root, name) for name in files if name.endswith('.java') and name != 'package-info.java']
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
939 if len(javafilelist) == 0:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
940 log('[no Java sources in {0} - skipping]'.format(sourceDir))
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
941 continue
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
942
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
943 timestampFile = join(p.suite.dir, 'mx', '.checkstyle' + sourceDir[len(p.suite.dir):].replace(os.sep, '_') + '.timestamp')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
944 mustCheck = False
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
945 if exists(timestampFile):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
946 timestamp = os.path.getmtime(timestampFile)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
947 for f in javafilelist:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
948 if os.path.getmtime(f) > timestamp:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
949 mustCheck = True
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
950 break
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
951 else:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
952 mustCheck = True
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
953
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
954 if not mustCheck:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
955 log('[all Java sources in {0} already checked - skipping]'.format(sourceDir))
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
956 continue
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
957
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
958 if exists(timestampFile):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
959 os.utime(timestampFile, None)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
960 else:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
961 file(timestampFile, 'a')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
962
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
963 dotCheckstyleXML = xml.dom.minidom.parse(dotCheckstyle)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
964 localCheckConfig = dotCheckstyleXML.getElementsByTagName('local-check-config')[0]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
965 configLocation = localCheckConfig.getAttribute('location')
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
966 configType = localCheckConfig.getAttribute('type')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
967 if configType == 'project':
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
968 # Eclipse plugin "Project Relative Configuration" format:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
969 #
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
970 # '/<project_name>/<suffix>'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
971 #
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
972 if configLocation.startswith('/'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
973 name, _, suffix = configLocation.lstrip('/').partition('/')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
974 config = join(project(name).dir, suffix)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
975 else:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
976 config = join(p.dir, configLocation)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
977 else:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
978 log('[unknown Checkstyle configuration type "' + configType + '" in {0} - skipping]'.format(sourceDir))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
979 continue
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
980
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
981 exclude = join(p.dir, '.checkstyle.exclude')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
982
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
983 if exists(exclude):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
984 with open(exclude) as f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
985 # Convert patterns to OS separators
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
986 patterns = [name.rstrip().replace('/', os.sep) for name in f.readlines()]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
987 def match(name):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
988 for p in patterns:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
989 if p in name:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
990 log('excluding: ' + name)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
991 return True
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
992 return False
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
993
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
994 javafilelist = [name for name in javafilelist if not match(name)]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
995
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
996 auditfileName = join(p.dir, 'checkstyleOutput.txt')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
997 log('Running Checkstyle on {0} using {1}...'.format(sourceDir, config))
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
998
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
999 try:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1000
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1001 # Checkstyle is unable to read the filenames to process from a file, and the
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1002 # CreateProcess function on Windows limits the length of a command line to
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1003 # 32,768 characters (http://msdn.microsoft.com/en-us/library/ms682425%28VS.85%29.aspx)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1004 # so calling Checkstyle must be done in batches.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1005 while len(javafilelist) != 0:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1006 i = 0
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1007 size = 0
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1008 while i < len(javafilelist):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1009 s = len(javafilelist[i]) + 1
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1010 if (size + s < 30000):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1011 size += s
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1012 i += 1
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1013 else:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1014 break
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1015
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1016 batch = javafilelist[:i]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1017 javafilelist = javafilelist[i:]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1018 try:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1019 run_java(['-Xmx1g', '-jar', library('CHECKSTYLE').get_path(True), '-c', config, '-o', auditfileName] + batch)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1020 finally:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1021 if exists(auditfileName):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1022 with open(auditfileName) as f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1023 warnings = [line.strip() for line in f if 'warning:' in line]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1024 if len(warnings) != 0:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1025 map(log, warnings)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1026 return 1
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1027 finally:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1028 if exists(auditfileName):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1029 os.unlink(auditfileName)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1030 return 0
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1031
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1032 def clean(args):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1033 """remove all class files, images, and executables
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1034
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1035 Removes all files created by a build, including Java class files, executables, and
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1036 generated images.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1037 """
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1038
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1039 for p in projects():
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1040 if p.native:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1041 run([gmake_cmd(), '-C', p.dir, 'clean'])
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1042 else:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1043 outputDir = p.output_dir()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1044 if outputDir != '' and exists(outputDir):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1045 log('Removing {0}...'.format(outputDir))
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1046 shutil.rmtree(outputDir)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1047
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1048 def help_(args):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1049 """show help for a given command
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1050
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1051 With no arguments, print a list of commands and short help for each command.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1052
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1053 Given a command name, print help for that command."""
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1054 if len(args) == 0:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1055 _argParser.print_help()
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1056 return
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1057
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1058 name = args[0]
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1059 if not commands.has_key(name):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1060 _argParser.error('unknown command: ' + name)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1061
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1062 value = commands[name]
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1063 (func, usage) = value[:2]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1064 doc = func.__doc__
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1065 if len(value) > 2:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1066 docArgs = value[2:]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1067 fmtArgs = []
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1068 for d in docArgs:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1069 if isinstance(d, Callable):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1070 fmtArgs += [d()]
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1071 else:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1072 fmtArgs += [str(d)]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1073 doc = doc.format(*fmtArgs)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1074 print 'mx {0} {1}\n\n{2}\n'.format(name, usage, doc)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1075
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1076
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1077 # Commands are in alphabetical order in this file.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1078
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1079 def javap(args):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1080 """launch javap with a -classpath option denoting all available classes
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1081
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1082 Run the JDK javap class file disassembler with the following prepended options:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1083
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1084 -private -verbose -classpath <path to project classes>"""
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1085
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1086 javap = _opts.javap
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1087 if not exists(javap):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1088 abort('The javap executable does not exists: ' + javap)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1089 else:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1090 run([javap, '-private', '-verbose', '-classpath', classpath()] + args)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1091
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1092 def show_projects(args):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1093 """show all loaded projects"""
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1094 for s in suites():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1095 projectsFile = join(s.dir, 'mx', 'projects')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1096 if exists(projectsFile):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1097 log(projectsFile)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1098 for p in s.projects:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1099 log('\t' + p.name)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1100
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1101 def add_argument(*args, **kwargs):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1102 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1103 Define how a single command-line argument.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1104 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1105 assert _argParser is not None
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1106 _argParser.add_argument(*args, **kwargs)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1107
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1108 # Table of commands in alphabetical order.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1109 # Keys are command names, value are lists: [<function>, <usage msg>, <format args to doc string of function>...]
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1110 # If any of the format args are instances of Callable, then they are called with an 'env' are before being
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1111 # used in the call to str.format().
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1112 # Extensions should update this table directly
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1113 commands = {
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1114 'build': [build, '[options] projects...'],
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1115 'checkstyle': [checkstyle, 'projects...'],
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1116 'canonicalizeprojects': [canonicalizeprojects, ''],
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1117 'clean': [clean, ''],
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1118 'help': [help_, '[command]'],
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1119 'javap': [javap, ''],
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1120 'projects': [show_projects, ''],
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1121 }
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1122
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1123 _argParser = ArgParser()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1124
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1125 def main():
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1126 MX_INCLUDES = os.environ.get('MX_INCLUDES', None)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1127 if MX_INCLUDES is not None:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1128 for path in MX_INCLUDES.split(os.pathsep):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1129 d = join(path, 'mx')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1130 if exists(d) and isdir(d):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1131 _loadSuite(path)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1132
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1133 cwdMxDir = join(os.getcwd(), 'mx')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1134 if exists(cwdMxDir) and isdir(cwdMxDir):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1135 _loadSuite(os.getcwd(), True)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1136
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1137 opts, commandAndArgs = _argParser._parse_cmd_line()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1138 global _opts
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1139 _opts = opts
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1140
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1141 if len(commandAndArgs) == 0:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1142 _argParser.print_help()
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1143 return
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1144
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1145 command = commandAndArgs[0]
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1146 command_args = commandAndArgs[1:]
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1147
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1148 if not commands.has_key(command):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1149 abort('mx: unknown command \'{0}\'\n{1}use "mx help" for more options'.format(command, _format_commands()))
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1150
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1151 c, _ = commands[command][:2]
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1152 try:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1153 retcode = c(command_args)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1154 if retcode is not None and retcode != 0:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1155 abort(retcode)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1156 except KeyboardInterrupt:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1157 # no need to show the stack trace when the user presses CTRL-C
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1158 abort(1)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1159
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1160 if __name__ == '__main__':
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1161 # rename this module as 'mx' so it is not imported twice by the commands.py modules
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1162 sys.modules['mx'] = sys.modules.pop('__main__')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1163
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1164 main()