Mercurial > hg > truffle
annotate mxtool/mx.py @ 3728:6ee0eac858c1
Added tag test4 for changeset 031fea7c05fe
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Fri, 16 Dec 2011 19:49:22 +0100 |
parents | 6c5f528c7aac |
children | 3e2e8b8abdaf |
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 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
105 class Dependency: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
106 def __init__(self, name, baseDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
107 self.name = name |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
108 self.baseDir = baseDir |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
109 self.env = None |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
110 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
111 def __str__(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
112 return self.name |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
113 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
114 def __eq__(self, other): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
115 return self.name == other.name |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
116 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
117 def __ne__(self, other): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
118 return self.name != other.name |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
119 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
120 def __hash__(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
121 return hash(self.name) |
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 isLibrary(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
124 return isinstance(self, Library) |
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 class Project(Dependency): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
127 def __init__(self, baseDir, name, srcDirs, deps): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
128 Dependency.__init__(self, name, baseDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
129 self.srcDirs = srcDirs |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
130 self.deps = deps |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
131 self.checkstyleProj = name |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
132 self.dir = join(baseDir, name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
133 self.native = False |
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 all_deps(self, deps, pdb, includeLibs): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
136 if self in deps: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
137 return deps |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
138 for name in self.deps: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
139 assert name != self.name |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
140 dep = pdb.libs.get(name, None) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
141 if dep is not None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
142 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
|
143 deps.append(dep) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
144 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
145 dep = pdb.project(name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
146 if not dep in deps: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
147 dep.all_deps(deps, pdb, includeLibs) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
148 if not self in deps: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
149 deps.append(self) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
150 return deps |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
151 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
152 def _compute_max_dep_distances(self, name, distances, dist, pdb): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
153 currentDist = distances.get(name); |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
154 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
|
155 distances[name] = dist |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
156 if pdb.projects.has_key(name): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
157 p = pdb.project(name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
158 for dep in p.deps: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
159 self._compute_max_dep_distances(dep, distances, dist + 1, pdb) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
160 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
161 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
162 def canonical_deps(self, env, pdb): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
163 distances = dict() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
164 result = set() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
165 self._compute_max_dep_distances(self.name, distances, 0, pdb) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
166 for n,d in distances.iteritems(): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
167 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
|
168 if d == 1: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
169 result.add(n) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
170 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
171 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
172 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
|
173 return self.deps |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
174 return result; |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
175 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
176 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
177 def source_dirs(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
178 return [join(self.baseDir, self.name, s) for s in self.srcDirs] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
179 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
180 def output_dir(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
181 return join(self.baseDir, self.name, 'bin') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
182 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
183 def classpath(self, resolve, env): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
184 classesDir = join(self.baseDir, 'classes') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
185 if exists(classesDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
186 return [self.output_dir(), classesDir] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
187 return [self.output_dir()] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
188 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
189 |
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 class Library(Dependency): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
192 def __init__(self, baseDir, name, path, mustExist, urls): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
193 Dependency.__init__(self, name, baseDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
194 self.path = path |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
195 self.urls = urls |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
196 self.mustExist = mustExist |
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 classpath(self, resolve, env): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
199 path = self.path |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
200 if not isabs(path): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
201 path = join(self.baseDir, path) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
202 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
|
203 assert not len(self.urls) == 0, 'cannot find required library ' + self.name + " " + path; |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
204 env.download(path, self.urls) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
205 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
206 if exists(path) or not resolve: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
207 return [path] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
208 return [] |
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 ProjectsDB(): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
211 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
212 def __init__(self, env): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
213 self.env = env |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
214 self.projects = dict() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
215 self.libs = dict() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
216 self.commandModules = dict() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
217 self.baseDirs = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
218 self.primary = '' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
219 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
220 def _load_projects(self, mxDir, baseDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
221 env = self.env |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
222 libsMap = dict() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
223 projsMap = dict() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
224 projectsFile = join(mxDir, 'projects') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
225 if not exists(projectsFile): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
226 return |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
227 with open(projectsFile) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
228 for line in f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
229 line = line.strip() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
230 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
|
231 key, value = line.split('=', 1) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
232 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
233 parts = key.split('@') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
234 if len(parts) != 3: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
235 env.abort('Property name does not have 3 parts separated by "@": ' + key) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
236 kind, name, attr = parts |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
237 if kind == 'project': |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
238 m = projsMap |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
239 elif kind == 'library': |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
240 m = libsMap |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
241 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
242 env.abort('Property name does not start with "project@" or "library@": ' + key) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
243 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
244 attrs = m.get(name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
245 if attrs is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
246 attrs = dict() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
247 m[name] = attrs |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
248 value = env.expandvars_in_property(value) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
249 attrs[attr] = value |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
250 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
251 def pop_list(attrs, name): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
252 v = attrs.pop(name, None) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
253 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
|
254 return [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
255 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
|
256 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
257 for name, attrs in projsMap.iteritems(): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
258 if self.projects.has_key(name): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
259 env.abort('cannot override project ' + name + ' in ' + self.project(name).baseDir + " with project of the same name in " + mxDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
260 srcDirs = pop_list(attrs, 'sourceDirs') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
261 deps = pop_list(attrs, 'dependencies') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
262 p = Project(baseDir, name, srcDirs, deps) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
263 p.checkstyleProj = attrs.pop('checkstyle', name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
264 p.native = attrs.pop('native', '') == 'true' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
265 p.__dict__.update(attrs) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
266 self.projects[name] = p |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
267 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
268 for name, attrs in libsMap.iteritems(): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
269 if self.libs.has_key(name): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
270 env.abort('cannot redefine library ' + name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
271 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
272 path = attrs['path'] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
273 mustExist = attrs.pop('optional', 'false') != 'true' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
274 urls = pop_list(attrs, 'urls') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
275 l = Library(baseDir, name, path, mustExist, urls) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
276 l.__dict__.update(attrs) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
277 self.libs[name] = l |
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 def _load_commands(self, mxDir, baseDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
280 env = self.env |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
281 commands = join(mxDir, 'commands.py') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
282 if exists(commands): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
283 # temporarily extend the Python path |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
284 sys.path.insert(0, mxDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
285 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
286 mod = __import__('commands') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
287 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
288 # revert the Python path |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
289 del sys.path[0] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
290 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
291 if not hasattr(mod, 'mx_init'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
292 env.abort(commands + ' must define an mx_init(env) function') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
293 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
294 mod.mx_init(env) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
295 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
296 name = baseDir + '.commands' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
297 sfx = 1 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
298 while sys.modules.has_key(name): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
299 name = baseDir + str(sfx) + '.commands' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
300 sfx += 1 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
301 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
302 sys.modules[name] = sys.modules.pop('commands') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
303 self.commandModules[name] = mod |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
304 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
305 def _load_includes(self, mxDir, baseDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
306 includes = join(mxDir, 'includes') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
307 if exists(includes): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
308 with open(includes) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
309 for line in f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
310 includeMxDir = join(self.env.expandvars_in_property(line.strip()), 'mx') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
311 self.load(includeMxDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
312 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
313 def _load_env(self, mxDir, baseDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
314 env = join(mxDir, 'env') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
315 if exists(env): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
316 with open(env) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
317 for line in f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
318 line = line.strip() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
319 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
|
320 key, value = line.split('=', 1) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
321 os.environ[key.strip()] = self.env.expandvars_in_property(value.strip()) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
322 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
323 def load(self, mxDir, primary=False): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
324 """ loads the mx data from a given directory """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
325 if not exists(mxDir) or not isdir(mxDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
326 self.env.abort('Directory does not exist: ' + mxDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
327 baseDir = dirname(mxDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
328 if primary: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
329 self.primary = baseDir |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
330 if not baseDir in self.baseDirs: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
331 self.baseDirs.append(baseDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
332 self._load_includes(mxDir, baseDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
333 self._load_projects(mxDir, baseDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
334 self._load_env(mxDir, baseDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
335 if primary: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
336 self._load_commands(mxDir, baseDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
337 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
338 def project_names(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
339 return ' '.join(self.projects.keys()) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
340 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
341 def project(self, name, fatalIfMissing=True): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
342 p = self.projects.get(name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
343 if p is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
344 self.env.abort('project named ' + name + ' not found') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
345 return p |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
346 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
347 def library(self, name): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
348 l = self.libs.get(name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
349 if l is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
350 self.env.abort('library named ' + name + ' not found') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
351 return l |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
352 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
353 def _as_classpath(self, deps, resolve): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
354 cp = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
355 if self.env.cp_prefix is not None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
356 cp = [self.env.cp_prefix] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
357 for d in deps: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
358 cp += d.classpath(resolve, self.env) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
359 if self.env.cp_suffix is not None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
360 cp += [self.env.cp_suffix] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
361 return os.pathsep.join(cp) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
362 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
363 def classpath(self, names=None, resolve=True): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
364 if names is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
365 return self._as_classpath(self.sorted_deps(True), resolve) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
366 deps = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
367 if isinstance(names, types.StringTypes): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
368 self.project(names).all_deps(deps, self, True) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
369 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
370 for n in names: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
371 self.project(n).all_deps(deps, self, True) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
372 return self._as_classpath(deps, resolve) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
373 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
374 def sorted_deps(self, includeLibs=False): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
375 deps = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
376 for p in self.projects.itervalues(): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
377 p.all_deps(deps, self, includeLibs) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
378 return deps |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
379 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
380 class Env(ArgumentParser): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
381 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
382 def format_commands(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
383 msg = '\navailable commands:\n\n' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
384 for cmd in sorted(self.commands.iterkeys()): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
385 c, _ = self.commands[cmd][:2] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
386 doc = c.__doc__ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
387 if doc is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
388 doc = '' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
389 msg += ' {0:<20} {1}\n'.format(cmd, doc.split('\n', 1)[0]) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
390 return msg + '\n' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
391 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
392 # 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
|
393 def format_help(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
394 return ArgumentParser.format_help(self) + self.format_commands() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
395 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
396 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
397 def __init__(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
398 self.java_initialized = False |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
399 self.pdb = ProjectsDB(self) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
400 self.commands = dict() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
401 ArgumentParser.__init__(self, prog='mx') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
402 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
403 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
|
404 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
|
405 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
|
406 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
|
407 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
|
408 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
|
409 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
|
410 self.add_argument('--user-home', help='users home directory', metavar='<path>', default=os.path.expanduser('~')) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
411 self.add_argument('--java-home', help='JDK installation directory (must be JDK 6 or later)', metavar='<path>', default=self.default_java_home()) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
412 self.add_argument('--java', help='Java VM executable (default: bin/java under $JAVA_HOME)', metavar='<path>') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
413 self.add_argument('--os', dest='os', help='operating system override') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
414 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
415 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
|
416 if args is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
417 args = sys.argv[1:] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
418 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
419 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
|
420 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
421 self.parse_args(namespace=self) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
422 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
423 if self.java_home is None or self.java_home == '': |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
424 self.abort('Could not find Java home. Use --java-home option or ensure JAVA_HOME environment variable is set.') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
425 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
426 if self.user_home is None or self.user_home == '': |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
427 self.abort('Could not find user home. Use --user-home option or ensure HOME environment variable is set.') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
428 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
429 if self.os is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
430 self.remote = False |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
431 if sys.platform.startswith('darwin'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
432 self.os = 'darwin' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
433 elif sys.platform.startswith('linux'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
434 self.os = 'linux' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
435 elif sys.platform.startswith('sunos'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
436 self.os = 'solaris' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
437 elif sys.platform.startswith('win32') or sys.platform.startswith('cygwin'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
438 self.os = 'windows' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
439 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
440 print 'Supported operating system could not be derived from', sys.platform, '- use --os option explicitly.' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
441 sys.exit(1) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
442 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
443 self.java_args += ' -Dmax.os=' + self.os |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
444 self.remote = True |
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 if self.java is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
447 self.java = join(self.java_home, 'bin', 'java') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
448 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
449 os.environ['JAVA_HOME'] = self.java_home |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
450 os.environ['HOME'] = self.user_home |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
451 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
452 self.javac = join(self.java_home, 'bin', 'javac') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
453 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
454 for mod in self.pdb.commandModules.itervalues(): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
455 if hasattr(mod, 'mx_post_parse_cmd_line'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
456 mod.mx_post_parse_cmd_line(self) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
457 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
458 def expandvars_in_property(self, value): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
459 result = expandvars(value) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
460 if '$' in result or '%' in result: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
461 self.abort('Property contains an undefined environment variable: ' + value) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
462 return result |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
463 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
464 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
465 def load_config_file(self, configFile, override=False): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
466 """ adds attributes to this object from a file containing key=value lines """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
467 if exists(configFile): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
468 with open(configFile) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
469 for line in f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
470 k, v = line.split('=', 1) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
471 k = k.strip().lower() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
472 if (override or not hasattr(self, k)): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
473 setattr(self, k, self.expandvars_in_property(v.strip())) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
474 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
475 def format_java_cmd(self, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
476 self.init_java() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
477 return [self.java] + self.java_args_pfx + self.java_args + self.java_args_sfx + args |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
478 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
479 def run_java(self, args, nonZeroIsFatal=True, out=None, err=None, cwd=None): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
480 return self.run(self.format_java_cmd(args), nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
481 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
482 def run(self, args, nonZeroIsFatal=True, out=None, err=None, cwd=None): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
483 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
484 Run a command in a subprocess, wait for it to complete and return the exit status of the process. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
485 If the exit status is non-zero and `nonZeroIsFatal` is true, then the program is exited with |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
486 the same exit status. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
487 Each line of the standard output and error streams of the subprocess are redirected to the |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
488 provided out and err functions if they are not None. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
489 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
490 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
491 assert isinstance(args, types.ListType), "'args' must be a list: " + str(args) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
492 for arg in args: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
493 assert isinstance(arg, types.StringTypes), 'argument is not a string: ' + str(arg) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
494 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
495 if self.verbose: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
496 self.log(' '.join(args)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
497 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
498 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
499 if out is None and err is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
500 retcode = subprocess.call(args, cwd=cwd) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
501 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
502 def redirect(stream, f): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
503 for line in iter(stream.readline, ''): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
504 f(line) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
505 stream.close() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
506 p = subprocess.Popen(args, cwd=cwd, stdout=None if out is None else subprocess.PIPE, stderr=None if err is None else subprocess.PIPE) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
507 if out is not None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
508 t = Thread(target=redirect, args=(p.stdout, out)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
509 t.daemon = True # thread dies with the program |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
510 t.start() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
511 if err is not None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
512 t = Thread(target=redirect, args=(p.stderr, err)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
513 t.daemon = True # thread dies with the program |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
514 t.start() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
515 retcode = p.wait() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
516 except OSError as e: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
517 self.log('Error executing \'' + ' '.join(args) + '\': ' + str(e)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
518 if self.verbose: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
519 raise e |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
520 self.abort(e.errno) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
521 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
522 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
523 if retcode and nonZeroIsFatal: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
524 if self.verbose: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
525 raise subprocess.CalledProcessError(retcode, ' '.join(args)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
526 self.abort(retcode) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
527 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
528 return retcode |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
529 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
530 def check_get_env(self, key): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
531 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
532 Gets an environment variable, aborting with a useful message if it is not set. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
533 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
534 value = os.environ.get(key) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
535 if value is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
536 self.abort('Required environment variable ' + key + ' must be set (e.g. in ' + join(self.pdb.primary, 'env') + ')') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
537 return value |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
538 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
539 def exe_suffix(self, name): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
540 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
541 Gets the platform specific suffix for an executable |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
542 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
543 if self.os == 'windows': |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
544 return name + '.exe' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
545 return name |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
546 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
547 def log(self, msg=None): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
548 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
549 Write a message to the console. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
550 All script output goes through this method thus allowing a subclass |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
551 to redirect it. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
552 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
553 if msg is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
554 print |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
555 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
556 print msg |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
557 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
558 def expand_project_in_class_path_arg(self, cpArg): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
559 cp = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
560 for part in cpArg.split(os.pathsep): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
561 if part.startswith('@'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
562 cp += self.pdb.classpath(part[1:]).split(os.pathsep) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
563 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
564 cp.append(part) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
565 return os.pathsep.join(cp) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
566 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
567 def expand_project_in_args(self, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
568 for i in range(len(args)): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
569 if args[i] == '-cp' or args[i] == '-classpath': |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
570 if i + 1 < len(args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
571 args[i + 1] = self.expand_project_in_class_path_arg(args[i + 1]) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
572 return |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
573 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
574 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
575 def init_java(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
576 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
577 Lazy initialization and preprocessing of this object's fields before running a Java command. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
578 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
579 if self.java_initialized: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
580 return |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
581 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
582 def delAtAndSplit(s): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
583 return shlex.split(s.lstrip('@')) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
584 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
585 self.java_args = delAtAndSplit(self.java_args) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
586 self.java_args_pfx = sum(map(delAtAndSplit, self.java_args_pfx), []) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
587 self.java_args_sfx = sum(map(delAtAndSplit, self.java_args_sfx), []) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
588 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
589 # Prepend the -d64 VM option only if the java command supports it |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
590 output = '' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
591 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
592 output = subprocess.check_output([self.java, '-d64', '-version'], stderr=subprocess.STDOUT) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
593 self.java_args = ['-d64'] + self.java_args |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
594 except subprocess.CalledProcessError as e: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
595 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
596 output = subprocess.check_output([self.java, '-version'], stderr=subprocess.STDOUT) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
597 except subprocess.CalledProcessError as e: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
598 print e.output |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
599 self.abort(e.returncode) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
600 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
601 output = output.split() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
602 assert output[0] == 'java' or output[0] == 'openjdk' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
603 assert output[1] == 'version' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
604 version = output[2] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
605 if not version.startswith('"1.6') and not version.startswith('"1.7'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
606 self.abort('Requires Java version 1.6 or 1.7, got version ' + version) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
607 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
608 if self.java_dbg: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
609 self.java_args += ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000'] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
610 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
611 self.java_initialized = True |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
612 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
613 def default_java_home(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
614 javaHome = os.getenv('JAVA_HOME') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
615 if javaHome is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
616 if exists('/usr/lib/java/java-6-sun'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
617 javaHome = '/usr/lib/java/java-6-sun' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
618 elif exists('/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
619 javaHome = '/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
620 elif exists('/usr/jdk/latest'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
621 javaHome = '/usr/jdk/latest' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
622 return javaHome |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
623 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
624 def gmake_cmd(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
625 for a in ['make', 'gmake', 'gnumake']: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
626 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
627 output = subprocess.check_output([a, '--version']) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
628 if 'GNU' in output: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
629 return a; |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
630 except: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
631 pass |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
632 self.abort('Could not find a GNU make executable on the current path.') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
633 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
634 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
635 def abort(self, codeOrMessage): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
636 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
637 Aborts the program with a SystemExit exception. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
638 If 'codeOrMessage' is a plain integer, it specifies the system exit status; |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
639 if it is None, the exit status is zero; if it has another type (such as a string), |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
640 the object's value is printed and the exit status is one. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
641 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
642 raise SystemExit(codeOrMessage) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
643 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
644 def download(self, path, urls): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
645 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
646 Attempts to downloads content for each URL in a list, stopping after the first successful download. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
647 If the content cannot be retrieved from any URL, the program is aborted. The downloaded content |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
648 is written to the file indicated by 'path'. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
649 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
650 d = dirname(path) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
651 if d != '' and not exists(d): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
652 os.makedirs(d) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
653 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
654 def url_open(url): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
655 userAgent = 'Mozilla/5.0 (compatible)' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
656 headers = { 'User-Agent' : userAgent } |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
657 req = urllib2.Request(url, headers=headers) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
658 return urllib2.urlopen(req); |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
659 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
660 for url in urls: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
661 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
662 self.log('Downloading ' + url + ' to ' + path) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
663 if url.startswith('zip:') or url.startswith('jar:'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
664 i = url.find('!/') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
665 if i == -1: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
666 self.abort('Zip or jar URL does not contain "!/": ' + url) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
667 url, _, entry = url[len('zip:'):].partition('!/') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
668 with contextlib.closing(url_open(url)) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
669 data = f.read() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
670 zipdata = StringIO.StringIO(f.read()) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
671 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
672 zf = zipfile.ZipFile(zipdata, 'r') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
673 data = zf.read(entry) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
674 with open(path, 'w') as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
675 f.write(data) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
676 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
677 with contextlib.closing(url_open(url)) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
678 data = f.read() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
679 with open(path, 'w') as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
680 f.write(data) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
681 return |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
682 except IOError as e: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
683 self.log('Error reading from ' + url + ': ' + str(e)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
684 except zipfile.BadZipfile as e: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
685 self.log('Error in zip file downloaded from ' + url + ': ' + str(e)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
686 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
687 # now try it with Java - urllib2 does not handle meta refreshes which are used by Sourceforge |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
688 myDir = dirname(__file__) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
689 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
690 javaSource = join(myDir, 'URLConnectionDownload.java') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
691 javaClass = join(myDir, 'URLConnectionDownload.class') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
692 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
693 subprocess.check_call([self.javac, '-d', myDir, javaSource]) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
694 if self.run([self.java, '-cp', myDir, 'URLConnectionDownload', path] + urls) != 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
695 self.abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' + |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
696 '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
697 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
698 def update_file(self, path, content): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
699 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
700 Updates a file with some given content if the content differs from what's in |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
701 the file already. The return value indicates if the file was updated. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
702 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
703 existed = exists(path) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
704 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
705 old = None |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
706 if existed: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
707 with open(path) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
708 old = f.read() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
709 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
710 if old == content: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
711 return False |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
712 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
713 with open(path, 'w') as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
714 f.write(content) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
715 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
716 self.log(('modified ' if existed else 'created ') + path) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
717 return True; |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
718 except IOError as e: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
719 self.abort('Error while writing to ' + path + ': ' + str(e)); |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
720 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
721 # Builtin commands |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
722 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
723 def build(env, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
724 """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
|
725 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
726 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
|
727 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
|
728 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
729 parser = ArgumentParser(prog='mx build'); |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
730 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
|
731 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
|
732 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
|
733 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
|
734 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
735 args = parser.parse_args(args) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
736 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
737 jdtJar = None |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
738 if args.jdt is not None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
739 if args.jdt.endswith('.jar'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
740 jdtJar=args.jdt |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
741 elif isdir(args.jdt): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
742 plugins = join(args.jdt, 'plugins') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
743 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
|
744 if len(choices) != 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
745 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
|
746 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
747 projects = [p.name for p in env.pdb.sorted_deps()] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
748 built = set() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
749 for project in projects: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
750 p = env.pdb.project(project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
751 projectDir = join(p.baseDir, project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
752 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
753 if p.native: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
754 if env.os == 'windows': |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
755 env.log('Skipping C compilation on Windows until it is supported') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
756 pass |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
757 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
758 env.log('Compiling C sources in {0}...'.format(projectDir)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
759 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
760 if args.clean: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
761 env.run([env.gmake_cmd(), 'clean'], cwd=projectDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
762 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
763 env.run([env.gmake_cmd()], cwd=projectDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
764 built.add(project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
765 continue |
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 outputDir = p.output_dir() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
768 if exists(outputDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
769 if args.clean: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
770 env.log('Cleaning {0}...'.format(outputDir)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
771 shutil.rmtree(outputDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
772 os.mkdir(outputDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
773 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
774 os.mkdir(outputDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
775 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
776 classpath = env.pdb.classpath(project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
777 sourceDirs = env.pdb.project(project).source_dirs() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
778 mustBuild = args.force |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
779 if not mustBuild: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
780 for dep in p.all_deps([], env.pdb, False): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
781 if dep.name in built: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
782 mustBuild = True |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
783 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
784 for sourceDir in sourceDirs: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
785 javafilelist = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
786 nonjavafilelist = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
787 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
|
788 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
|
789 javafilelist += javafiles |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
790 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
|
791 if not mustBuild: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
792 for javafile in javafiles: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
793 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
|
794 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
|
795 mustBuild = True |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
796 break |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
797 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
798 if not mustBuild: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
799 env.log('[all class files in {0} are up to date - skipping]'.format(sourceDir)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
800 continue |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
801 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
802 if len(javafilelist) == 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
803 env.log('[no Java sources in {0} - skipping]'.format(sourceDir)) |
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 built.add(project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
807 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
808 argfileName = join(projectDir, 'javafilelist.txt') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
809 argfile = open(argfileName, 'w') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
810 argfile.write('\n'.join(javafilelist)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
811 argfile.close() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
812 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
813 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
814 if jdtJar is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
815 env.log('Compiling Java sources in {0} with javac...'.format(sourceDir)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
816 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
817 class Filter: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
818 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
819 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
|
820 warning when compiling the VM classes. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
821 |
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 def __init__(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
824 self.c = 0 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
825 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
826 def eat(self, line): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
827 if 'Sun proprietary API' in line: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
828 self.c = 2 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
829 elif self.c != 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
830 self.c -= 1 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
831 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
832 print line.rstrip() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
833 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
834 env.run([env.javac, '-g', '-J-Xmx1g', '-classpath', classpath, '-d', outputDir, '@' + argfile.name], err=Filter().eat) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
835 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
836 env.log('Compiling Java sources in {0} with JDT...'.format(sourceDir)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
837 jdtProperties = join(projectDir, '.settings', 'org.eclipse.jdt.core.prefs') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
838 if not exists(jdtProperties): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
839 raise SystemError('JDT properties file {0} not found'.format(jdtProperties)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
840 env.run([env.java, '-Xmx1g', '-jar', jdtJar, '-1.6', '-cp', classpath, '-g', |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
841 '-properties', jdtProperties, |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
842 '-warn:-unusedImport,-unchecked', |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
843 '-d', outputDir, '@' + argfile.name]) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
844 finally: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
845 os.remove(argfileName) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
846 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
847 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
848 for name in nonjavafilelist: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
849 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
|
850 if exists(dirname(dst)): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
851 shutil.copyfile(name, dst) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
852 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
853 def canonicalizeprojects(env, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
854 """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
|
855 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
856 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
|
857 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
858 changedFiles = 0 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
859 pdb = env.pdb |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
860 for d in pdb.baseDirs: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
861 projectsFile = join(d, 'mx', 'projects') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
862 if not exists(projectsFile): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
863 continue |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
864 with open(projectsFile) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
865 out = StringIO.StringIO() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
866 pattern = re.compile('project@([^@]+)@dependencies=.*') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
867 for line in f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
868 line = line.strip() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
869 m = pattern.match(line) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
870 if m is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
871 out.write(line + '\n') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
872 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
873 p = pdb.project(m.group(1)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
874 out.write('project@' + m.group(1) + '@dependencies=' + ','.join(p.canonical_deps(env, pdb)) + '\n') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
875 content = out.getvalue() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
876 if env.update_file(projectsFile, content): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
877 changedFiles += 1 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
878 return changedFiles; |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
879 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
880 def checkstyle(env, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
881 """run Checkstyle on the Java sources |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
882 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
883 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
|
884 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
|
885 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
886 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
|
887 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
888 allProjects = [p.name for p in env.pdb.sorted_deps()] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
889 if len(args) == 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
890 projects = allProjects |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
891 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
892 projects = args |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
893 unknown = set(projects).difference(allProjects) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
894 if len(unknown) != 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
895 env.error('unknown projects: ' + ', '.join(unknown)) |
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 for project in projects: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
898 p = env.pdb.project(project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
899 projectDir = join(p.baseDir, project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
900 sourceDirs = env.pdb.project(project).source_dirs() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
901 dotCheckstyle = join(projectDir, '.checkstyle') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
902 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
903 if not exists(dotCheckstyle): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
904 continue |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
905 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
906 for sourceDir in sourceDirs: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
907 javafilelist = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
908 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
|
909 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
|
910 if len(javafilelist) == 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
911 env.log('[no Java sources in {0} - skipping]'.format(sourceDir)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
912 continue |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
913 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
914 timestampFile = join(p.baseDir, 'mx', '.checkstyle' + sourceDir[len(p.baseDir):].replace(os.sep, '_') + '.timestamp') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
915 mustCheck = False |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
916 if exists(timestampFile): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
917 timestamp = os.path.getmtime(timestampFile) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
918 for f in javafilelist: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
919 if os.path.getmtime(f) > timestamp: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
920 mustCheck = True |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
921 break |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
922 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
923 mustCheck = True |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
924 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
925 if not mustCheck: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
926 env.log('[all Java sources in {0} already checked - skipping]'.format(sourceDir)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
927 continue |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
928 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
929 if exists(timestampFile): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
930 os.utime(timestampFile, None) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
931 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
932 file(timestampFile, 'a') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
933 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
934 dotCheckstyleXML = xml.dom.minidom.parse(dotCheckstyle) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
935 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
|
936 configLocation = localCheckConfig.getAttribute('location') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
937 if configLocation.startswith('/'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
938 config = join(p.baseDir, configLocation.lstrip('/')) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
939 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
940 config = join(projectDir, configLocation) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
941 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
942 exclude = join(projectDir, '.checkstyle.exclude') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
943 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
944 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
945 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
946 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
947 if exists(exclude): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
948 with open(exclude) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
949 # Convert patterns to OS separators |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
950 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
|
951 def match(name): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
952 for p in patterns: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
953 if p in name: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
954 env.log('excluding: ' + name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
955 return True |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
956 return False |
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 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
|
959 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
960 auditfileName = join(projectDir, 'checkstyleOutput.txt') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
961 env.log('Running Checkstyle on {0} using {1}...'.format(sourceDir, config)) |
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 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
964 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
965 # 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
|
966 # 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
|
967 # 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
|
968 # 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
|
969 while len(javafilelist) != 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
970 i = 0 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
971 size = 0 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
972 while i < len(javafilelist): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
973 s = len(javafilelist[i]) + 1 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
974 if (size + s < 30000): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
975 size += s |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
976 i += 1 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
977 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
978 break |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
979 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
980 batch = javafilelist[:i] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
981 javafilelist = javafilelist[i:] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
982 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
983 env.run_java(['-Xmx1g', '-jar', env.pdb.library('CHECKSTYLE').classpath(True, env)[0], '-c', config, '-o', auditfileName] + batch) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
984 finally: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
985 if exists(auditfileName): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
986 with open(auditfileName) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
987 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
|
988 if len(warnings) != 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
989 map(env.log, warnings) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
990 return 1 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
991 finally: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
992 if exists(auditfileName): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
993 os.unlink(auditfileName) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
994 return 0 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
995 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
996 def clean(env, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
997 """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
|
998 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
999 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
|
1000 generated images. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1001 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1002 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1003 projects = env.pdb.projects.keys() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1004 for project in projects: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1005 p = env.pdb.project(project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1006 if p.native: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1007 env.run([env.gmake_cmd(), '-C', p.dir, 'clean']) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1008 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1009 outputDir = p.output_dir() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1010 if outputDir != '' and exists(outputDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1011 env.log('Removing {0}...'.format(outputDir)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1012 shutil.rmtree(outputDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1013 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1014 def help_(env, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1015 """show help for a given command |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1016 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1017 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
|
1018 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1019 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
|
1020 if len(args) == 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1021 env.print_help() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1022 return |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1023 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1024 name = args[0] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1025 if not env.commands.has_key(name): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1026 env.error('unknown command: ' + name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1027 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1028 value = env.commands[name] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1029 (func, usage) = value[:2] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1030 doc = func.__doc__ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1031 if len(value) > 2: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1032 docArgs = value[2:] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1033 fmtArgs = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1034 for d in docArgs: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1035 if isinstance(d, Callable): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1036 fmtArgs += [d(env)] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1037 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1038 fmtArgs += [str(d)] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1039 doc = doc.format(*fmtArgs) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1040 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
|
1041 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1042 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1043 # 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
|
1044 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1045 def javap(env, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1046 """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
|
1047 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1048 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
|
1049 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1050 -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
|
1051 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1052 javap = join(env.java_home, 'bin', 'javap') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1053 if not exists(javap): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1054 env.abort('The javap executable does not exists: ' + javap) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1055 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1056 env.run([javap, '-private', '-verbose', '-classpath', env.pdb.classpath()] + args) |
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 def projects(env, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1059 """show all loaded projects""" |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1060 pdb = env.pdb |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1061 for d in pdb.baseDirs: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1062 projectsFile = join(d, 'mx', 'projects') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1063 if exists(projectsFile): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1064 env.log('# file: ' + projectsFile) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1065 for p in pdb.projects.values(): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1066 if p.baseDir == d: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1067 env.log(p.name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1068 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1069 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1070 def main(env): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1071 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1072 # Table of commands in alphabetical order. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1073 # Keys are command names, value are lists: [<function>, <usage msg>, <format args to doc string of function>...] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1074 # If any of the format args are instances of Callable, then they are called with an 'env' are before being |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1075 # used in the call to str.format(). |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1076 # Extensions should update this table directly |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1077 env.commands = { |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1078 'build': [build, '[options] projects...'], |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1079 'checkstyle': [checkstyle, 'projects...'], |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1080 'canonicalizeprojects': [canonicalizeprojects, ''], |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1081 'clean': [clean, ''], |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1082 'help': [help_, '[command]'], |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1083 'javap': [javap, ''], |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1084 'projects': [projects, ''], |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1085 } |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1086 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1087 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
|
1088 if MX_INCLUDES is not None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1089 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
|
1090 d = join(path, 'mx') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1091 if exists(d) and isdir(d): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1092 env.pdb.load(d) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1093 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1094 cwdMxDir = join(os.getcwd(), 'mx') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1095 if exists(cwdMxDir) and isdir(cwdMxDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1096 env.pdb.load(cwdMxDir, primary=True) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1097 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1098 env._parse_cmd_line() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1099 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1100 if len(env.commandAndArgs) == 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1101 env.print_help() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1102 return |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1103 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1104 env.command = env.commandAndArgs[0] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1105 env.command_args = env.commandAndArgs[1:] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1106 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1107 if not env.commands.has_key(env.command): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1108 env.abort('mx: unknown command \'{0}\'\n{1}use "mx help" for more options'.format(env.command, env.format_commands())) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1109 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1110 c, _ = env.commands[env.command][:2] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1111 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1112 retcode = c(env, env.command_args) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1113 if retcode is not None and retcode != 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1114 env.abort(retcode) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1115 except KeyboardInterrupt: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1116 # no need to show the stack trace when the user presses CTRL-C |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1117 env.abort(1) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1118 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1119 if __name__ == '__main__': |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1120 main(Env()) |