Mercurial > hg > truffle
annotate mxtool/mx.py @ 3732:3e2e8b8abdaf
Updated mxtool to allow projects in subdirectories.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Sat, 17 Dec 2011 19:58:27 +0100 |
parents | 6c5f528c7aac |
children | 34527a24bcf8 |
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') |
3732
3e2e8b8abdaf
Updated mxtool to allow projects in subdirectories.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
3723
diff
changeset
|
262 subDir = attrs.pop('subDir', ''); |
3e2e8b8abdaf
Updated mxtool to allow projects in subdirectories.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
3723
diff
changeset
|
263 p = Project(join(baseDir, subDir), name, srcDirs, deps) |
3723
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
264 p.checkstyleProj = attrs.pop('checkstyle', name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
265 p.native = attrs.pop('native', '') == 'true' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
266 p.__dict__.update(attrs) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
267 self.projects[name] = p |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
268 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
269 for name, attrs in libsMap.iteritems(): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
270 if self.libs.has_key(name): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
271 env.abort('cannot redefine library ' + name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
272 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
273 path = attrs['path'] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
274 mustExist = attrs.pop('optional', 'false') != 'true' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
275 urls = pop_list(attrs, 'urls') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
276 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
|
277 l.__dict__.update(attrs) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
278 self.libs[name] = l |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
279 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
280 def _load_commands(self, mxDir, baseDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
281 env = self.env |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
282 commands = join(mxDir, 'commands.py') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
283 if exists(commands): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
284 # temporarily extend the Python path |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
285 sys.path.insert(0, mxDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
286 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
287 mod = __import__('commands') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
288 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
289 # revert the Python path |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
290 del sys.path[0] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
291 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
292 if not hasattr(mod, 'mx_init'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
293 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
|
294 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
295 mod.mx_init(env) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
296 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
297 name = baseDir + '.commands' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
298 sfx = 1 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
299 while sys.modules.has_key(name): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
300 name = baseDir + str(sfx) + '.commands' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
301 sfx += 1 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
302 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
303 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
|
304 self.commandModules[name] = mod |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
305 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
306 def _load_includes(self, mxDir, baseDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
307 includes = join(mxDir, 'includes') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
308 if exists(includes): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
309 with open(includes) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
310 for line in f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
311 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
|
312 self.load(includeMxDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
313 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
314 def _load_env(self, mxDir, baseDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
315 env = join(mxDir, 'env') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
316 if exists(env): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
317 with open(env) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
318 for line in f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
319 line = line.strip() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
320 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
|
321 key, value = line.split('=', 1) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
322 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
|
323 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
324 def load(self, mxDir, primary=False): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
325 """ 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
|
326 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
|
327 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
|
328 baseDir = dirname(mxDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
329 if primary: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
330 self.primary = baseDir |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
331 if not baseDir in self.baseDirs: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
332 self.baseDirs.append(baseDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
333 self._load_includes(mxDir, baseDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
334 self._load_projects(mxDir, baseDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
335 self._load_env(mxDir, baseDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
336 if primary: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
337 self._load_commands(mxDir, baseDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
338 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
339 def project_names(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
340 return ' '.join(self.projects.keys()) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
341 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
342 def project(self, name, fatalIfMissing=True): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
343 p = self.projects.get(name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
344 if p is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
345 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
|
346 return p |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
347 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
348 def library(self, name): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
349 l = self.libs.get(name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
350 if l is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
351 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
|
352 return l |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
353 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
354 def _as_classpath(self, deps, resolve): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
355 cp = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
356 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
|
357 cp = [self.env.cp_prefix] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
358 for d in deps: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
359 cp += d.classpath(resolve, self.env) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
360 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
|
361 cp += [self.env.cp_suffix] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
362 return os.pathsep.join(cp) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
363 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
364 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
|
365 if names is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
366 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
|
367 deps = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
368 if isinstance(names, types.StringTypes): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
369 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
|
370 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
371 for n in names: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
372 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
|
373 return self._as_classpath(deps, resolve) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
374 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
375 def sorted_deps(self, includeLibs=False): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
376 deps = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
377 for p in self.projects.itervalues(): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
378 p.all_deps(deps, self, includeLibs) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
379 return deps |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
380 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
381 class Env(ArgumentParser): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
382 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
383 def format_commands(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
384 msg = '\navailable commands:\n\n' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
385 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
|
386 c, _ = self.commands[cmd][:2] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
387 doc = c.__doc__ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
388 if doc is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
389 doc = '' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
390 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
|
391 return msg + '\n' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
392 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
393 # 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
|
394 def format_help(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
395 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
|
396 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
397 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
398 def __init__(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
399 self.java_initialized = False |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
400 self.pdb = ProjectsDB(self) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
401 self.commands = dict() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
402 ArgumentParser.__init__(self, prog='mx') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
403 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
404 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
|
405 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
|
406 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
|
407 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
|
408 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
|
409 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
|
410 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
|
411 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
|
412 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
|
413 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
|
414 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
|
415 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
416 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
|
417 if args is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
418 args = sys.argv[1:] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
419 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
420 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
|
421 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
422 self.parse_args(namespace=self) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
423 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
424 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
|
425 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
|
426 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
427 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
|
428 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
|
429 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
430 if self.os is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
431 self.remote = False |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
432 if sys.platform.startswith('darwin'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
433 self.os = 'darwin' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
434 elif sys.platform.startswith('linux'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
435 self.os = 'linux' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
436 elif sys.platform.startswith('sunos'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
437 self.os = 'solaris' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
438 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
|
439 self.os = 'windows' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
440 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
441 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
|
442 sys.exit(1) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
443 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
444 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
|
445 self.remote = True |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
446 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
447 if self.java is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
448 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
|
449 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
450 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
|
451 os.environ['HOME'] = self.user_home |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
452 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
453 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
|
454 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
455 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
|
456 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
|
457 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
|
458 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
459 def expandvars_in_property(self, value): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
460 result = expandvars(value) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
461 if '$' in result or '%' in result: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
462 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
|
463 return result |
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 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
466 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
|
467 """ 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
|
468 if exists(configFile): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
469 with open(configFile) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
470 for line in f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
471 k, v = line.split('=', 1) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
472 k = k.strip().lower() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
473 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
|
474 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
|
475 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
476 def format_java_cmd(self, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
477 self.init_java() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
478 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
|
479 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
480 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
|
481 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
|
482 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
483 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
|
484 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
485 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
|
486 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
|
487 the same exit status. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
488 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
|
489 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
|
490 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
491 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
492 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
|
493 for arg in args: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
494 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
|
495 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
496 if self.verbose: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
497 self.log(' '.join(args)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
498 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
499 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
500 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
|
501 retcode = subprocess.call(args, cwd=cwd) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
502 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
503 def redirect(stream, f): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
504 for line in iter(stream.readline, ''): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
505 f(line) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
506 stream.close() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
507 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
|
508 if out is not None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
509 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
|
510 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
|
511 t.start() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
512 if err is not None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
513 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
|
514 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
|
515 t.start() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
516 retcode = p.wait() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
517 except OSError as e: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
518 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
|
519 if self.verbose: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
520 raise e |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
521 self.abort(e.errno) |
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 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
524 if retcode and nonZeroIsFatal: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
525 if self.verbose: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
526 raise subprocess.CalledProcessError(retcode, ' '.join(args)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
527 self.abort(retcode) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
528 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
529 return retcode |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
530 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
531 def check_get_env(self, key): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
532 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
533 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
|
534 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
535 value = os.environ.get(key) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
536 if value is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
537 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
|
538 return value |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
539 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
540 def exe_suffix(self, name): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
541 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
542 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
|
543 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
544 if self.os == 'windows': |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
545 return name + '.exe' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
546 return name |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
547 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
548 def log(self, msg=None): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
549 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
550 Write a message to the console. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
551 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
|
552 to redirect it. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
553 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
554 if msg is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
555 print |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
556 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
557 print msg |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
558 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
559 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
|
560 cp = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
561 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
|
562 if part.startswith('@'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
563 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
|
564 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
565 cp.append(part) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
566 return os.pathsep.join(cp) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
567 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
568 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
|
569 for i in range(len(args)): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
570 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
|
571 if i + 1 < len(args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
572 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
|
573 return |
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 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
576 def init_java(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
577 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
578 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
|
579 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
580 if self.java_initialized: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
581 return |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
582 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
583 def delAtAndSplit(s): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
584 return shlex.split(s.lstrip('@')) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
585 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
586 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
|
587 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
|
588 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
|
589 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
590 # 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
|
591 output = '' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
592 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
593 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
|
594 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
|
595 except subprocess.CalledProcessError as e: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
596 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
597 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
|
598 except subprocess.CalledProcessError as e: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
599 print e.output |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
600 self.abort(e.returncode) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
601 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
602 output = output.split() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
603 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
|
604 assert output[1] == 'version' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
605 version = output[2] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
606 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
|
607 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
|
608 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
609 if self.java_dbg: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
610 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
|
611 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
612 self.java_initialized = True |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
613 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
614 def default_java_home(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
615 javaHome = os.getenv('JAVA_HOME') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
616 if javaHome is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
617 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
|
618 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
|
619 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
|
620 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
|
621 elif exists('/usr/jdk/latest'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
622 javaHome = '/usr/jdk/latest' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
623 return javaHome |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
624 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
625 def gmake_cmd(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
626 for a in ['make', 'gmake', 'gnumake']: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
627 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
628 output = subprocess.check_output([a, '--version']) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
629 if 'GNU' in output: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
630 return a; |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
631 except: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
632 pass |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
633 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
|
634 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
635 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
636 def abort(self, codeOrMessage): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
637 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
638 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
|
639 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
|
640 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
|
641 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
|
642 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
643 raise SystemExit(codeOrMessage) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
644 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
645 def download(self, path, urls): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
646 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
647 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
|
648 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
|
649 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
|
650 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
651 d = dirname(path) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
652 if d != '' and not exists(d): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
653 os.makedirs(d) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
654 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
655 def url_open(url): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
656 userAgent = 'Mozilla/5.0 (compatible)' |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
657 headers = { 'User-Agent' : userAgent } |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
658 req = urllib2.Request(url, headers=headers) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
659 return urllib2.urlopen(req); |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
660 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
661 for url in urls: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
662 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
663 self.log('Downloading ' + url + ' to ' + path) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
664 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
|
665 i = url.find('!/') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
666 if i == -1: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
667 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
|
668 url, _, entry = url[len('zip:'):].partition('!/') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
669 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
|
670 data = f.read() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
671 zipdata = StringIO.StringIO(f.read()) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
672 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
673 zf = zipfile.ZipFile(zipdata, 'r') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
674 data = zf.read(entry) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
675 with open(path, 'w') as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
676 f.write(data) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
677 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
678 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
|
679 data = f.read() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
680 with open(path, 'w') as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
681 f.write(data) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
682 return |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
683 except IOError as e: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
684 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
|
685 except zipfile.BadZipfile as e: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
686 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
|
687 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
688 # 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
|
689 myDir = dirname(__file__) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
690 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
691 javaSource = join(myDir, 'URLConnectionDownload.java') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
692 javaClass = join(myDir, 'URLConnectionDownload.class') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
693 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
|
694 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
|
695 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
|
696 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
|
697 '\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
|
698 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
699 def update_file(self, path, content): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
700 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
701 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
|
702 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
|
703 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
704 existed = exists(path) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
705 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
706 old = None |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
707 if existed: |
3732
3e2e8b8abdaf
Updated mxtool to allow projects in subdirectories.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
3723
diff
changeset
|
708 with open(path, 'rb') as f: |
3723
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
709 old = f.read() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
710 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
711 if old == content: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
712 return False |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
713 |
3732
3e2e8b8abdaf
Updated mxtool to allow projects in subdirectories.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
3723
diff
changeset
|
714 with open(path, 'wb') as f: |
3723
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
715 f.write(content) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
716 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
717 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
|
718 return True; |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
719 except IOError as e: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
720 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
|
721 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
722 # Builtin commands |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
723 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
724 def build(env, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
725 """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
|
726 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
727 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
|
728 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
|
729 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
730 parser = ArgumentParser(prog='mx build'); |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
731 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
|
732 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
|
733 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
|
734 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
|
735 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
736 args = parser.parse_args(args) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
737 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
738 jdtJar = None |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
739 if args.jdt is not None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
740 if args.jdt.endswith('.jar'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
741 jdtJar=args.jdt |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
742 elif isdir(args.jdt): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
743 plugins = join(args.jdt, 'plugins') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
744 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
|
745 if len(choices) != 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
746 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
|
747 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
748 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
|
749 built = set() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
750 for project in projects: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
751 p = env.pdb.project(project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
752 projectDir = join(p.baseDir, project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
753 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
754 if p.native: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
755 if env.os == 'windows': |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
756 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
|
757 pass |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
758 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
759 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
|
760 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
761 if args.clean: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
762 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
|
763 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
764 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
|
765 built.add(project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
766 continue |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
767 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
768 outputDir = p.output_dir() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
769 if exists(outputDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
770 if args.clean: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
771 env.log('Cleaning {0}...'.format(outputDir)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
772 shutil.rmtree(outputDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
773 os.mkdir(outputDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
774 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
775 os.mkdir(outputDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
776 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
777 classpath = env.pdb.classpath(project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
778 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
|
779 mustBuild = args.force |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
780 if not mustBuild: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
781 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
|
782 if dep.name in built: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
783 mustBuild = True |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
784 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
785 for sourceDir in sourceDirs: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
786 javafilelist = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
787 nonjavafilelist = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
788 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
|
789 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
|
790 javafilelist += javafiles |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
791 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
|
792 if not mustBuild: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
793 for javafile in javafiles: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
794 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
|
795 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
|
796 mustBuild = True |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
797 break |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
798 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
799 if not mustBuild: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
800 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
|
801 continue |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
802 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
803 if len(javafilelist) == 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
804 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
|
805 continue |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
806 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
807 built.add(project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
808 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
809 argfileName = join(projectDir, 'javafilelist.txt') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
810 argfile = open(argfileName, 'w') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
811 argfile.write('\n'.join(javafilelist)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
812 argfile.close() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
813 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
814 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
815 if jdtJar is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
816 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
|
817 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
818 class Filter: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
819 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
820 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
|
821 warning when compiling the VM classes. |
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 """ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
824 def __init__(self): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
825 self.c = 0 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
826 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
827 def eat(self, line): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
828 if 'Sun proprietary API' in line: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
829 self.c = 2 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
830 elif self.c != 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
831 self.c -= 1 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
832 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
833 print line.rstrip() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
834 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
835 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
|
836 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
837 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
|
838 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
|
839 if not exists(jdtProperties): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
840 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
|
841 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
|
842 '-properties', jdtProperties, |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
843 '-warn:-unusedImport,-unchecked', |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
844 '-d', outputDir, '@' + argfile.name]) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
845 finally: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
846 os.remove(argfileName) |
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 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
849 for name in nonjavafilelist: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
850 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
|
851 if exists(dirname(dst)): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
852 shutil.copyfile(name, dst) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
853 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
854 def canonicalizeprojects(env, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
855 """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
|
856 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
857 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
|
858 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
859 changedFiles = 0 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
860 pdb = env.pdb |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
861 for d in pdb.baseDirs: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
862 projectsFile = join(d, 'mx', 'projects') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
863 if not exists(projectsFile): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
864 continue |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
865 with open(projectsFile) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
866 out = StringIO.StringIO() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
867 pattern = re.compile('project@([^@]+)@dependencies=.*') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
868 for line in f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
869 line = line.strip() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
870 m = pattern.match(line) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
871 if m is None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
872 out.write(line + '\n') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
873 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
874 p = pdb.project(m.group(1)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
875 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
|
876 content = out.getvalue() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
877 if env.update_file(projectsFile, content): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
878 changedFiles += 1 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
879 return changedFiles; |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
880 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
881 def checkstyle(env, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
882 """run Checkstyle on the Java sources |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
883 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
884 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
|
885 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
|
886 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
887 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
|
888 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
889 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
|
890 if len(args) == 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
891 projects = allProjects |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
892 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
893 projects = args |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
894 unknown = set(projects).difference(allProjects) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
895 if len(unknown) != 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
896 env.error('unknown projects: ' + ', '.join(unknown)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
897 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
898 for project in projects: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
899 p = env.pdb.project(project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
900 projectDir = join(p.baseDir, project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
901 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
|
902 dotCheckstyle = join(projectDir, '.checkstyle') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
903 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
904 if not exists(dotCheckstyle): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
905 continue |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
906 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
907 for sourceDir in sourceDirs: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
908 javafilelist = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
909 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
|
910 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
|
911 if len(javafilelist) == 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
912 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
|
913 continue |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
914 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
915 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
|
916 mustCheck = False |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
917 if exists(timestampFile): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
918 timestamp = os.path.getmtime(timestampFile) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
919 for f in javafilelist: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
920 if os.path.getmtime(f) > timestamp: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
921 mustCheck = True |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
922 break |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
923 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
924 mustCheck = True |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
925 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
926 if not mustCheck: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
927 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
|
928 continue |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
929 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
930 if exists(timestampFile): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
931 os.utime(timestampFile, None) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
932 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
933 file(timestampFile, 'a') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
934 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
935 dotCheckstyleXML = xml.dom.minidom.parse(dotCheckstyle) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
936 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
|
937 configLocation = localCheckConfig.getAttribute('location') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
938 if configLocation.startswith('/'): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
939 config = join(p.baseDir, configLocation.lstrip('/')) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
940 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
941 config = join(projectDir, configLocation) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
942 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
943 exclude = join(projectDir, '.checkstyle.exclude') |
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 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
948 if exists(exclude): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
949 with open(exclude) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
950 # Convert patterns to OS separators |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
951 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
|
952 def match(name): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
953 for p in patterns: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
954 if p in name: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
955 env.log('excluding: ' + name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
956 return True |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
957 return False |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
958 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
959 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
|
960 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
961 auditfileName = join(projectDir, 'checkstyleOutput.txt') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
962 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
|
963 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
964 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
965 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
966 # 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
|
967 # 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
|
968 # 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
|
969 # 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
|
970 while len(javafilelist) != 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
971 i = 0 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
972 size = 0 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
973 while i < len(javafilelist): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
974 s = len(javafilelist[i]) + 1 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
975 if (size + s < 30000): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
976 size += s |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
977 i += 1 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
978 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
979 break |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
980 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
981 batch = javafilelist[:i] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
982 javafilelist = javafilelist[i:] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
983 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
984 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
|
985 finally: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
986 if exists(auditfileName): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
987 with open(auditfileName) as f: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
988 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
|
989 if len(warnings) != 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
990 map(env.log, warnings) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
991 return 1 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
992 finally: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
993 if exists(auditfileName): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
994 os.unlink(auditfileName) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
995 return 0 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
996 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
997 def clean(env, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
998 """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
|
999 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1000 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
|
1001 generated images. |
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 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1004 projects = env.pdb.projects.keys() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1005 for project in projects: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1006 p = env.pdb.project(project) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1007 if p.native: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1008 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
|
1009 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1010 outputDir = p.output_dir() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1011 if outputDir != '' and exists(outputDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1012 env.log('Removing {0}...'.format(outputDir)) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1013 shutil.rmtree(outputDir) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1014 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1015 def help_(env, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1016 """show help for a given command |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1017 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1018 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
|
1019 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1020 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
|
1021 if len(args) == 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1022 env.print_help() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1023 return |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1024 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1025 name = args[0] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1026 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
|
1027 env.error('unknown command: ' + name) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1028 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1029 value = env.commands[name] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1030 (func, usage) = value[:2] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1031 doc = func.__doc__ |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1032 if len(value) > 2: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1033 docArgs = value[2:] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1034 fmtArgs = [] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1035 for d in docArgs: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1036 if isinstance(d, Callable): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1037 fmtArgs += [d(env)] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1038 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1039 fmtArgs += [str(d)] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1040 doc = doc.format(*fmtArgs) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1041 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
|
1042 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1043 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1044 # 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
|
1045 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1046 def javap(env, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1047 """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
|
1048 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1049 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
|
1050 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1051 -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
|
1052 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1053 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
|
1054 if not exists(javap): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1055 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
|
1056 else: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1057 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
|
1058 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1059 def projects(env, args): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1060 """show all loaded projects""" |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1061 pdb = env.pdb |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1062 for d in pdb.baseDirs: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1063 projectsFile = join(d, 'mx', 'projects') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1064 if exists(projectsFile): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1065 env.log('# file: ' + projectsFile) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1066 for p in pdb.projects.values(): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1067 if p.baseDir == d: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1068 env.log(p.name) |
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 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1071 def main(env): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1072 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1073 # Table of commands in alphabetical order. |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1074 # 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
|
1075 # 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
|
1076 # 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
|
1077 # Extensions should update this table directly |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1078 env.commands = { |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1079 'build': [build, '[options] projects...'], |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1080 'checkstyle': [checkstyle, 'projects...'], |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1081 'canonicalizeprojects': [canonicalizeprojects, ''], |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1082 'clean': [clean, ''], |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1083 'help': [help_, '[command]'], |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1084 'javap': [javap, ''], |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1085 'projects': [projects, ''], |
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 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1088 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
|
1089 if MX_INCLUDES is not None: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1090 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
|
1091 d = join(path, 'mx') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1092 if exists(d) and isdir(d): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1093 env.pdb.load(d) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1094 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1095 cwdMxDir = join(os.getcwd(), 'mx') |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1096 if exists(cwdMxDir) and isdir(cwdMxDir): |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1097 env.pdb.load(cwdMxDir, primary=True) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1098 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1099 env._parse_cmd_line() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1100 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1101 if len(env.commandAndArgs) == 0: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1102 env.print_help() |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1103 return |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1104 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1105 env.command = env.commandAndArgs[0] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1106 env.command_args = env.commandAndArgs[1:] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1107 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1108 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
|
1109 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
|
1110 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1111 c, _ = env.commands[env.command][:2] |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1112 try: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1113 retcode = c(env, env.command_args) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1114 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
|
1115 env.abort(retcode) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1116 except KeyboardInterrupt: |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1117 # 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
|
1118 env.abort(1) |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1119 |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1120 if __name__ == '__main__': |
6c5f528c7aac
Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1121 main(Env()) |