annotate mxtool/mx.py @ 5455:271e83dcfcef

added findclass command to mx tool
author Doug Simon <doug.simon@oracle.com>
date Wed, 30 May 2012 18:07:38 +0200
parents bfc9aeb1264c
children 9911227e6dd3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 #!/usr/bin/python
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 #
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 # ----------------------------------------------------------------------------------------------------
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 #
4186
71a2cd79c375 Made stdout for mx unbuffered.
Doug Simon <doug.simon@oracle.com>
parents: 4180
diff changeset
5 # Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
3723
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 #
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
28
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
29 r"""
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
30 mx is a command line tool inspired by mvn (http://maven.apache.org/)
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
31 and hg (http://mercurial.selenic.com/). It includes a mechanism for
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
32 managing the dependencies between a set of projects (like Maven)
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
33 as well as making it simple to run commands
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
34 (like hg is the interface to the Mercurial commands).
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
35
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
36 The organizing principle of mx is a project suite. A suite is a directory
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
37 containing one or more projects. It's not coincidental that this closely
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
38 matches the layout of one or more projects in a Mercurial repository.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
39 The configuration information for a suite lives in an 'mx' sub-directory
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
40 at the top level of the suite.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
41
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
42 When launched, mx treats the current working directory as a suite.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
43 This is the primary suite. All other suites are called included suites.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
44
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
45 The configuration files (i.e. in the 'mx' sub-directory) of a suite are:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
46
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
47 projects
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
48 Defines the projects and libraries in the suite and the
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
49 dependencies between them.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
50
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
51 commands.py
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
52 Suite specific extensions to the commands available to mx.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
53 This is only processed for the primary suite.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
54
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
55 includes
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
56 Other suites to be loaded. This is recursive.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
57
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
58 env
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
59 A set of environment variable definitions. These override any
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
60 existing environment variables.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
61
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
62 The includes and env files are typically not put under version control
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
63 as they usually contain local file-system paths.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
64
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
65 The projects file is like the pom.xml file from Maven except that
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
66 it is a properties file (not XML). Each non-comment line
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
67 in the file specifies an attribute of a project or library. The main
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
68 difference between a project and a library is that the former contains
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
69 source code built by the mx tool where as the latter is an external
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
70 dependency. The format of the projects file is
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
71
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
72 Library specification format:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
73
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
74 library@<name>@<prop>=<value>
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
75
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
76 Built-in library properties (* = required):
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
77
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
78 *path
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
79 The file system path for the library to appear on a class path.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
80
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
81 urls
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
82 A comma separated list of URLs from which the library (jar) can
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
83 be downloaded and saved in the location specified by 'path'.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
84
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
85 optional
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
86 If "true" then this library will be omitted from a class path
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
87 if it doesn't exist on the file system and no URLs are specified.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
88
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
89 Project specification format:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
90
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
91 project@<name>@<prop>=<value>
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
92
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
93 The name of a project also denotes the directory it is in.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
94
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
95 Built-in project properties (* = required):
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
96
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
97 subDir
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
98 The sub-directory of the suite in which the project directory is
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
99 contained. If not specified, the project directory is directly
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
100 under the suite directory.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
101
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
102 *sourceDirs
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
103 A comma separated list of source directory names (relative to
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
104 the project directory).
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
105
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
106 dependencies
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
107 A comma separated list of the libraries and project the project
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
108 depends upon (transitive dependencies should be omitted).
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
109
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
110 checkstyle
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
111 The project whose Checkstyle configuration
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
112 (i.e. <project>/.checkstyle_checks.xml) is used.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
113
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
114 native
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
115 "true" if the project is native.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
116
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
117 javaCompliance
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
118 The minimum JDK version (format: x.y) to which the project's
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
119 sources comply (required for non-native projects).
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
120
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
121 Other properties can be specified for projects and libraries for use
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
122 by extension commands.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
123
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
124 Property values can use environment variables with Bash syntax (e.g. ${HOME}).
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
125 """
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
126
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
127 import sys, os, errno, time, subprocess, shlex, types, urllib2, contextlib, StringIO, zipfile, signal, xml.sax.saxutils, tempfile
4158
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
128 import shutil, fnmatch, re, xml.dom.minidom
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
129 from collections import Callable
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
130 from threading import Thread
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
131 from argparse import ArgumentParser, REMAINDER
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
132 from os.path import join, basename, dirname, exists, getmtime, isabs, expandvars, isdir, isfile
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
133
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
134 DEFAULT_JAVA_ARGS = '-ea -Xss2m -Xmx1g'
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
135
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
136 _projects = dict()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
137 _libs = dict()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
138 _suites = dict()
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
139 _mainSuite = None
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
140 _opts = None
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
141 _java = None
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
142
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
143 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
144 A dependency is a library or project specified in a suite.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
145 """
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
146 class Dependency:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
147 def __init__(self, suite, name):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
148 self.name = name
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
149 self.suite = suite
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
150
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
151 def __str__(self):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
152 return self.name
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
153
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
154 def __eq__(self, other):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
155 return self.name == other.name
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
156
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
157 def __ne__(self, other):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
158 return self.name != other.name
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
159
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
160 def __hash__(self):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
161 return hash(self.name)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
162
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
163 def isLibrary(self):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
164 return isinstance(self, Library)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
165
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
166 class Project(Dependency):
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
167 def __init__(self, suite, name, srcDirs, deps, javaCompliance, dir):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
168 Dependency.__init__(self, suite, name)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
169 self.srcDirs = srcDirs
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
170 self.deps = deps
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
171 self.checkstyleProj = name
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
172 self.javaCompliance = JavaCompliance(javaCompliance) if javaCompliance is not None else None
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
173 self.native = False
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
174 self.dir = dir
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
175
4219
47f7d91d34cf Fix javac build issues with classpath
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4215
diff changeset
176 def all_deps(self, deps, includeLibs, includeSelf=True):
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
177 """
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
178 Add the transitive set of dependencies for this project, including
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
179 libraries if 'includeLibs' is true, to the 'deps' list.
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
180 """
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
181 if self in deps:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
182 return deps
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
183 for name in self.deps:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
184 assert name != self.name
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
185 dep = _libs.get(name, None)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
186 if dep is not None:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
187 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
188 deps.append(dep)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
189 else:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
190 dep = project(name)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
191 if not dep in deps:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
192 dep.all_deps(deps, includeLibs)
4219
47f7d91d34cf Fix javac build issues with classpath
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4215
diff changeset
193 if not self in deps and includeSelf:
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
194 deps.append(self)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
195 return deps
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
196
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
197 def _compute_max_dep_distances(self, name, distances, dist):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
198 currentDist = distances.get(name);
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
199 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
200 distances[name] = dist
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
201 p = project(name, False)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
202 if p is not None:
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
203 for dep in p.deps:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
204 self._compute_max_dep_distances(dep, distances, dist + 1)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
205
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
206 def canonical_deps(self):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
207 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
208 Get the dependencies of this project that are not recursive (i.e. cannot be reached
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
209 via other dependencies).
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
210 """
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
211 distances = dict()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
212 result = set()
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
213 self._compute_max_dep_distances(self.name, distances, 0)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
214 for n,d in distances.iteritems():
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
215 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
216 if d == 1:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
217 result.add(n)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
218
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
219
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
220 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
221 return self.deps
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
222 return result;
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
223
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
224
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
225 def source_dirs(self):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
226 """
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
227 Get the directories in which the sources of this project are found.
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
228 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
229 return [join(self.dir, s) for s in self.srcDirs]
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
230
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
231 def output_dir(self):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
232 """
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
233 Get the directory in which the class files of this project are found/placed.
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
234 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
235 if self.native:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
236 return None
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
237 return join(self.dir, 'bin')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
238
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
239 def jasmin_output_dir(self):
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
240 """
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
241 Get the directory in which the Jasmin assembled class files of this project are found/placed.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
242 """
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
243 if self.native:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
244 return None
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
245 return join(self.dir, 'jasmin_classes')
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
246
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
247 def append_to_classpath(self, cp, resolve):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
248 if not self.native:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
249 cp.append(self.output_dir())
3723
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 class Library(Dependency):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
252 def __init__(self, suite, name, path, mustExist, urls):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
253 Dependency.__init__(self, suite, name)
4271
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
254 self.path = path.replace('/', os.sep)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
255 self.urls = urls
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
256 self.mustExist = mustExist
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
257
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
258 def get_path(self, resolve):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
259 path = self.path
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
260 if not isabs(path):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
261 path = join(self.suite.dir, path)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
262 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
263 assert not len(self.urls) == 0, 'cannot find required library ' + self.name + " " + path;
4178
d1b26c17910a Add the Dacapo benchmarks to the "lib" folder instead of using the environment variable. Fixed an issue in the downloader.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4161
diff changeset
264 print('Downloading ' + self.name + ' from ' + str(self.urls))
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
265 download(path, self.urls)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
266
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
267 return path
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
268
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
269 def append_to_classpath(self, cp, resolve):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
270 path = self.get_path(resolve)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
271 if exists(path) or not resolve:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
272 cp.append(path)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
273
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
274 class Suite:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
275 def __init__(self, dir, primary):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
276 self.dir = dir
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
277 self.projects = []
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
278 self.libs = []
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
279 self.includes = []
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
280 self.commands = None
4180
383c1272cd1f Fixed gate script such that JAVA_HOME can be set in env file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4178
diff changeset
281 self.primary = primary
4215
a2caa019ba3a Fix mx : commands' scripts mx_init hook should be called before parsing command line arguments.
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4188
diff changeset
282 mxDir = join(dir, 'mx')
a2caa019ba3a Fix mx : commands' scripts mx_init hook should be called before parsing command line arguments.
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4188
diff changeset
283 self._load_env(mxDir)
a2caa019ba3a Fix mx : commands' scripts mx_init hook should be called before parsing command line arguments.
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4188
diff changeset
284 if primary:
a2caa019ba3a Fix mx : commands' scripts mx_init hook should be called before parsing command line arguments.
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4188
diff changeset
285 self._load_commands(mxDir)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
286
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
287 def _load_projects(self, mxDir):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
288 libsMap = dict()
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
289 projsMap = dict()
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
290 projectsFile = join(mxDir, 'projects')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
291 if not exists(projectsFile):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
292 return
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
293 with open(projectsFile) as f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
294 for line in f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
295 line = line.strip()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
296 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
297 key, value = line.split('=', 1)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
298
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
299 parts = key.split('@')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
300
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
301 if len(parts) == 2:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
302 pass
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
303 if len(parts) != 3:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
304 abort('Property name does not have 3 parts separated by "@": ' + key)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
305 kind, name, attr = parts
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
306 if kind == 'project':
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
307 m = projsMap
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
308 elif kind == 'library':
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
309 m = libsMap
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
310 else:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
311 abort('Property name does not start with "project@" or "library@": ' + key)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
312
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
313 attrs = m.get(name)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
314 if attrs is None:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
315 attrs = dict()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
316 m[name] = attrs
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
317 value = expandvars_in_property(value)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
318 attrs[attr] = value
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
319
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
320 def pop_list(attrs, name):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
321 v = attrs.pop(name, None)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
322 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
323 return []
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
324 return [n.strip() for n in v.split(',')]
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
325
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
326 for name, attrs in projsMap.iteritems():
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
327 srcDirs = pop_list(attrs, 'sourceDirs')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
328 deps = pop_list(attrs, 'dependencies')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
329 javaCompliance = attrs.pop('javaCompliance', None)
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
330 subDir = attrs.pop('subDir', None);
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
331 if subDir is None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
332 dir = join(self.dir, name)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
333 else:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
334 dir = join(self.dir, subDir, name)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
335 p = Project(self, name, srcDirs, deps, javaCompliance, dir)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
336 p.checkstyleProj = attrs.pop('checkstyle', name)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
337 p.native = attrs.pop('native', '') == 'true'
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
338 if not p.native and p.javaCompliance is None:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
339 abort('javaCompliance property required for non-native project ' + name)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
340 p.__dict__.update(attrs)
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
341 self.projects.append(p)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
342
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
343 for name, attrs in libsMap.iteritems():
4271
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
344 path = attrs.pop('path')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
345 mustExist = attrs.pop('optional', 'false') != 'true'
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
346 urls = pop_list(attrs, 'urls')
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
347 l = Library(self, name, path, mustExist, urls)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
348 l.__dict__.update(attrs)
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
349 self.libs.append(l)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
350
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
351 def _load_commands(self, mxDir):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
352 commands = join(mxDir, 'commands.py')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
353 if exists(commands):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
354 # temporarily extend the Python path
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
355 sys.path.insert(0, mxDir)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
356
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
357 mod = __import__('commands')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
358
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
359 # revert the Python path
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
360 del sys.path[0]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
361
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
362 if not hasattr(mod, 'mx_init'):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
363 abort(commands + ' must define an mx_init(env) function')
4215
a2caa019ba3a Fix mx : commands' scripts mx_init hook should be called before parsing command line arguments.
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4188
diff changeset
364 if hasattr(mod, 'mx_post_parse_cmd_line'):
a2caa019ba3a Fix mx : commands' scripts mx_init hook should be called before parsing command line arguments.
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4188
diff changeset
365 self.mx_post_parse_cmd_line = mod.mx_post_parse_cmd_line
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
366
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
367 mod.mx_init()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
368 self.commands = mod
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
369
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
370 def _load_includes(self, mxDir):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
371 includes = join(mxDir, 'includes')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
372 if exists(includes):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
373 with open(includes) as f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
374 for line in f:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
375 self.includes.append(expandvars_in_property(line.strip()))
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
376
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
377 def _load_env(self, mxDir):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
378 e = join(mxDir, 'env')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
379 if exists(e):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
380 with open(e) as f:
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
381 for line in f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
382 line = line.strip()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
383 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
384 key, value = line.split('=', 1)
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
385 os.environ[key.strip()] = expandvars_in_property(value.strip())
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
386
4180
383c1272cd1f Fixed gate script such that JAVA_HOME can be set in env file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4178
diff changeset
387 def _post_init(self, opts):
383c1272cd1f Fixed gate script such that JAVA_HOME can be set in env file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4178
diff changeset
388 mxDir = join(self.dir, 'mx')
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
389 self._load_includes(mxDir)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
390 self._load_projects(mxDir)
4215
a2caa019ba3a Fix mx : commands' scripts mx_init hook should be called before parsing command line arguments.
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4188
diff changeset
391 if self.mx_post_parse_cmd_line is not None:
a2caa019ba3a Fix mx : commands' scripts mx_init hook should be called before parsing command line arguments.
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4188
diff changeset
392 self.mx_post_parse_cmd_line(opts)
4180
383c1272cd1f Fixed gate script such that JAVA_HOME can be set in env file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4178
diff changeset
393 for p in self.projects:
383c1272cd1f Fixed gate script such that JAVA_HOME can be set in env file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4178
diff changeset
394 existing = _projects.get(p.name)
383c1272cd1f Fixed gate script such that JAVA_HOME can be set in env file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4178
diff changeset
395 if existing is not None:
383c1272cd1f Fixed gate script such that JAVA_HOME can be set in env file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4178
diff changeset
396 abort('cannot override project ' + p.name + ' in ' + p.dir + " with project of the same name in " + existing.dir)
383c1272cd1f Fixed gate script such that JAVA_HOME can be set in env file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4178
diff changeset
397 _projects[p.name] = p
383c1272cd1f Fixed gate script such that JAVA_HOME can be set in env file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4178
diff changeset
398 for l in self.libs:
383c1272cd1f Fixed gate script such that JAVA_HOME can be set in env file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4178
diff changeset
399 existing = _libs.get(l.name)
383c1272cd1f Fixed gate script such that JAVA_HOME can be set in env file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4178
diff changeset
400 if existing is not None:
383c1272cd1f Fixed gate script such that JAVA_HOME can be set in env file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4178
diff changeset
401 abort('cannot redefine library ' + l.name)
383c1272cd1f Fixed gate script such that JAVA_HOME can be set in env file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4178
diff changeset
402 _libs[l.name] = l
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
403
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
404 class XMLElement(xml.dom.minidom.Element):
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
405 def writexml(self, writer, indent="", addindent="", newl=""):
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
406 writer.write(indent+"<" + self.tagName)
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
407
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
408 attrs = self._get_attributes()
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
409 a_names = attrs.keys()
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
410 a_names.sort()
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
411
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
412 for a_name in a_names:
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
413 writer.write(" %s=\"" % a_name)
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
414 xml.dom.minidom._write_data(writer, attrs[a_name].value)
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
415 writer.write("\"")
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
416 if self.childNodes:
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
417 if not self.ownerDocument.padTextNodeWithoutSiblings and len(self.childNodes) == 1 and isinstance(self.childNodes[0], xml.dom.minidom.Text):
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
418 # if the only child of an Element node is a Text node, then the
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
419 # text is printed without any indentation or new line padding
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
420 writer.write(">")
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
421 self.childNodes[0].writexml(writer)
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
422 writer.write("</%s>%s" % (self.tagName,newl))
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
423 else:
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
424 writer.write(">%s"%(newl))
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
425 for node in self.childNodes:
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
426 node.writexml(writer,indent+addindent,addindent,newl)
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
427 writer.write("%s</%s>%s" % (indent,self.tagName,newl))
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
428 else:
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
429 writer.write("/>%s"%(newl))
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
430
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
431 class XMLDoc(xml.dom.minidom.Document):
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
432
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
433 def __init__(self):
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
434 xml.dom.minidom.Document.__init__(self)
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
435 self.current = self
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
436 self.padTextNodeWithoutSiblings = False
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
437
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
438 def createElement(self, tagName):
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
439 # overwritten to create XMLElement
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
440 e = XMLElement(tagName)
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
441 e.ownerDocument = self
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
442 return e
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
443
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
444 def open(self, tag, attributes={}, data=None):
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
445 element = self.createElement(tag)
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
446 for key, value in attributes.items():
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
447 element.setAttribute(key, value)
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
448 self.current.appendChild(element)
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
449 self.current = element
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
450 if data is not None:
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
451 element.appendChild(self.createTextNode(data))
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
452 return self
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
453
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
454 def close(self, tag):
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
455 assert self.current != self
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
456 assert tag == self.current.tagName, str(tag) + ' != ' + self.current.tagName
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
457 self.current = self.current.parentNode
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
458 return self
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
459
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
460 def element(self, tag, attributes={}, data=None):
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
461 return self.open(tag, attributes, data).close(tag)
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
462
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
463 def xml(self, indent='', newl='', escape=False):
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
464 assert self.current == self
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
465 result = self.toprettyxml(indent, newl, encoding="UTF-8")
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
466 if escape:
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
467 entities = { '"': "&quot;", "'": "&apos;", '\n': '&#10;' }
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
468 result = xml.sax.saxutils.escape(result, entities)
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
469 return result
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
470
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
471 def get_os():
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
472 """
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
473 Get a canonical form of sys.platform.
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
474 """
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
475 if sys.platform.startswith('darwin'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
476 return 'darwin'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
477 elif sys.platform.startswith('linux'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
478 return 'linux'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
479 elif sys.platform.startswith('sunos'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
480 return 'solaris'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
481 elif sys.platform.startswith('win32') or sys.platform.startswith('cygwin'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
482 return 'windows'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
483 else:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
484 abort('Unknown operating system ' + sys.platform)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
485
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
486 def _loadSuite(dir, primary=False):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
487 mxDir = join(dir, 'mx')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
488 if not exists(mxDir) or not isdir(mxDir):
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
489 return None
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
490 if not _suites.has_key(dir):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
491 suite = Suite(dir, primary)
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
492 _suites[dir] = suite
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
493 return suite
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
494
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
495 def suites():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
496 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
497 Get the list of all loaded suites.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
498 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
499 return _suites.values()
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
500
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
501 def projects():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
502 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
503 Get the list of all loaded projects.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
504 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
505 return _projects.values()
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
506
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
507 def project(name, fatalIfMissing=True):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
508 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
509 Get the project for a given name. This will abort if the named project does
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
510 not exist and 'fatalIfMissing' is true.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
511 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
512 p = _projects.get(name)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
513 if p is None and fatalIfMissing:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
514 abort('project named ' + name + ' not found')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
515 return p
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
516
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
517 def library(name, fatalIfMissing=True):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
518 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
519 Gets the library for a given name. This will abort if the named library does
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
520 not exist and 'fatalIfMissing' is true.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
521 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
522 l = _libs.get(name)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
523 if l is None and fatalIfMissing:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
524 abort('library named ' + name + ' not found')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
525 return l
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
526
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
527 def _as_classpath(deps, resolve):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
528 cp = []
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
529 if _opts.cp_prefix is not None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
530 cp = [_opts.cp_prefix]
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
531 for d in deps:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
532 d.append_to_classpath(cp, resolve)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
533 if _opts.cp_suffix is not None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
534 cp += [_opts.cp_suffix]
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
535 return os.pathsep.join(cp)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
536
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
537 def classpath(names=None, resolve=True, includeSelf=True, includeBootClasspath=False):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
538 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
539 Get the class path for a list of given projects, resolving each entry in the
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
540 path (e.g. downloading a missing library) if 'resolve' is true.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
541 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
542 if names is None:
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
543 result = _as_classpath(sorted_deps(includeLibs=True), resolve)
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
544 else:
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
545 deps = []
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
546 if isinstance(names, types.StringTypes):
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
547 project(names).all_deps(deps, True, includeSelf)
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
548 else:
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
549 for n in names:
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
550 project(n).all_deps(deps, True, includeSelf)
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
551 result = _as_classpath(deps, resolve)
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
552 if includeBootClasspath:
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
553 result = os.pathsep.join([java().bootclasspath(), result])
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
554 return result
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
555
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
556 def classpath_walk(names=None, resolve=True, includeSelf=True, includeBootClasspath=False):
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
557 """
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
558 Walks the resources available in a given classpath, yielding a tuple for each resource
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
559 where the first member of the tuple is a directory path or ZipFile object for a
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
560 classpath entry and the second member is the qualified path of the resource relative
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
561 to the classpath entry.
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
562 """
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
563 cp = classpath(names, resolve, includeSelf, includeBootClasspath)
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
564 for entry in cp.split(os.pathsep):
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
565 if not exists(entry):
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
566 continue
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
567 if isdir(entry):
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
568 for root, dirs, files in os.walk(entry):
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
569 for d in dirs:
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
570 entryPath = join(root[len(entry) + 1:], d)
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
571 yield entry, entryPath
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
572 for f in files:
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
573 entryPath = join(root[len(entry) + 1:], f)
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
574 yield entry, entryPath
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
575 elif entry.endswith('.jar') or entry.endswith('.zip'):
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
576 with zipfile.ZipFile(entry, 'r') as zf:
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
577 for zi in zf.infolist():
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
578 entryPath = zi.filename
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
579 yield zf, entryPath
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
580
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
581 def sorted_deps(projectNames=None, includeLibs=False):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
582 """
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
583 Gets projects and libraries sorted such that dependencies
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
584 are before the projects that depend on them. Unless 'includeLibs' is
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
585 true, libraries are omitted from the result.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
586 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
587 deps = []
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
588 if projectNames is None:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
589 projects = _projects.values()
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
590 else:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
591 projects = [project(name) for name in projectNames]
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
592
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
593 for p in projects:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
594 p.all_deps(deps, includeLibs)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
595 return deps
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
596
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
597 class ArgParser(ArgumentParser):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
598
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
599 # 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
600 def format_help(self):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
601 return ArgumentParser.format_help(self) + _format_commands()
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
602
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
603
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
604 def __init__(self):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
605 self.java_initialized = False
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
606 ArgumentParser.__init__(self, prog='mx')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
607
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
608 self.add_argument('-v', action='store_true', dest='verbose', help='enable verbose output')
5091
54819cdcca7f Added -V option to mx for 'very verbose'which prints the environment variables used for an external command.
Doug Simon <doug.simon@oracle.com>
parents: 5072
diff changeset
609 self.add_argument('-V', action='store_true', dest='very_verbose', help='enable very verbose output')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
610 self.add_argument('--dbg', type=int, dest='java_dbg_port', help='make Java processes wait on <port> for a debugger', metavar='<port>')
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
611 self.add_argument('-d', action='store_const', const=8000, dest='java_dbg_port', help='alias for "-dbg 8000"')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
612 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
613 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
614 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
615 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
616 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
617 self.add_argument('--user-home', help='users home directory', metavar='<path>', default=os.path.expanduser('~'))
4149
cf4de9cc1268 Integrated latest mxtool updates.
Doug Simon <doug.simon@oracle.com>
parents: 4148
diff changeset
618 self.add_argument('--java-home', help='JDK installation directory (must be JDK 6 or later)', metavar='<path>')
4239
676feaf8adee Made the --timeout option apply to the whole mx command as opposed to each subprocess executed (the new --ptimeout does the latter).
Doug Simon <doug.simon@oracle.com>
parents: 4236
diff changeset
619 if get_os() != 'windows':
676feaf8adee Made the --timeout option apply to the whole mx command as opposed to each subprocess executed (the new --ptimeout does the latter).
Doug Simon <doug.simon@oracle.com>
parents: 4236
diff changeset
620 # Time outs are (currently) implemented with Unix specific functionality
676feaf8adee Made the --timeout option apply to the whole mx command as opposed to each subprocess executed (the new --ptimeout does the latter).
Doug Simon <doug.simon@oracle.com>
parents: 4236
diff changeset
621 self.add_argument('--timeout', help='Timeout (in seconds) for command', type=int, default=0, metavar='<secs>')
676feaf8adee Made the --timeout option apply to the whole mx command as opposed to each subprocess executed (the new --ptimeout does the latter).
Doug Simon <doug.simon@oracle.com>
parents: 4236
diff changeset
622 self.add_argument('--ptimeout', help='Timeout (in seconds) for subprocesses', type=int, default=0, metavar='<secs>')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
623
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
624 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
625 if args is None:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
626 args = sys.argv[1:]
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
627
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
628 self.add_argument('commandAndArgs', nargs=REMAINDER, metavar='command args...')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
629
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
630 opts = self.parse_args()
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
631
4270
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
632 # Give the timeout options a default value to avoid the need for hasattr() tests
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
633 opts.__dict__.setdefault('timeout', 0)
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
634 opts.__dict__.setdefault('ptimeout', 0)
4149
cf4de9cc1268 Integrated latest mxtool updates.
Doug Simon <doug.simon@oracle.com>
parents: 4148
diff changeset
635
5091
54819cdcca7f Added -V option to mx for 'very verbose'which prints the environment variables used for an external command.
Doug Simon <doug.simon@oracle.com>
parents: 5072
diff changeset
636 if opts.very_verbose:
54819cdcca7f Added -V option to mx for 'very verbose'which prints the environment variables used for an external command.
Doug Simon <doug.simon@oracle.com>
parents: 5072
diff changeset
637 opts.verbose = True
54819cdcca7f Added -V option to mx for 'very verbose'which prints the environment variables used for an external command.
Doug Simon <doug.simon@oracle.com>
parents: 5072
diff changeset
638
4149
cf4de9cc1268 Integrated latest mxtool updates.
Doug Simon <doug.simon@oracle.com>
parents: 4148
diff changeset
639 if opts.java_home is None:
cf4de9cc1268 Integrated latest mxtool updates.
Doug Simon <doug.simon@oracle.com>
parents: 4148
diff changeset
640 opts.java_home = os.environ.get('JAVA_HOME')
cf4de9cc1268 Integrated latest mxtool updates.
Doug Simon <doug.simon@oracle.com>
parents: 4148
diff changeset
641
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
642 if opts.java_home is None or opts.java_home == '':
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
643 abort('Could not find Java home. Use --java-home option or ensure JAVA_HOME environment variable is set.')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
644
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
645 if opts.user_home is None or opts.user_home == '':
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
646 abort('Could not find user home. Use --user-home option or ensure HOME environment variable is set.')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
647
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
648 os.environ['JAVA_HOME'] = opts.java_home
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
649 os.environ['HOME'] = opts.user_home
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
650
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
651 commandAndArgs = opts.__dict__.pop('commandAndArgs')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
652 return opts, commandAndArgs
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
653
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
654 def _format_commands():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
655 msg = '\navailable commands:\n\n'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
656 for cmd in sorted(commands.iterkeys()):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
657 c, _ = commands[cmd][:2]
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
658 doc = c.__doc__
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
659 if doc is None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
660 doc = ''
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
661 msg += ' {0:<20} {1}\n'.format(cmd, doc.split('\n', 1)[0])
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
662 return msg + '\n'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
663
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
664 def java():
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
665 """
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
666 Get a JavaConfig object containing Java commands launch details.
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
667 """
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
668 assert _java is not None
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
669 return _java
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
670
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
671 def run_java(args, nonZeroIsFatal=True, out=None, err=None, cwd=None):
4147
55376d8953a6 Improved 'build' and 'clean' commands.
Doug Simon <doug.simon@oracle.com>
parents: 4145
diff changeset
672 return run(java().format_cmd(args), nonZeroIsFatal=nonZeroIsFatal, out=out, err=err, cwd=cwd)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
673
4241
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
674 def _kill_process_group(pid):
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
675 pgid = os.getpgid(pid)
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
676 try:
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
677 os.killpg(pgid, signal.SIGKILL)
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
678 return True
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
679 except:
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
680 log('Error killing subprocess ' + str(pgid) + ': ' + str(sys.exc_info()[1]))
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
681 return False
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
682
4158
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
683 def _waitWithTimeout(process, args, timeout):
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
684 def _waitpid(pid):
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
685 while True:
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
686 try:
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
687 return os.waitpid(pid, os.WNOHANG)
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
688 except OSError, e:
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
689 if e.errno == errno.EINTR:
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
690 continue
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
691 raise
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
692
4236
11383dafc318 Fixed bug in getting correct result code for a subprocess executed with a timeout.
Doug Simon <doug.simon@oracle.com>
parents: 4234
diff changeset
693 def _returncode(status):
11383dafc318 Fixed bug in getting correct result code for a subprocess executed with a timeout.
Doug Simon <doug.simon@oracle.com>
parents: 4234
diff changeset
694 if os.WIFSIGNALED(status):
11383dafc318 Fixed bug in getting correct result code for a subprocess executed with a timeout.
Doug Simon <doug.simon@oracle.com>
parents: 4234
diff changeset
695 return -os.WTERMSIG(status)
11383dafc318 Fixed bug in getting correct result code for a subprocess executed with a timeout.
Doug Simon <doug.simon@oracle.com>
parents: 4234
diff changeset
696 elif os.WIFEXITED(status):
11383dafc318 Fixed bug in getting correct result code for a subprocess executed with a timeout.
Doug Simon <doug.simon@oracle.com>
parents: 4234
diff changeset
697 return os.WEXITSTATUS(status)
11383dafc318 Fixed bug in getting correct result code for a subprocess executed with a timeout.
Doug Simon <doug.simon@oracle.com>
parents: 4234
diff changeset
698 else:
11383dafc318 Fixed bug in getting correct result code for a subprocess executed with a timeout.
Doug Simon <doug.simon@oracle.com>
parents: 4234
diff changeset
699 # Should never happen
11383dafc318 Fixed bug in getting correct result code for a subprocess executed with a timeout.
Doug Simon <doug.simon@oracle.com>
parents: 4234
diff changeset
700 raise RuntimeError("Unknown child exit status!")
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
701
4158
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
702 end = time.time() + timeout
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
703 delay = 0.0005
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
704 while True:
4236
11383dafc318 Fixed bug in getting correct result code for a subprocess executed with a timeout.
Doug Simon <doug.simon@oracle.com>
parents: 4234
diff changeset
705 (pid, status) = _waitpid(process.pid)
4158
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
706 if pid == process.pid:
4236
11383dafc318 Fixed bug in getting correct result code for a subprocess executed with a timeout.
Doug Simon <doug.simon@oracle.com>
parents: 4234
diff changeset
707 return _returncode(status)
4158
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
708 remaining = end - time.time()
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
709 if remaining <= 0:
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
710 abort('Process timed out after {0} seconds: {1}'.format(timeout, ' '.join(args)))
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
711 delay = min(delay * 2, remaining, .05)
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
712 time.sleep(delay)
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
713
4242
3e25132be4b4 Disabled eager resolution of libraries as they are defined.
Doug Simon <doug.simon@oracle.com>
parents: 4241
diff changeset
714 # Makes the current subprocess accessible to the abort() function
3e25132be4b4 Disabled eager resolution of libraries as they are defined.
Doug Simon <doug.simon@oracle.com>
parents: 4241
diff changeset
715 # This is a tuple of the Popen object and args.
4241
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
716 _currentSubprocess = None
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
717
4660
b06ade6e927c Fixed Ctrl+C for Windows in mx.py
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4482
diff changeset
718 def waitOn(p):
b06ade6e927c Fixed Ctrl+C for Windows in mx.py
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4482
diff changeset
719 if get_os() == 'windows':
b06ade6e927c Fixed Ctrl+C for Windows in mx.py
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4482
diff changeset
720 # on windows use a poll loop, otherwise signal does not get handled
b06ade6e927c Fixed Ctrl+C for Windows in mx.py
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4482
diff changeset
721 retcode = None
b06ade6e927c Fixed Ctrl+C for Windows in mx.py
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4482
diff changeset
722 while retcode == None:
b06ade6e927c Fixed Ctrl+C for Windows in mx.py
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4482
diff changeset
723 retcode = p.poll()
b06ade6e927c Fixed Ctrl+C for Windows in mx.py
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4482
diff changeset
724 time.sleep(0.05)
b06ade6e927c Fixed Ctrl+C for Windows in mx.py
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4482
diff changeset
725 else:
b06ade6e927c Fixed Ctrl+C for Windows in mx.py
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4482
diff changeset
726 retcode = p.wait()
b06ade6e927c Fixed Ctrl+C for Windows in mx.py
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4482
diff changeset
727 return retcode
b06ade6e927c Fixed Ctrl+C for Windows in mx.py
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4482
diff changeset
728
4158
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
729 def run(args, nonZeroIsFatal=True, out=None, err=None, cwd=None, timeout=None):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
730 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
731 Run a command in a subprocess, wait for it to complete and return the exit status of the process.
4158
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
732 If the exit status is non-zero and `nonZeroIsFatal` is true, then mx is exited with
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
733 the same exit status.
4225
339cf8d4904d Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents: 4219
diff changeset
734 Each line of the standard output and error streams of the subprocess are redirected to
339cf8d4904d Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents: 4219
diff changeset
735 out and err if they are callable objects.
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
736 """
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
737
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
738 assert isinstance(args, types.ListType), "'args' must be a list: " + str(args)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
739 for arg in args:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
740 assert isinstance(arg, types.StringTypes), 'argument is not a string: ' + str(arg)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
741
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
742 if _opts.verbose:
5091
54819cdcca7f Added -V option to mx for 'very verbose'which prints the environment variables used for an external command.
Doug Simon <doug.simon@oracle.com>
parents: 5072
diff changeset
743 if _opts.very_verbose:
54819cdcca7f Added -V option to mx for 'very verbose'which prints the environment variables used for an external command.
Doug Simon <doug.simon@oracle.com>
parents: 5072
diff changeset
744 log('Environment variables:')
54819cdcca7f Added -V option to mx for 'very verbose'which prints the environment variables used for an external command.
Doug Simon <doug.simon@oracle.com>
parents: 5072
diff changeset
745 for key in sorted(os.environ.keys()):
54819cdcca7f Added -V option to mx for 'very verbose'which prints the environment variables used for an external command.
Doug Simon <doug.simon@oracle.com>
parents: 5072
diff changeset
746 log(' ' + key + '=' + os.environ[key])
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
747 log(' '.join(args))
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
748
4270
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
749 if timeout is None and _opts.ptimeout != 0:
4241
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
750 timeout = _opts.ptimeout
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
751
4293
d4906ea4255b Handle SIGTERM : killing mx will properly kill subprocesses
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4271
diff changeset
752 global _currentSubprocess
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
753
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
754 try:
4241
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
755 # On Unix, the new subprocess should be in a separate group so that a timeout alarm
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
756 # can use os.killpg() to kill the whole subprocess group
4252
67e88b7624d5 Removed need for GRAAL environment variable on Windows.
Doug Simon <doug.simon@oracle.com>
parents: 4248
diff changeset
757 preexec_fn = None
67e88b7624d5 Removed need for GRAAL environment variable on Windows.
Doug Simon <doug.simon@oracle.com>
parents: 4248
diff changeset
758 creationflags = 0
67e88b7624d5 Removed need for GRAAL environment variable on Windows.
Doug Simon <doug.simon@oracle.com>
parents: 4248
diff changeset
759 if get_os() == 'windows':
67e88b7624d5 Removed need for GRAAL environment variable on Windows.
Doug Simon <doug.simon@oracle.com>
parents: 4248
diff changeset
760 creationflags = subprocess.CREATE_NEW_PROCESS_GROUP
67e88b7624d5 Removed need for GRAAL environment variable on Windows.
Doug Simon <doug.simon@oracle.com>
parents: 4248
diff changeset
761 else:
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
762 preexec_fn = os.setsid
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
763
4225
339cf8d4904d Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents: 4219
diff changeset
764 if not callable(out) and not callable(err) and timeout is None:
4241
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
765 # The preexec_fn=os.setsid
4252
67e88b7624d5 Removed need for GRAAL environment variable on Windows.
Doug Simon <doug.simon@oracle.com>
parents: 4248
diff changeset
766 p = subprocess.Popen(args, cwd=cwd, preexec_fn=preexec_fn, creationflags=creationflags)
4242
3e25132be4b4 Disabled eager resolution of libraries as they are defined.
Doug Simon <doug.simon@oracle.com>
parents: 4241
diff changeset
767 _currentSubprocess = (p, args)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
768 retcode = waitOn(p)
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
769 else:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
770 def redirect(stream, f):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
771 for line in iter(stream.readline, ''):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
772 f(line)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
773 stream.close()
4225
339cf8d4904d Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents: 4219
diff changeset
774 stdout=out if not callable(out) else subprocess.PIPE
339cf8d4904d Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents: 4219
diff changeset
775 stderr=err if not callable(err) else subprocess.PIPE
4252
67e88b7624d5 Removed need for GRAAL environment variable on Windows.
Doug Simon <doug.simon@oracle.com>
parents: 4248
diff changeset
776 p = subprocess.Popen(args, cwd=cwd, stdout=stdout, stderr=stderr, preexec_fn=preexec_fn, creationflags=creationflags)
4241
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
777 _currentSubprocess = (p, args)
4225
339cf8d4904d Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents: 4219
diff changeset
778 if callable(out):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
779 t = Thread(target=redirect, args=(p.stdout, out))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
780 t.daemon = True # thread dies with the program
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
781 t.start()
4225
339cf8d4904d Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents: 4219
diff changeset
782 if callable(err):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
783 t = Thread(target=redirect, args=(p.stderr, err))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
784 t.daemon = True # thread dies with the program
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
785 t.start()
4161
8c507a8dd6a4 Interpret '--timeout 0' correctly (i.e. as no timeout).
Doug Simon <doug.simon@oracle.com>
parents: 4158
diff changeset
786 if timeout is None or timeout == 0:
4660
b06ade6e927c Fixed Ctrl+C for Windows in mx.py
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4482
diff changeset
787 retcode = waitOn(p)
4158
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
788 else:
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
789 if get_os() == 'windows':
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
790 abort('Use of timeout not (yet) supported on Windows')
f3a50640333b Added support for specifying a timeout when running an external command.
Doug Simon <doug.simon@oracle.com>
parents: 4150
diff changeset
791 retcode = _waitWithTimeout(p, args, timeout)
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
792 except OSError as e:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
793 log('Error executing \'' + ' '.join(args) + '\': ' + str(e))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
794 if _opts.verbose:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
795 raise e
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
796 abort(e.errno)
4242
3e25132be4b4 Disabled eager resolution of libraries as they are defined.
Doug Simon <doug.simon@oracle.com>
parents: 4241
diff changeset
797 except KeyboardInterrupt:
3e25132be4b4 Disabled eager resolution of libraries as they are defined.
Doug Simon <doug.simon@oracle.com>
parents: 4241
diff changeset
798 abort(1)
4241
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
799 finally:
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
800 _currentSubprocess = None
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
801
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
802 if retcode and nonZeroIsFatal:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
803 if _opts.verbose:
5091
54819cdcca7f Added -V option to mx for 'very verbose'which prints the environment variables used for an external command.
Doug Simon <doug.simon@oracle.com>
parents: 5072
diff changeset
804 if _opts.very_verbose:
54819cdcca7f Added -V option to mx for 'very verbose'which prints the environment variables used for an external command.
Doug Simon <doug.simon@oracle.com>
parents: 5072
diff changeset
805 raise subprocess.CalledProcessError(retcode, ' '.join(args))
54819cdcca7f Added -V option to mx for 'very verbose'which prints the environment variables used for an external command.
Doug Simon <doug.simon@oracle.com>
parents: 5072
diff changeset
806 else:
54819cdcca7f Added -V option to mx for 'very verbose'which prints the environment variables used for an external command.
Doug Simon <doug.simon@oracle.com>
parents: 5072
diff changeset
807 log('[exit code: ' + str(retcode)+ ']')
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
808 abort(retcode)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
809
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
810 return retcode
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
811
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
812 def exe_suffix(name):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
813 """
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
814 Gets the platform specific suffix for an executable
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
815 """
4258
8d2c14f722ac mx.py: fix OS detection in exe_suffix()
Andreas Woess <andreas.woess@jku.at>
parents: 4257
diff changeset
816 if get_os() == 'windows':
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
817 return name + '.exe'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
818 return name
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
819
4482
7903b6c28f9c Add hsdis command to mx
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4396
diff changeset
820 def lib_suffix(name):
7903b6c28f9c Add hsdis command to mx
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4396
diff changeset
821 """
7903b6c28f9c Add hsdis command to mx
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4396
diff changeset
822 Gets the platform specific suffix for a library
7903b6c28f9c Add hsdis command to mx
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4396
diff changeset
823 """
7903b6c28f9c Add hsdis command to mx
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4396
diff changeset
824 os = get_os();
7903b6c28f9c Add hsdis command to mx
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4396
diff changeset
825 if os == 'windows':
7903b6c28f9c Add hsdis command to mx
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4396
diff changeset
826 return name + '.dll'
5189
6fbf12b8e572 automated download of hsdis lib if PrintAssembly option is used; added support for hsdis on the Mac
Doug Simon <doug.simon@oracle.com>
parents: 5171
diff changeset
827 if os == 'linux' or os == 'solaris':
4482
7903b6c28f9c Add hsdis command to mx
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4396
diff changeset
828 return name + '.so'
5189
6fbf12b8e572 automated download of hsdis lib if PrintAssembly option is used; added support for hsdis on the Mac
Doug Simon <doug.simon@oracle.com>
parents: 5171
diff changeset
829 if os == 'darwin':
6fbf12b8e572 automated download of hsdis lib if PrintAssembly option is used; added support for hsdis on the Mac
Doug Simon <doug.simon@oracle.com>
parents: 5171
diff changeset
830 return name + '.dylib'
4482
7903b6c28f9c Add hsdis command to mx
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4396
diff changeset
831 return name
7903b6c28f9c Add hsdis command to mx
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 4396
diff changeset
832
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
833 """
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
834 A JavaCompliance simplifies comparing Java compliance values extracted from a JDK version string.
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
835 """
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
836 class JavaCompliance:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
837 def __init__(self, ver):
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
838 m = re.match('1\.(\d+).*', ver)
5071
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
839 assert m is not None, 'not a recognized version string: ' + ver
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
840 self.value = int(m.group(1))
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
841
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
842 def __str__ (self):
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
843 return '1.' + str(self.value)
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
844
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
845 def __cmp__ (self, other):
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
846 if isinstance(other, types.StringType):
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
847 other = JavaCompliance(other)
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
848
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
849 return cmp(self.value, other.value)
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
850
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
851 """
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
852 A JavaConfig object encapsulates info on how Java commands are run.
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
853 """
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
854 class JavaConfig:
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
855 def __init__(self, opts):
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
856 self.jdk = opts.java_home
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
857 self.debug_port = opts.java_dbg_port
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
858 self.java = exe_suffix(join(self.jdk, 'bin', 'java'))
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
859 self.javac = exe_suffix(join(self.jdk, 'bin', 'javac'))
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
860 self.javap = exe_suffix(join(self.jdk, 'bin', 'javap'))
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
861 self.javadoc = exe_suffix(join(self.jdk, 'bin', 'javadoc'))
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
862 self._bootclasspath = None
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
863
4257
32b8274f52ad Made 'mx ideinit' resolve library dependencies eagerly as well as put absolute paths into the generated Eclipse project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4252
diff changeset
864 if not exists(self.java):
32b8274f52ad Made 'mx ideinit' resolve library dependencies eagerly as well as put absolute paths into the generated Eclipse project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4252
diff changeset
865 abort('Java launcher derived from JAVA_HOME does not exist: ' + self.java)
32b8274f52ad Made 'mx ideinit' resolve library dependencies eagerly as well as put absolute paths into the generated Eclipse project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4252
diff changeset
866
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
867 def delAtAndSplit(s):
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
868 return shlex.split(s.lstrip('@'))
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
869
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
870 self.java_args = delAtAndSplit(_opts.java_args)
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
871 self.java_args_pfx = sum(map(delAtAndSplit, _opts.java_args_pfx), [])
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
872 self.java_args_sfx = sum(map(delAtAndSplit, _opts.java_args_sfx), [])
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
873
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
874 # Prepend the -d64 VM option only if the java command supports it
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
875 try:
4148
bf5efc22fb3f Replace downloading of JDK 7 with copying of host JDK 7.
Doug Simon <doug.simon@oracle.com>
parents: 4147
diff changeset
876 output = subprocess.check_output([self.java, '-d64', '-version'], stderr=subprocess.STDOUT)
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
877 self.java_args = ['-d64'] + self.java_args
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
878 except subprocess.CalledProcessError as e:
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
879 try:
4148
bf5efc22fb3f Replace downloading of JDK 7 with copying of host JDK 7.
Doug Simon <doug.simon@oracle.com>
parents: 4147
diff changeset
880 output = subprocess.check_output([self.java, '-version'], stderr=subprocess.STDOUT)
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
881 except subprocess.CalledProcessError as e:
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
882 print e.output
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
883 abort(e.returncode)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
884
4148
bf5efc22fb3f Replace downloading of JDK 7 with copying of host JDK 7.
Doug Simon <doug.simon@oracle.com>
parents: 4147
diff changeset
885 output = output.split()
bf5efc22fb3f Replace downloading of JDK 7 with copying of host JDK 7.
Doug Simon <doug.simon@oracle.com>
parents: 4147
diff changeset
886 assert output[1] == 'version'
bf5efc22fb3f Replace downloading of JDK 7 with copying of host JDK 7.
Doug Simon <doug.simon@oracle.com>
parents: 4147
diff changeset
887 self.version = output[2].strip('"')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
888 self.javaCompliance = JavaCompliance(self.version)
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
889
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
890 if self.debug_port is not None:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
891 self.java_args += ['-Xdebug', '-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=' + str(self.debug_port)]
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
892
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
893 def format_cmd(self, args):
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
894 return [self.java] + self.java_args_pfx + self.java_args + self.java_args_sfx + args
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
895
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
896 def bootclasspath(self):
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
897 if self._bootclasspath is None:
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
898 tmpDir = tempfile.mkdtemp()
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
899 try:
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
900 src = join(tmpDir, 'bootclasspath.java')
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
901 with open(src, 'w') as fp:
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
902 print >> fp, """
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
903 public class bootclasspath {
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
904 public static void main(String[] args) {
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
905 String s = System.getProperty("sun.boot.class.path");
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
906 if (s != null) {
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
907 System.out.println(s);
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
908 }
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
909 }
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
910 }"""
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
911 subprocess.check_call([self.javac, '-d', tmpDir, src])
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
912 self._bootclasspath = subprocess.check_output([self.java, '-cp', tmpDir, 'bootclasspath'])
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
913 finally:
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
914 shutil.rmtree(tmpDir)
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
915 return self._bootclasspath
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
916
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
917 def check_get_env(key):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
918 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
919 Gets an environment variable, aborting with a useful message if it is not set.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
920 """
4178
d1b26c17910a Add the Dacapo benchmarks to the "lib" folder instead of using the environment variable. Fixed an issue in the downloader.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4161
diff changeset
921 value = get_env(key)
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
922 if value is None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
923 abort('Required environment variable ' + key + ' must be set')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
924 return value
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
925
4227
1fe200db8c30 Environment variables for HotSpot's make are only set by mx.build if they aren't already defined.
Doug Simon <doug.simon@oracle.com>
parents: 4226
diff changeset
926 def get_env(key, default=None):
4178
d1b26c17910a Add the Dacapo benchmarks to the "lib" folder instead of using the environment variable. Fixed an issue in the downloader.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4161
diff changeset
927 """
d1b26c17910a Add the Dacapo benchmarks to the "lib" folder instead of using the environment variable. Fixed an issue in the downloader.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4161
diff changeset
928 Gets an environment variable.
d1b26c17910a Add the Dacapo benchmarks to the "lib" folder instead of using the environment variable. Fixed an issue in the downloader.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4161
diff changeset
929 """
4227
1fe200db8c30 Environment variables for HotSpot's make are only set by mx.build if they aren't already defined.
Doug Simon <doug.simon@oracle.com>
parents: 4226
diff changeset
930 value = os.environ.get(key, default)
4178
d1b26c17910a Add the Dacapo benchmarks to the "lib" folder instead of using the environment variable. Fixed an issue in the downloader.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4161
diff changeset
931 return value
d1b26c17910a Add the Dacapo benchmarks to the "lib" folder instead of using the environment variable. Fixed an issue in the downloader.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4161
diff changeset
932
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
933 def log(msg=None):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
934 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
935 Write a message to the console.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
936 All script output goes through this method thus allowing a subclass
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
937 to redirect it.
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
938 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
939 if msg is None:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
940 print
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
941 else:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
942 print msg
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
943
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
944 def expand_project_in_class_path_arg(cpArg):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
945 cp = []
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
946 for part in cpArg.split(os.pathsep):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
947 if part.startswith('@'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
948 cp += classpath(part[1:]).split(os.pathsep)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
949 else:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
950 cp.append(part)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
951 return os.pathsep.join(cp)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
952
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
953 def expand_project_in_args(args):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
954 for i in range(len(args)):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
955 if args[i] == '-cp' or args[i] == '-classpath':
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
956 if i + 1 < len(args):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
957 args[i + 1] = expand_project_in_class_path_arg(args[i + 1])
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
958 return
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
959
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
960
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
961 def gmake_cmd():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
962 for a in ['make', 'gmake', 'gnumake']:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
963 try:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
964 output = subprocess.check_output([a, '--version'])
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
965 if 'GNU' in output:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
966 return a;
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
967 except:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
968 pass
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
969 abort('Could not find a GNU make executable on the current path.')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
970
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
971 def expandvars_in_property(value):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
972 result = expandvars(value)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
973 if '$' in result or '%' in result:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
974 abort('Property contains an undefined environment variable: ' + value)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
975 return result
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
976
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
977
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
978 def abort(codeOrMessage):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
979 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
980 Aborts the program with a SystemExit exception.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
981 If 'codeOrMessage' is a plain integer, it specifies the system exit status;
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
982 if it is None, the exit status is zero; if it has another type (such as a string),
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
983 the object's value is printed and the exit status is one.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
984 """
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
985
4242
3e25132be4b4 Disabled eager resolution of libraries as they are defined.
Doug Simon <doug.simon@oracle.com>
parents: 4241
diff changeset
986 #import traceback
3e25132be4b4 Disabled eager resolution of libraries as they are defined.
Doug Simon <doug.simon@oracle.com>
parents: 4241
diff changeset
987 #traceback.print_stack()
3e25132be4b4 Disabled eager resolution of libraries as they are defined.
Doug Simon <doug.simon@oracle.com>
parents: 4241
diff changeset
988 currentSubprocess = _currentSubprocess
3e25132be4b4 Disabled eager resolution of libraries as they are defined.
Doug Simon <doug.simon@oracle.com>
parents: 4241
diff changeset
989 if currentSubprocess is not None:
3e25132be4b4 Disabled eager resolution of libraries as they are defined.
Doug Simon <doug.simon@oracle.com>
parents: 4241
diff changeset
990 p, _ = currentSubprocess
4252
67e88b7624d5 Removed need for GRAAL environment variable on Windows.
Doug Simon <doug.simon@oracle.com>
parents: 4248
diff changeset
991 if get_os() == 'windows':
67e88b7624d5 Removed need for GRAAL environment variable on Windows.
Doug Simon <doug.simon@oracle.com>
parents: 4248
diff changeset
992 p.kill()
67e88b7624d5 Removed need for GRAAL environment variable on Windows.
Doug Simon <doug.simon@oracle.com>
parents: 4248
diff changeset
993 else:
67e88b7624d5 Removed need for GRAAL environment variable on Windows.
Doug Simon <doug.simon@oracle.com>
parents: 4248
diff changeset
994 _kill_process_group(p.pid)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
995
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
996 raise SystemExit(codeOrMessage)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
997
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
998 def download(path, urls, verbose=False):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
999 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1000 Attempts to downloads content for each URL in a list, stopping after the first successful download.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1001 If the content cannot be retrieved from any URL, the program is aborted. The downloaded content
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1002 is written to the file indicated by 'path'.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1003 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1004 d = dirname(path)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1005 if d != '' and not exists(d):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1006 os.makedirs(d)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1007
4188
148fa38782e8 Downloads are attempted via Java first since it shows a progress counter.
Doug Simon <doug.simon@oracle.com>
parents: 4186
diff changeset
1008 # Try it with the Java tool first since it can show a progress counter
148fa38782e8 Downloads are attempted via Java first since it shows a progress counter.
Doug Simon <doug.simon@oracle.com>
parents: 4186
diff changeset
1009 myDir = dirname(__file__)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1010
4188
148fa38782e8 Downloads are attempted via Java first since it shows a progress counter.
Doug Simon <doug.simon@oracle.com>
parents: 4186
diff changeset
1011 javaSource = join(myDir, 'URLConnectionDownload.java')
148fa38782e8 Downloads are attempted via Java first since it shows a progress counter.
Doug Simon <doug.simon@oracle.com>
parents: 4186
diff changeset
1012 javaClass = join(myDir, 'URLConnectionDownload.class')
148fa38782e8 Downloads are attempted via Java first since it shows a progress counter.
Doug Simon <doug.simon@oracle.com>
parents: 4186
diff changeset
1013 if not exists(javaClass) or getmtime(javaClass) < getmtime(javaSource):
148fa38782e8 Downloads are attempted via Java first since it shows a progress counter.
Doug Simon <doug.simon@oracle.com>
parents: 4186
diff changeset
1014 subprocess.check_call([java().javac, '-d', myDir, javaSource])
148fa38782e8 Downloads are attempted via Java first since it shows a progress counter.
Doug Simon <doug.simon@oracle.com>
parents: 4186
diff changeset
1015 if run([java().java, '-cp', myDir, 'URLConnectionDownload', path] + urls) == 0:
148fa38782e8 Downloads are attempted via Java first since it shows a progress counter.
Doug Simon <doug.simon@oracle.com>
parents: 4186
diff changeset
1016 return
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1017
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1018 def url_open(url):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1019 userAgent = 'Mozilla/5.0 (compatible)'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1020 headers = { 'User-Agent' : userAgent }
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1021 req = urllib2.Request(url, headers=headers)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1022 return urllib2.urlopen(req);
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1023
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1024 for url in urls:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1025 try:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1026 if (verbose):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1027 log('Downloading ' + url + ' to ' + path)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1028 if url.startswith('zip:') or url.startswith('jar:'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1029 i = url.find('!/')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1030 if i == -1:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1031 abort('Zip or jar URL does not contain "!/": ' + url)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1032 url, _, entry = url[len('zip:'):].partition('!/')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1033 with contextlib.closing(url_open(url)) as f:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1034 data = f.read()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1035 zipdata = StringIO.StringIO(f.read())
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1036
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1037 zf = zipfile.ZipFile(zipdata, 'r')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1038 data = zf.read(entry)
4178
d1b26c17910a Add the Dacapo benchmarks to the "lib" folder instead of using the environment variable. Fixed an issue in the downloader.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4161
diff changeset
1039 with open(path, 'wb') as f:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1040 f.write(data)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1041 else:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1042 with contextlib.closing(url_open(url)) as f:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1043 data = f.read()
4178
d1b26c17910a Add the Dacapo benchmarks to the "lib" folder instead of using the environment variable. Fixed an issue in the downloader.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4161
diff changeset
1044 with open(path, 'wb') as f:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1045 f.write(data)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1046 return
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1047 except IOError as e:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1048 log('Error reading from ' + url + ': ' + str(e))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1049 except zipfile.BadZipfile as e:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1050 log('Error in zip file downloaded from ' + url + ': ' + str(e))
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1051
4188
148fa38782e8 Downloads are attempted via Java first since it shows a progress counter.
Doug Simon <doug.simon@oracle.com>
parents: 4186
diff changeset
1052 abort('Could not download to ' + path + ' from any of the following URLs:\n\n ' +
148fa38782e8 Downloads are attempted via Java first since it shows a progress counter.
Doug Simon <doug.simon@oracle.com>
parents: 4186
diff changeset
1053 '\n '.join(urls) + '\n\nPlease use a web browser to do the download manually')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1054
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1055 def update_file(path, content):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1056 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1057 Updates a file with some given content if the content differs from what's in
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1058 the file already. The return value indicates if the file was updated.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1059 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1060 existed = exists(path)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1061 try:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1062 old = None
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1063 if existed:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1064 with open(path, 'rb') as f:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1065 old = f.read()
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1066
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1067 if old == content:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1068 return False
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1069
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1070 with open(path, 'wb') as f:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1071 f.write(content)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1072
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1073 log(('modified ' if existed else 'created ') + path)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1074 return True;
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1075 except IOError as e:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1076 abort('Error while writing to ' + path + ': ' + str(e));
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1077
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1078 # Builtin commands
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1079
4226
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1080 def build(args, parser=None):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1081 """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
1082
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1083 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
1084 and linkers for the various source code types."""
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1085
4234
057620486c90 Improved time stamps of gate tasks to show duration of each task explicitly.
Doug Simon <doug.simon@oracle.com>
parents: 4227
diff changeset
1086 suppliedParser = parser is not None
057620486c90 Improved time stamps of gate tasks to show duration of each task explicitly.
Doug Simon <doug.simon@oracle.com>
parents: 4227
diff changeset
1087 if not suppliedParser:
057620486c90 Improved time stamps of gate tasks to show duration of each task explicitly.
Doug Simon <doug.simon@oracle.com>
parents: 4227
diff changeset
1088 parser = ArgumentParser(prog='mx build')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1089
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1090 javaCompliance = java().javaCompliance
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1091
5071
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1092 defaultEcjPath = join(_mainSuite.dir, 'mx', 'ecj.jar')
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
1093
4234
057620486c90 Improved time stamps of gate tasks to show duration of each task explicitly.
Doug Simon <doug.simon@oracle.com>
parents: 4227
diff changeset
1094 parser = parser if parser is not None else ArgumentParser(prog='mx build')
5239
b9db4fee6eb2 skip a native build if all files in src and make are older than the timestamp of the previous build
Doug Simon <doug.simon@oracle.com>
parents: 5219
diff changeset
1095 parser.add_argument('-f', action='store_true', dest='force', help='force build (disables timestamp checking)')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1096 parser.add_argument('-c', action='store_true', dest='clean', help='removes existing build output')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1097 parser.add_argument('--source', dest='compliance', help='Java compliance level', default=str(javaCompliance))
4147
55376d8953a6 Improved 'build' and 'clean' commands.
Doug Simon <doug.simon@oracle.com>
parents: 4145
diff changeset
1098 parser.add_argument('--Wapi', action='store_true', dest='warnAPI', help='show warnings about using internal APIs')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1099 parser.add_argument('--projects', action='store', help='comma separated projects to build (omit to build all projects)')
4226
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1100 parser.add_argument('--no-java', action='store_false', dest='java', help='do not build Java projects')
4147
55376d8953a6 Improved 'build' and 'clean' commands.
Doug Simon <doug.simon@oracle.com>
parents: 4145
diff changeset
1101 parser.add_argument('--no-native', action='store_false', dest='native', help='do not build native projects')
5071
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1102 parser.add_argument('--jdt', help='Eclipse installation or path to ecj.jar for using the Eclipse batch compiler (default: ' + defaultEcjPath + ')', default=defaultEcjPath, metavar='<path>')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1103
4234
057620486c90 Improved time stamps of gate tasks to show duration of each task explicitly.
Doug Simon <doug.simon@oracle.com>
parents: 4227
diff changeset
1104 if suppliedParser:
057620486c90 Improved time stamps of gate tasks to show duration of each task explicitly.
Doug Simon <doug.simon@oracle.com>
parents: 4227
diff changeset
1105 parser.add_argument('remainder', nargs=REMAINDER, metavar='...')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1106
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1107 args = parser.parse_args(args)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1108
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1109 jdtJar = None
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1110 if args.jdt is not None:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1111 if args.jdt.endswith('.jar'):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1112 jdtJar=args.jdt
5071
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1113 if not exists(jdtJar) and os.path.abspath(jdtJar) == os.path.abspath(defaultEcjPath):
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1114 # Silently ignore JDT if default location is used but not ecj.jar exists there
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1115 jdtJar = None
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1116 elif isdir(args.jdt):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1117 plugins = join(args.jdt, 'plugins')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1118 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
1119 if len(choices) != 0:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1120 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
1121
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1122 built = set()
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1123
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1124 projects = None
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1125 if args.projects is not None:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1126 projects = args.projects.split(',')
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1127
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1128 for p in sorted_deps(projects):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1129 if p.native:
4226
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1130 if args.native:
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1131 log('Calling GNU make {0}...'.format(p.dir))
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1132
4226
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1133 if args.clean:
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1134 run([gmake_cmd(), 'clean'], cwd=p.dir)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1135
4226
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1136 run([gmake_cmd()], cwd=p.dir)
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1137 built.add(p.name)
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1138 continue
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1139 else:
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1140 if not args.java:
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1141 continue
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1142
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1143 # skip building this Java project if its Java compliance level is "higher" than the configured JDK
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1144 if javaCompliance < p.javaCompliance:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1145 log('Excluding {0} from build (Java compliance level {1} required)'.format(p.name, p.javaCompliance))
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1146 continue
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1147
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1148
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1149 outputDir = p.output_dir()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1150 if exists(outputDir):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1151 if args.clean:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1152 log('Cleaning {0}...'.format(outputDir))
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1153 shutil.rmtree(outputDir)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1154 os.mkdir(outputDir)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1155 else:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1156 os.mkdir(outputDir)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1157
4225
339cf8d4904d Made mx.run work properly when stderr is redirected to stdout.
Doug Simon <doug.simon@oracle.com>
parents: 4219
diff changeset
1158 cp = classpath(p.name, includeSelf=True)
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1159 sourceDirs = p.source_dirs()
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1160 mustBuild = args.force
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1161 if not mustBuild:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1162 for dep in p.all_deps([], False):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1163 if dep.name in built:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1164 mustBuild = True
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1165
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1166 jasminAvailable = None
4247
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1167 javafilelist = []
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1168 for sourceDir in sourceDirs:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1169 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
1170 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
1171 javafilelist += javafiles
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1172
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1173 # Copy all non Java resources or assemble Jasmin files
4247
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1174 nonjavafilelist = [join(root, name) for name in files if not name.endswith('.java')]
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1175 for src in nonjavafilelist:
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1176 if src.endswith('.jasm'):
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1177 className = None
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1178 with open(src) as f:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1179 for line in f:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1180 if line.startswith('.class '):
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1181 className = line.split()[-1]
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1182 break
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1183
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1184 if className is not None:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1185 jasminOutputDir = p.jasmin_output_dir()
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1186 classFile = join(jasminOutputDir, className.replace('/', os.sep) + '.class')
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1187 if exists(dirname(classFile)) and (not exists(classFile) or os.path.getmtime(classFile) < os.path.getmtime(src)):
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1188 if jasminAvailable is None:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1189 try:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1190 with open(os.devnull) as devnull:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1191 subprocess.call('jasmin', stdout=devnull, stderr=subprocess.STDOUT)
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1192 jasminAvailable = True
5071
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1193 except OSError:
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1194 jasminAvailable = False
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1195
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1196 if jasminAvailable:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1197 log('Assembling Jasmin file ' + src)
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1198 run(['jasmin', '-d', jasminOutputDir, src])
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1199 else:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1200 log('The jasmin executable could not be found - skipping ' + src)
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1201 with file(classFile, 'a'):
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1202 os.utime(classFile, None)
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1203
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1204 else:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1205 log('could not file .class directive in Jasmin source: ' + src)
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1206 else:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1207 dst = join(outputDir, src[len(sourceDir) + 1:])
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1208 if exists(dirname(dst)) and (not exists(dst) or os.path.getmtime(dst) != os.path.getmtime(src)):
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1209 shutil.copyfile(src, dst)
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1210
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1211 if not mustBuild:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1212 for javafile in javafiles:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1213 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
1214 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
1215 mustBuild = True
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1216 break
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1217
4247
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1218 if not mustBuild:
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1219 log('[all class files for {0} are up to date - skipping]'.format(p.name))
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1220 continue
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1221
4247
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1222 if len(javafilelist) == 0:
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1223 log('[no Java sources for {0} - skipping]'.format(p.name))
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1224 continue
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1225
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1226 built.add(p.name)
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1227
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1228 argfileName = join(p.dir, 'javafilelist.txt')
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1229 argfile = open(argfileName, 'wb')
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1230 argfile.write('\n'.join(javafilelist))
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1231 argfile.close()
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1232
4247
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1233 try:
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1234 if jdtJar is None:
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1235 log('Compiling Java sources for {0} with javac...'.format(p.name))
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1236 errFilt = None
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1237 if not args.warnAPI:
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1238 class Filter:
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1239 """
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1240 Class to errFilt the 'is Sun proprietary API and may be removed in a future release'
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1241 warning when compiling the VM classes.
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1242
4247
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1243 """
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1244 def __init__(self):
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1245 self.c = 0
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1246
4247
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1247 def eat(self, line):
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1248 if 'proprietary API' in line:
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1249 self.c = 2
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1250 elif self.c != 0:
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1251 self.c -= 1
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1252 else:
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1253 log(line.rstrip())
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1254 errFilt=Filter().eat
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1255
4247
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1256 run([java().javac, '-g', '-J-Xmx1g', '-source', args.compliance, '-classpath', cp, '-d', outputDir, '@' + argfile.name], err=errFilt)
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1257 else:
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1258 log('Compiling Java sources for {0} with JDT...'.format(p.name))
5071
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1259 jdtArgs = [java().java, '-Xmx1g', '-jar', jdtJar,
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1260 '-' + args.compliance,
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1261 '-cp', cp, '-g', '-enableJavadoc',
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1262 '-d', outputDir]
4247
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1263 jdtProperties = join(p.dir, '.settings', 'org.eclipse.jdt.core.prefs')
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1264 if not exists(jdtProperties):
5072
f6503609a12d Made the Eclipse properties be automatically generated if they don't exist when building with the Eclipse batch compiler.
Doug Simon <doug.simon@oracle.com>
parents: 5071
diff changeset
1265 # Try to fix a missing properties file by running eclipseinit
f6503609a12d Made the Eclipse properties be automatically generated if they don't exist when building with the Eclipse batch compiler.
Doug Simon <doug.simon@oracle.com>
parents: 5071
diff changeset
1266 eclipseinit([])
f6503609a12d Made the Eclipse properties be automatically generated if they don't exist when building with the Eclipse batch compiler.
Doug Simon <doug.simon@oracle.com>
parents: 5071
diff changeset
1267 if not exists(jdtProperties):
f6503609a12d Made the Eclipse properties be automatically generated if they don't exist when building with the Eclipse batch compiler.
Doug Simon <doug.simon@oracle.com>
parents: 5071
diff changeset
1268 log('JDT properties file {0} not found'.format(jdtProperties))
5071
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1269 else:
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1270 jdtArgs += ['-properties', jdtProperties]
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1271 jdtArgs.append('@' + argfile.name)
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1272 run(jdtArgs)
4247
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1273 finally:
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1274 os.remove(argfileName)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1275
4247
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1276 if suppliedParser:
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1277 return args
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1278 return None
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1279
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1280 def canonicalizeprojects(args):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1281 """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
1282
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1283 The exit code of this command reflects how many files were updated."""
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1284
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1285 changedFiles = 0
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1286 for s in suites():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1287 projectsFile = join(s.dir, 'mx', 'projects')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1288 if not exists(projectsFile):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1289 continue
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1290 with open(projectsFile) as f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1291 out = StringIO.StringIO()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1292 pattern = re.compile('project@([^@]+)@dependencies=.*')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1293 for line in f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1294 line = line.strip()
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1295 m = pattern.match(line)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1296 if m is None:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1297 out.write(line + '\n')
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1298 else:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1299 p = project(m.group(1))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1300 out.write('project@' + m.group(1) + '@dependencies=' + ','.join(p.canonical_deps()) + '\n')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1301 content = out.getvalue()
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1302 if update_file(projectsFile, content):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1303 changedFiles += 1
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1304 return changedFiles;
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1305
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1306 def checkstyle(args):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1307 """run Checkstyle on the Java sources
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1308
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1309 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
1310 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
1311
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1312 If no projects are given, then all Java projects are checked."""
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1313
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1314 for p in sorted_deps():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1315 if p.native:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1316 continue
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1317 sourceDirs = p.source_dirs()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1318 dotCheckstyle = join(p.dir, '.checkstyle')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1319
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1320 if not exists(dotCheckstyle):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1321 continue
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1322
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1323 for sourceDir in sourceDirs:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1324 javafilelist = []
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1325 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
1326 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
1327 if len(javafilelist) == 0:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1328 log('[no Java sources in {0} - skipping]'.format(sourceDir))
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1329 continue
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1330
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1331 timestampFile = join(p.suite.dir, 'mx', 'checkstyle-timestamps', sourceDir[len(p.suite.dir) + 1:].replace(os.sep, '_') + '.timestamp')
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1332 if not exists(dirname(timestampFile)):
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1333 os.makedirs(dirname(timestampFile))
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1334 mustCheck = False
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1335 if exists(timestampFile):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1336 timestamp = os.path.getmtime(timestampFile)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1337 for f in javafilelist:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1338 if os.path.getmtime(f) > timestamp:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1339 mustCheck = True
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1340 break
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1341 else:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1342 mustCheck = True
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1343
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1344 if not mustCheck:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1345 log('[all Java sources in {0} already checked - skipping]'.format(sourceDir))
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1346 continue
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1347
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1348 if exists(timestampFile):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1349 os.utime(timestampFile, None)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1350 else:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1351 file(timestampFile, 'a')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1352
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1353 dotCheckstyleXML = xml.dom.minidom.parse(dotCheckstyle)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1354 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
1355 configLocation = localCheckConfig.getAttribute('location')
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1356 configType = localCheckConfig.getAttribute('type')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1357 if configType == 'project':
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1358 # Eclipse plugin "Project Relative Configuration" format:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1359 #
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1360 # '/<project_name>/<suffix>'
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1361 #
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1362 if configLocation.startswith('/'):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1363 name, _, suffix = configLocation.lstrip('/').partition('/')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1364 config = join(project(name).dir, suffix)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1365 else:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1366 config = join(p.dir, configLocation)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1367 else:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1368 log('[unknown Checkstyle configuration type "' + configType + '" in {0} - skipping]'.format(sourceDir))
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1369 continue
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1370
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1371 exclude = join(p.dir, '.checkstyle.exclude')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1372
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1373 if exists(exclude):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1374 with open(exclude) as f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1375 # Convert patterns to OS separators
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1376 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
1377 def match(name):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1378 for p in patterns:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1379 if p in name:
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1380 if _opts.verbose:
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1381 log('excluding: ' + name)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1382 return True
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1383 return False
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1384
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1385 javafilelist = [name for name in javafilelist if not match(name)]
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1386
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1387 auditfileName = join(p.dir, 'checkstyleOutput.txt')
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1388 log('Running Checkstyle on {0} using {1}...'.format(sourceDir, config))
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1389
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1390 try:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1391
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1392 # 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
1393 # 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
1394 # 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
1395 # 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
1396 while len(javafilelist) != 0:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1397 i = 0
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1398 size = 0
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1399 while i < len(javafilelist):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1400 s = len(javafilelist[i]) + 1
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1401 if (size + s < 30000):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1402 size += s
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1403 i += 1
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1404 else:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1405 break
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1406
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1407 batch = javafilelist[:i]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1408 javafilelist = javafilelist[i:]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1409 try:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1410 run_java(['-Xmx1g', '-jar', library('CHECKSTYLE').get_path(True), '-c', config, '-o', auditfileName] + batch)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1411 finally:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1412 if exists(auditfileName):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1413 with open(auditfileName) as f:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1414 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
1415 if len(warnings) != 0:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1416 map(log, warnings)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1417 return 1
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1418 finally:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1419 if exists(auditfileName):
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1420 os.unlink(auditfileName)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1421 return 0
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1422
4226
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1423 def clean(args, parser=None):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1424 """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
1425
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1426 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
1427 generated images.
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1428 """
4247
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1429
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1430 suppliedParser = parser is not None
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1431
4247
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1432 parser = parser if suppliedParser else ArgumentParser(prog='mx build');
4226
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1433 parser.add_argument('--no-native', action='store_false', dest='native', help='do not clean native projects')
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1434 parser.add_argument('--no-java', action='store_false', dest='java', help='do not clean Java projects')
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1435
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1436 args = parser.parse_args(args)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1437
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1438 for p in projects():
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1439 if p.native:
4226
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1440 if args.native:
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1441 run([gmake_cmd(), '-C', p.dir, 'clean'])
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1442 else:
4226
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1443 if args.java:
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1444 outputDir = p.output_dir()
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1445 if outputDir != '' and exists(outputDir):
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1446 log('Removing {0}...'.format(outputDir))
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
1447 shutil.rmtree(outputDir)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1448
4247
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1449 if suppliedParser:
3f6c6e61614e Changed 'mx build' such that all Java sources for a project are compiled together instead of by source directory.
Doug Simon <doug.simon@oracle.com>
parents: 4242
diff changeset
1450 return args
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1451
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1452 def about(args):
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1453 """show the 'man page' for mx"""
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1454 print __doc__
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1455
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1456 def help_(args):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1457 """show help for a given command
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1458
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1459 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
1460
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1461 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
1462 if len(args) == 0:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1463 _argParser.print_help()
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1464 return
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1465
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1466 name = args[0]
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1467 if not commands.has_key(name):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1468 _argParser.error('unknown command: ' + name)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1469
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1470 value = commands[name]
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1471 (func, usage) = value[:2]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1472 doc = func.__doc__
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1473 if len(value) > 2:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1474 docArgs = value[2:]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1475 fmtArgs = []
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1476 for d in docArgs:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1477 if isinstance(d, Callable):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
1478 fmtArgs += [d()]
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1479 else:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1480 fmtArgs += [str(d)]
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1481 doc = doc.format(*fmtArgs)
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1482 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
1483
4301
fad6f1ebeb44 mx.py: new projectgraph command
Lukas Stadler <lukas.stadler@jku.at>
parents: 4271
diff changeset
1484 def projectgraph(args, suite=None):
fad6f1ebeb44 mx.py: new projectgraph command
Lukas Stadler <lukas.stadler@jku.at>
parents: 4271
diff changeset
1485 """create dot graph for project structure ("mx projectgraph | dot -Tpdf -oprojects.pdf")"""
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1486
4301
fad6f1ebeb44 mx.py: new projectgraph command
Lukas Stadler <lukas.stadler@jku.at>
parents: 4271
diff changeset
1487 print 'digraph projects {'
fad6f1ebeb44 mx.py: new projectgraph command
Lukas Stadler <lukas.stadler@jku.at>
parents: 4271
diff changeset
1488 print 'rankdir=BT;'
fad6f1ebeb44 mx.py: new projectgraph command
Lukas Stadler <lukas.stadler@jku.at>
parents: 4271
diff changeset
1489 print 'node [shape=rect];'
fad6f1ebeb44 mx.py: new projectgraph command
Lukas Stadler <lukas.stadler@jku.at>
parents: 4271
diff changeset
1490 for p in projects():
fad6f1ebeb44 mx.py: new projectgraph command
Lukas Stadler <lukas.stadler@jku.at>
parents: 4271
diff changeset
1491 for dep in p.canonical_deps():
fad6f1ebeb44 mx.py: new projectgraph command
Lukas Stadler <lukas.stadler@jku.at>
parents: 4271
diff changeset
1492 print '"' + p.name + '"->"' + dep + '"'
fad6f1ebeb44 mx.py: new projectgraph command
Lukas Stadler <lukas.stadler@jku.at>
parents: 4271
diff changeset
1493 print '}'
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
1494
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
1495
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1496 def _source_locator_memento(deps):
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
1497 slm = XMLDoc()
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1498 slm.open('sourceLookupDirector')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1499 slm.open('sourceContainers', {'duplicates' : 'false'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1500
5252
1a9a048386d6 added JRE to source path in generated Eclipse launches
Doug Simon <doug.simon@oracle.com>
parents: 5239
diff changeset
1501 # Every Java program depends on the JRE
1a9a048386d6 added JRE to source path in generated Eclipse launches
Doug Simon <doug.simon@oracle.com>
parents: 5239
diff changeset
1502 memento = XMLDoc().element('classpathContainer', {'path' : 'org.eclipse.jdt.launching.JRE_CONTAINER'}).xml()
1a9a048386d6 added JRE to source path in generated Eclipse launches
Doug Simon <doug.simon@oracle.com>
parents: 5239
diff changeset
1503 slm.element('classpathContainer', {'memento' : memento, 'typeId':'org.eclipse.jdt.launching.sourceContainer.classpathContainer'})
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
1504
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1505 for dep in deps:
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1506 if dep.isLibrary():
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1507 if hasattr(dep, 'eclipse.container'):
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
1508 memento = XMLDoc().element('classpathContainer', {'path' : getattr(dep, 'eclipse.container')}).xml()
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1509 slm.element('classpathContainer', {'memento' : memento, 'typeId':'org.eclipse.jdt.launching.sourceContainer.classpathContainer'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1510 else:
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
1511 memento = XMLDoc().element('javaProject', {'name' : dep.name}).xml()
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1512 slm.element('container', {'memento' : memento, 'typeId':'org.eclipse.jdt.launching.sourceContainer.javaProject'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1513
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1514 slm.close('sourceContainers')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1515 slm.close('sourceLookupDirector')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1516 return slm
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1517
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1518 def make_eclipse_attach(hostname, port, name=None, deps=[]):
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1519 """
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1520 Creates an Eclipse launch configuration file for attaching to a Java process.
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1521 """
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1522 slm = _source_locator_memento(deps)
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
1523 launch = XMLDoc()
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1524 launch.open('launchConfiguration', {'type' : 'org.eclipse.jdt.launching.remoteJavaApplication'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1525 launch.element('stringAttribute', {'key' : 'org.eclipse.debug.core.source_locator_id', 'value' : 'org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1526 launch.element('stringAttribute', {'key' : 'org.eclipse.debug.core.source_locator_memento', 'value' : '%s'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1527 launch.element('booleanAttribute', {'key' : 'org.eclipse.jdt.launching.ALLOW_TERMINATE', 'value' : 'true'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1528 launch.open('mapAttribute', {'key' : 'org.eclipse.jdt.launching.CONNECT_MAP'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1529 launch.element('mapEntry', {'key' : 'hostname', 'value' : hostname})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1530 launch.element('mapEntry', {'key' : 'port', 'value' : port})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1531 launch.close('mapAttribute')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1532 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROJECT_ATTR', 'value' : ''})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1533 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.VM_CONNECTOR_ID', 'value' : 'org.eclipse.jdt.launching.socketAttachConnector'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1534 launch.close('launchConfiguration')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1535 launch = launch.xml(newl='\n') % slm.xml(escape=True)
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
1536
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1537 if name is None:
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1538 name = 'attach-' + hostname + '-' + port
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1539 eclipseLaunches = join('mx', 'eclipse-launches')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1540 if not exists(eclipseLaunches):
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1541 os.makedirs(eclipseLaunches)
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1542 return update_file(join(eclipseLaunches, name + '.launch'), launch)
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1543
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1544 def make_eclipse_launch(javaArgs, jre, name=None, deps=[]):
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1545 """
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1546 Creates an Eclipse launch configuration file for running/debugging a Java command.
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1547 """
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1548 mainClass = None
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1549 vmArgs = []
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1550 appArgs = []
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1551 cp = None
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1552 argsCopy = list(reversed(javaArgs))
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1553 while len(argsCopy) != 0:
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1554 a = argsCopy.pop()
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1555 if a == '-jar':
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1556 mainClass = '-jar'
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1557 appArgs = list(reversed(argsCopy))
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1558 break
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1559 if a == '-cp' or a == '-classpath':
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1560 assert len(argsCopy) != 0
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1561 cp = argsCopy.pop()
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1562 vmArgs.append(a)
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1563 vmArgs.append(cp)
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1564 elif a.startswith('-'):
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1565 vmArgs.append(a)
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1566 else:
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1567 mainClass = a
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1568 appArgs = list(reversed(argsCopy))
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1569 break
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
1570
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1571 if mainClass is None:
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1572 log('Cannot create Eclipse launch configuration without main class or jar file: java ' + ' '.join(javaArgs))
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1573 return False
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
1574
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1575 if name is None:
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1576 if mainClass == '-jar':
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1577 name = basename(appArgs[0])
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1578 if len(appArgs) > 1 and not appArgs[1].startswith('-'):
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1579 name = name + '_' + appArgs[1]
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1580 else:
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1581 name = mainClass
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1582 name = time.strftime('%Y-%m-%d-%H%M%S_' + name)
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1583
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1584 if cp is not None:
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1585 for e in cp.split(os.pathsep):
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1586 for s in suites():
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1587 deps += [p for p in s.projects if e == p.output_dir()]
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1588 deps += [l for l in s.libs if e == l.get_path(False)]
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
1589
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1590 slm = _source_locator_memento(deps)
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
1591
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
1592 launch = XMLDoc()
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1593 launch.open('launchConfiguration', {'type' : 'org.eclipse.jdt.launching.localJavaApplication'})
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1594 launch.element('stringAttribute', {'key' : 'org.eclipse.debug.core.source_locator_id', 'value' : 'org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector'})
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1595 launch.element('stringAttribute', {'key' : 'org.eclipse.debug.core.source_locator_memento', 'value' : '%s'})
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1596 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.JRE_CONTAINER', 'value' : 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/' + jre})
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1597 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.MAIN_TYPE', 'value' : mainClass})
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1598 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROGRAM_ARGUMENTS', 'value' : ' '.join(appArgs)})
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1599 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.PROJECT_ATTR', 'value' : ''})
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1600 launch.element('stringAttribute', {'key' : 'org.eclipse.jdt.launching.VM_ARGUMENTS', 'value' : ' '.join(vmArgs)})
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1601 launch.close('launchConfiguration')
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1602 launch = launch.xml(newl='\n') % slm.xml(escape=True)
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1603
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1604 eclipseLaunches = join('mx', 'eclipse-launches')
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1605 if not exists(eclipseLaunches):
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1606 os.makedirs(eclipseLaunches)
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1607 return update_file(join(eclipseLaunches, name + '.launch'), launch)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1608
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1609 def eclipseinit(args, suite=None):
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1610 """(re)generate Eclipse project configurations"""
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1611
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1612 if suite is None:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1613 suite = _mainSuite
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1614
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1615 for p in projects():
5071
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1616 if p.native:
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1617 continue
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
1618
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1619 if not exists(p.dir):
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1620 os.makedirs(p.dir)
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1621
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
1622 out = XMLDoc()
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1623 out.open('classpath')
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
1624
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1625 for src in p.srcDirs:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1626 srcDir = join(p.dir, src)
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1627 if not exists(srcDir):
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1628 os.mkdir(srcDir)
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1629 out.element('classpathentry', {'kind' : 'src', 'path' : src})
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1630
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1631 # Every Java program depends on the JRE
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1632 out.element('classpathentry', {'kind' : 'con', 'path' : 'org.eclipse.jdt.launching.JRE_CONTAINER'})
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1633
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1634 for dep in p.all_deps([], True):
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1635 if dep == p:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1636 continue;
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1637
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1638 if dep.isLibrary():
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1639 if hasattr(dep, 'eclipse.container'):
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1640 out.element('classpathentry', {'exported' : 'true', 'kind' : 'con', 'path' : getattr(dep, 'eclipse.container')})
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1641 elif hasattr(dep, 'eclipse.project'):
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1642 out.element('classpathentry', {'combineaccessrules' : 'false', 'exported' : 'true', 'kind' : 'src', 'path' : '/' + getattr(dep, 'eclipse.project')})
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1643 else:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1644 path = dep.path
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1645 if dep.mustExist:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1646 dep.get_path(resolve=True)
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1647 if isabs(path):
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1648 out.element('classpathentry', {'exported' : 'true', 'kind' : 'lib', 'path' : path})
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1649 else:
5071
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1650 # Relative paths for "lib" class path entries have various semantics depending on the Eclipse
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1651 # version being used (e.g. see https://bugs.eclipse.org/bugs/show_bug.cgi?id=274737) so it's
9d055af068a8 Made Java builds look for mx/ecj.jar to use Eclipse batch compiler by default.
Doug Simon <doug.simon@oracle.com>
parents: 5032
diff changeset
1652 # safest to simply use absolute paths.
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1653 out.element('classpathentry', {'exported' : 'true', 'kind' : 'lib', 'path' : join(suite.dir, path)})
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1654 else:
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1655 out.element('classpathentry', {'combineaccessrules' : 'false', 'exported' : 'true', 'kind' : 'src', 'path' : '/' + dep.name})
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1656
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1657 out.element('classpathentry', {'kind' : 'output', 'path' : getattr(p, 'eclipse.output', 'bin')})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1658 out.close('classpath')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1659 update_file(join(p.dir, '.classpath'), out.xml(indent='\t', newl='\n'))
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1660
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1661 csConfig = join(project(p.checkstyleProj).dir, '.checkstyle_checks.xml')
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1662 if exists(csConfig):
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
1663 out = XMLDoc()
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1664
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1665 dotCheckstyle = join(p.dir, ".checkstyle")
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1666 checkstyleConfigPath = '/' + p.checkstyleProj + '/.checkstyle_checks.xml'
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1667 out.open('fileset-config', {'file-format-version' : '1.2.0', 'simple-config' : 'true'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1668 out.open('local-check-config', {'name' : 'Checks', 'location' : checkstyleConfigPath, 'type' : 'project', 'description' : ''})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1669 out.element('additional-data', {'name' : 'protect-config-file', 'value' : 'false'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1670 out.close('local-check-config')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1671 out.open('fileset', {'name' : 'all', 'enabled' : 'true', 'check-config-name' : 'Checks', 'local' : 'true'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1672 out.element('file-match-pattern', {'match-pattern' : '.', 'include-pattern' : 'true'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1673 out.close('fileset')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1674 out.open('filter', {'name' : 'all', 'enabled' : 'true', 'check-config-name' : 'Checks', 'local' : 'true'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1675 out.element('filter-data', {'value' : 'java'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1676 out.close('filter')
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1677
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1678 exclude = join(p.dir, '.checkstyle.exclude')
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1679 if exists(exclude):
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1680 out.open('filter', {'name' : 'FilesFromPackage', 'enabled' : 'true'})
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1681 with open(exclude) as f:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1682 for line in f:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1683 if not line.startswith('#'):
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1684 line = line.strip()
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1685 exclDir = join(p.dir, line)
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1686 assert isdir(exclDir), 'excluded source directory listed in ' + exclude + ' does not exist or is not a directory: ' + exclDir
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1687 out.element('filter-data', {'value' : line})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1688 out.close('filter')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1689
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1690 out.close('fileset-config')
5219
ddccd4abdb09 configured test source directory for graal.graph project
Doug Simon <doug.simon@oracle.com>
parents: 5217
diff changeset
1691 update_file(dotCheckstyle, out.xml(indent=' ', newl='\n'))
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1692
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
1693 out = XMLDoc()
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1694 out.open('projectDescription')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1695 out.element('name', data=p.name)
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1696 out.element('comment', data='')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1697 out.element('projects', data='')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1698 out.open('buildSpec')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1699 out.open('buildCommand')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1700 out.element('name', data='org.eclipse.jdt.core.javabuilder')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1701 out.element('arguments', data='')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1702 out.close('buildCommand')
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1703 if exists(csConfig):
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1704 out.open('buildCommand')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1705 out.element('name', data='net.sf.eclipsecs.core.CheckstyleBuilder')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1706 out.element('arguments', data='')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1707 out.close('buildCommand')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1708 out.close('buildSpec')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1709 out.open('natures')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1710 out.element('nature', data='org.eclipse.jdt.core.javanature')
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1711 if exists(csConfig):
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1712 out.element('nature', data='net.sf.eclipsecs.core.CheckstyleNature')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1713 out.close('natures')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1714 out.close('projectDescription')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1715 update_file(join(p.dir, '.project'), out.xml(indent='\t', newl='\n'))
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1716
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1717 settingsDir = join(p.dir, ".settings")
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1718 if not exists(settingsDir):
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1719 os.mkdir(settingsDir)
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1720
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1721 eclipseSettingsDir = join(suite.dir, 'mx', 'eclipse-settings')
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1722 if exists(eclipseSettingsDir):
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1723 for name in os.listdir(eclipseSettingsDir):
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1724 path = join(eclipseSettingsDir, name)
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1725 if isfile(path):
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1726 with open(join(eclipseSettingsDir, name)) as f:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1727 content = f.read()
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1728 content = content.replace('${javaCompliance}', str(p.javaCompliance))
4271
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1729 update_file(join(settingsDir, name), content)
5194
a6eceb5efb0e added --ecl option to mx for saving VM execution(s) as Eclipse launch configurations
Doug Simon <doug.simon@oracle.com>
parents: 5189
diff changeset
1730
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
1731 make_eclipse_attach('localhost', '8000', deps=projects())
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1732
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1733 def netbeansinit(args, suite=None):
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1734 """(re)generate NetBeans project configurations"""
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1735
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1736 if suite is None:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1737 suite = _mainSuite
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1738
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1739 def println(out, obj):
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1740 out.write(str(obj) + '\n')
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1741
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1742 updated = False
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1743 for p in projects():
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1744 if p.native:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1745 continue
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1746
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1747 if not exists(join(p.dir, 'nbproject')):
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1748 os.makedirs(join(p.dir, 'nbproject'))
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1749
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
1750 out = XMLDoc()
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1751 out.open('project', {'name' : p.name, 'default' : 'default', 'basedir' : '.'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1752 out.element('description', data='Builds, tests, and runs the project ' + p.name + '.')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1753 out.element('import', {'file' : 'nbproject/build-impl.xml'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1754 out.close('project')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1755 updated = update_file(join(p.dir, 'build.xml'), out.xml(indent='\t', newl='\n')) or updated
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1756
5217
70777e50f1e6 replace monkey patch with subclassing instead
Doug Simon <doug.simon@oracle.com>
parents: 5198
diff changeset
1757 out = XMLDoc()
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1758 out.open('project', {'xmlns' : 'http://www.netbeans.org/ns/project/1'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1759 out.element('type', data='org.netbeans.modules.java.j2seproject')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1760 out.open('configuration')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1761 out.open('data', {'xmlns' : 'http://www.netbeans.org/ns/j2se-project/3'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1762 out.element('name', data=p.name)
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1763 out.element('explicit-platform', {'explicit-source-supported' : 'true'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1764 out.open('source-roots')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1765 out.element('root', {'id' : 'src.dir'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1766 out.close('source-roots')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1767 out.open('test-roots')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1768 out.element('root', {'id' : 'test.src.dir'})
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1769 out.close('test-roots')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1770 out.close('data')
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
1771
4270
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1772 firstDep = True
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1773 for dep in p.all_deps([], True):
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1774 if dep == p:
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1775 continue;
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1776
4270
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1777 if not dep.isLibrary():
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1778 n = dep.name.replace('.', '_')
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1779 if firstDep:
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1780 out.open('references', {'xmlns' : 'http://www.netbeans.org/ns/ant-project-references/1'})
4270
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1781 firstDep = False
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1782
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1783 out.open('reference')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1784 out.element('foreign-project', data=n)
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1785 out.element('artifact-type', data='jar')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1786 out.element('script', data='build.xml')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1787 out.element('target', data='jar')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1788 out.element('clean-target', data='clean')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1789 out.element('id', data='jar')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1790 out.close('reference')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1791
4270
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1792 if not firstDep:
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1793 out.close('references')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1794
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1795 out.close('configuration')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1796 out.close('project')
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1797 updated = update_file(join(p.dir, 'nbproject', 'project.xml'), out.xml(indent=' ', newl='\n')) or updated
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1798
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1799 out = StringIO.StringIO()
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1800 jdkPlatform = 'JDK_' + java().version
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1801
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1802 content = """
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1803 annotation.processing.enabled=false
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1804 annotation.processing.enabled.in.editor=false
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1805 annotation.processing.processors.list=
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1806 annotation.processing.run.all.processors=true
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1807 annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1808 application.title=""" + p.name + """
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1809 application.vendor=mx
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1810 build.classes.dir=${build.dir}
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1811 build.classes.excludes=**/*.java,**/*.form
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1812 # This directory is removed when the project is cleaned:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1813 build.dir=bin
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1814 build.generated.dir=${build.dir}/generated
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1815 build.generated.sources.dir=${build.dir}/generated-sources
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1816 # Only compile against the classpath explicitly listed here:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1817 build.sysclasspath=ignore
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1818 build.test.classes.dir=${build.dir}/test/classes
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1819 build.test.results.dir=${build.dir}/test/results
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1820 # Uncomment to specify the preferred debugger connection transport:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1821 #debug.transport=dt_socket
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1822 debug.classpath=\\
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1823 ${run.classpath}
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1824 debug.test.classpath=\\
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1825 ${run.test.classpath}
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1826 # This directory is removed when the project is cleaned:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1827 dist.dir=dist
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1828 dist.jar=${dist.dir}/""" + p.name + """.jar
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1829 dist.javadoc.dir=${dist.dir}/javadoc
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1830 endorsed.classpath=
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1831 excludes=
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1832 includes=**
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1833 jar.compress=false
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1834 # Space-separated list of extra javac options
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1835 javac.compilerargs=
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1836 javac.deprecation=false
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1837 javac.processorpath=\\
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1838 ${javac.classpath}
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1839 javac.source=1.7
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1840 javac.target=1.7
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1841 javac.test.classpath=\\
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1842 ${javac.classpath}:\\
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1843 ${build.classes.dir}
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1844 javac.test.processorpath=\\
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1845 ${javac.test.classpath}
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1846 javadoc.additionalparam=
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1847 javadoc.author=false
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1848 javadoc.encoding=${source.encoding}
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1849 javadoc.noindex=false
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1850 javadoc.nonavbar=false
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1851 javadoc.notree=false
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1852 javadoc.private=false
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1853 javadoc.splitindex=true
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1854 javadoc.use=true
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1855 javadoc.version=false
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1856 javadoc.windowtitle=
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1857 main.class=
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1858 manifest.file=manifest.mf
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1859 meta.inf.dir=${src.dir}/META-INF
4270
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1860 mkdist.disabled=false
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1861 platforms.""" + jdkPlatform + """.home=""" + java().jdk + """
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1862 platform.active=""" + jdkPlatform + """
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1863 run.classpath=\\
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1864 ${javac.classpath}:\\
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1865 ${build.classes.dir}
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1866 # Space-separated list of JVM arguments used when running the project
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1867 # (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1868 # or test-sys-prop.name=value to set system properties for unit tests):
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1869 run.jvmargs=
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1870 run.test.classpath=\\
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1871 ${javac.test.classpath}:\\
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1872 ${build.test.classes.dir}
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1873 test.src.dir=
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1874 source.encoding=UTF-8""".replace(':', os.pathsep).replace('/', os.sep)
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1875 print >> out, content
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1876
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1877 mainSrc = True
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1878 for src in p.srcDirs:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1879 srcDir = join(p.dir, src)
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1880 if not exists(srcDir):
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1881 os.mkdir(srcDir)
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1882 ref = 'file.reference.' + p.name + '-' + src
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1883 print >> out, ref + '=' + src
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1884 if mainSrc:
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1885 print >> out, 'src.dir=${' + ref + '}'
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1886 mainSrc = False
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1887 else:
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1888 print >> out, 'src.' + src + '.dir=${' + ref + '}'
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1889
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1890 javacClasspath = []
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1891 for dep in p.all_deps([], True):
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1892 if dep == p:
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1893 continue;
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1894
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1895 if dep.isLibrary():
4271
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1896 if not dep.mustExist:
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1897 continue
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1898 path = dep.get_path(resolve=True)
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1899 if os.sep == '\\':
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1900 path = path.replace('\\', '\\\\')
4270
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1901 ref = 'file.reference.' + dep.name + '-bin'
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1902 print >> out, ref + '=' + path
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1903
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1904 else:
4270
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1905 n = dep.name.replace('.', '_')
4271
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1906 relDepPath = os.path.relpath(dep.dir, p.dir).replace(os.sep, '/')
4270
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1907 ref = 'reference.' + n + '.jar'
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1908 print >> out, 'project.' + n + '=' + relDepPath
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1909 print >> out, ref + '=${project.' + n + '}/dist/' + dep.name + '.jar'
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1910
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1911 javacClasspath.append('${' + ref + '}')
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1912
5198
887b45f6aa02 improved name of Eclipse launch file created for jar applications
Doug Simon <doug.simon@oracle.com>
parents: 5194
diff changeset
1913 print >> out, 'javac.classpath=\\\n ' + (os.pathsep + '\\\n ').join(javacClasspath)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1914
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1915
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1916 updated = update_file(join(p.dir, 'nbproject', 'project.properties'), out.getvalue()) or updated
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1917 out.close()
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1918
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1919 if updated:
4270
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1920 log('If using NetBeans:')
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1921 log(' 1. Ensure that a platform named "JDK ' + java().version + '" is defined (Tools -> Java Platforms)')
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
1922 log(' 2. Open/create a Project Group for the directory containing the projects (File -> Project Group -> New Group... -> Folder of Projects)')
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1923
4271
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1924 def ideclean(args, suite=None):
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1925 """remove all Eclipse and NetBeans project configurations"""
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1926
4271
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1927 def rm(path):
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1928 if exists(path):
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1929 os.remove(path)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1930
4271
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1931 for p in projects():
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1932 if p.native:
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1933 continue
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1934
4271
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1935 shutil.rmtree(join(p.dir, '.settings'), ignore_errors=True)
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1936 shutil.rmtree(join(p.dir, 'nbproject'), ignore_errors=True)
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1937 rm(join(p.dir, '.classpath'))
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1938 rm(join(p.dir, '.project'))
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
1939 rm(join(p.dir, 'build.xml'))
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
1940
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1941 def ideinit(args, suite=None):
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1942 """(re)generate Eclipse and NetBeans project configurations"""
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1943 eclipseinit(args, suite)
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
1944 netbeansinit(args, suite)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1945
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1946 def javadoc(args):
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1947 """generate javadoc for some/all Java projects"""
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
1948
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1949 parser = ArgumentParser(prog='mx javadoc')
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1950 parser.add_argument('--unified', action='store_true', help='put javadoc in a single directory instead of one per project')
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1951 parser.add_argument('--force', action='store_true', help='(re)generate javadoc even if package-list file exists')
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1952 parser.add_argument('--projects', action='store', help='comma separated projects to process (omit to process all projects)')
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1953 parser.add_argument('--argfile', action='store', help='name of file containing extra javadoc options')
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1954 parser.add_argument('-m', '--memory', action='store', help='-Xmx value to pass to underlying JVM')
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1955 parser.add_argument('--wiki', action='store_true', help='generate Confluence Wiki format for package-info.java files')
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1956 parser.add_argument('--packages', action='store', help='comma separated packages to process (omit to process all packages)')
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1957
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1958 args = parser.parse_args(args)
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1959
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1960 # build list of projects to be processed
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1961 candidates = sorted_deps()
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1962 if args.projects is not None:
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1963 candidates = [project(name) for name in args.projects.split(',')]
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1964
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1965 # optionally restrict packages within a project (most useful for wiki)
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1966 packages = []
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1967 if args.packages is not None:
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1968 packages = [name for name in args.packages.split(',')]
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1969
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1970 # the WikiDoclet cannot see the -classpath argument passed to javadoc so we pass the
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1971 # full list of projects as an explicit argument, thereby enabling it to map classes
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1972 # to projects, which is needed to generate Wiki links to the source code.
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1973 # There is no virtue in running the doclet on dependent projects as there are
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1974 # no generated links between Wiki pages
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1975 docletArgs = []
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1976 if args.wiki:
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1977 docDir = 'wikidoc'
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1978 toolsDir = project('com.oracle.max.tools').output_dir()
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1979 baseDir = project('com.oracle.max.base').output_dir()
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1980 dp = os.pathsep.join([toolsDir, baseDir])
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1981 project_list = ','.join(p.name for p in sorted_deps())
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1982 docletArgs = ['-docletpath', dp, '-doclet', 'com.oracle.max.tools.javadoc.wiki.WikiDoclet', '-projects', project_list]
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1983 else:
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1984 docDir = 'javadoc'
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1985
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1986 def check_package_list(p):
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1987 if args.wiki:
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1988 return True
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1989 else:
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1990 return not exists(join(p.dir, docDir, 'package-list'))
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1991
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1992 def assess_candidate(p, projects):
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1993 if p in projects:
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1994 return False
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1995 if args.force or args.unified or check_package_list(p):
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1996 projects.append(p)
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1997 return True
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
1998 return False
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
1999
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2000 projects = []
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2001 for p in candidates:
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2002 if not p.native:
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2003 if not args.wiki:
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2004 deps = p.all_deps([], includeLibs=False, includeSelf=False)
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2005 for d in deps:
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2006 assess_candidate(d, projects)
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2007 if not assess_candidate(p, projects):
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2008 log('[package-list file exists - skipping {0}]'.format(p.name))
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2009
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2010
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2011 def find_packages(sourceDirs, pkgs=set()):
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2012 for sourceDir in sourceDirs:
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2013 for root, _, files in os.walk(sourceDir):
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2014 if len([name for name in files if name.endswith('.java')]) != 0:
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2015 pkg = root[len(sourceDir) + 1:].replace('/','.')
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2016 if (len(packages) == 0) | (pkg in packages):
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2017 pkgs.add(pkg)
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2018 return pkgs
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2019
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2020 extraArgs = []
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2021 if args.argfile is not None:
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2022 extraArgs += ['@' + args.argfile]
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2023 memory = '2g'
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2024 if args.memory is not None:
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2025 memory = args.memory
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2026 memory = '-J-Xmx' + memory
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2027
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2028 if not args.unified:
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2029 for p in projects:
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2030 pkgs = find_packages(p.source_dirs(), set())
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2031 deps = p.all_deps([], includeLibs=False, includeSelf=False)
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2032 links = ['-link', 'http://docs.oracle.com/javase/' + str(p.javaCompliance.value) + '/docs/api/']
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2033 out = join(p.dir, docDir)
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2034 for d in deps:
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2035 depOut = join(d.dir, docDir)
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2036 links.append('-link')
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2037 links.append(os.path.relpath(depOut, out))
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2038 cp = classpath(p.name, includeSelf=True)
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2039 sp = os.pathsep.join(p.source_dirs())
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2040 log('Generating {2} for {0} in {1}'.format(p.name, out, docDir))
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2041 run([java().javadoc, memory, '-classpath', cp, '-quiet', '-d', out, '-sourcepath', sp] + docletArgs + links + extraArgs + list(pkgs))
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2042 log('Generated {2} for {0} in {1}'.format(p.name, out, docDir))
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2043 else:
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2044 pkgs = set()
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2045 sp = []
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2046 names = []
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2047 for p in projects:
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2048 find_packages(p.source_dirs(), pkgs)
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2049 sp += p.source_dirs()
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2050 names.append(p.name)
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2051
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2052 links = ['-link', 'http://docs.oracle.com/javase/' + str(_java.javaCompliance.value) + '/docs/api/']
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2053 out = join(_mainSuite.dir, docDir)
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2054 cp = classpath()
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2055 sp = os.pathsep.join(sp)
5376
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2056 log('Generating {2} for {0} in {1}'.format(', '.join(names), out, docDir))
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2057 run([java().javadoc, memory, '-classpath', cp, '-quiet', '-d', out, '-sourcepath', sp] + docletArgs + links + extraArgs + list(pkgs))
bfc9aeb1264c synchronized mxtool with Maxine
Doug Simon <doug.simon@oracle.com>
parents: 5252
diff changeset
2058 log('Generated {2} for {0} in {1}'.format(', '.join(names), out, docDir))
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2059
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
2060 def findclass(args):
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
2061 """find all classes matching a given substring"""
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
2062
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
2063 for entry, filename in classpath_walk(includeBootClasspath=True):
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
2064 if filename.endswith('.class'):
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
2065 if isinstance(entry, zipfile.ZipFile):
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
2066 classname = filename.replace('/', '.')
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
2067 else:
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
2068 classname = filename.replace(os.sep, '.')
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
2069 classname = classname[:-len('.class')]
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
2070 for a in args:
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
2071 if a in classname:
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
2072 log(classname)
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
2073
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2074 def javap(args):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2075 """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
2076
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2077 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
2078
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2079 -private -verbose -classpath <path to project classes>"""
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
2080
4147
55376d8953a6 Improved 'build' and 'clean' commands.
Doug Simon <doug.simon@oracle.com>
parents: 4145
diff changeset
2081 javap = java().javap
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2082 if not exists(javap):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2083 abort('The javap executable does not exists: ' + javap)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2084 else:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2085 run([javap, '-private', '-verbose', '-classpath', classpath()] + args)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2086
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2087 def show_projects(args):
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2088 """show all loaded projects"""
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2089 for s in suites():
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2090 projectsFile = join(s.dir, 'mx', 'projects')
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2091 if exists(projectsFile):
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2092 log(projectsFile)
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2093 for p in s.projects:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2094 log('\t' + p.name)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2095
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2096 def add_argument(*args, **kwargs):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2097 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2098 Define how a single command-line argument.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2099 """
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2100 assert _argParser is not None
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2101 _argParser.add_argument(*args, **kwargs)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
2102
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2103 # Table of commands in alphabetical order.
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2104 # Keys are command names, value are lists: [<function>, <usage msg>, <format args to doc string of function>...]
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2105 # If any of the format args are instances of Callable, then they are called with an 'env' are before being
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
2106 # used in the call to str.format().
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2107 # Extensions should update this table directly
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2108 commands = {
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
2109 'about': [about, ''],
4226
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
2110 'build': [build, '[options]'],
e03ff10d4bfc Made the gate clean the Java projects only.
Doug Simon <doug.simon@oracle.com>
parents: 4225
diff changeset
2111 'checkstyle': [checkstyle, ''],
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2112 'canonicalizeprojects': [canonicalizeprojects, ''],
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2113 'clean': [clean, ''],
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
2114 'eclipseinit': [eclipseinit, ''],
5455
271e83dcfcef added findclass command to mx tool
Doug Simon <doug.simon@oracle.com>
parents: 5376
diff changeset
2115 'findclass': [findclass, ''],
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2116 'help': [help_, '[command]'],
4271
311d193de5a2 Fixed regressions and Windows issues in generated IDE project configurations.
Doug Simon <doug.simon@oracle.com>
parents: 4270
diff changeset
2117 'ideclean': [ideclean, ''],
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
2118 'ideinit': [ideinit, ''],
4301
fad6f1ebeb44 mx.py: new projectgraph command
Lukas Stadler <lukas.stadler@jku.at>
parents: 4271
diff changeset
2119 'projectgraph': [projectgraph, ''],
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2120 'javap': [javap, ''],
5171
99ad84da5f99 added javadoc command (from Maxine version of mx)
Doug Simon <doug.simon@oracle.com>
parents: 5166
diff changeset
2121 'javadoc': [javadoc, '[options]'],
4270
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
2122 'netbeansinit': [netbeansinit, ''],
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2123 'projects': [show_projects, ''],
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2124 }
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2125
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2126 _argParser = ArgParser()
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2127
4241
8fece0287975 Made command timeout also kill any currently executing subprocess (group).
Doug Simon <doug.simon@oracle.com>
parents: 4239
diff changeset
2128 def main():
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2129 cwdMxDir = join(os.getcwd(), 'mx')
4180
383c1272cd1f Fixed gate script such that JAVA_HOME can be set in env file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4178
diff changeset
2130 if exists(cwdMxDir) and isdir(cwdMxDir):
4269
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
2131 global _mainSuite
ffd5ce8fc736 Moved IDE project configuration into mx.py.
Doug Simon <doug.simon@oracle.com>
parents: 4258
diff changeset
2132 _mainSuite = _loadSuite(os.getcwd(), True)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
2133
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2134 opts, commandAndArgs = _argParser._parse_cmd_line()
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
2135
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
2136 global _opts, _java
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2137 _opts = opts
4145
9aee7df31417 Removed 'tests' command.
Doug Simon <doug.simon@oracle.com>
parents: 4144
diff changeset
2138 _java = JavaConfig(opts)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
2139
4148
bf5efc22fb3f Replace downloading of JDK 7 with copying of host JDK 7.
Doug Simon <doug.simon@oracle.com>
parents: 4147
diff changeset
2140 for s in suites():
4180
383c1272cd1f Fixed gate script such that JAVA_HOME can be set in env file.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 4178
diff changeset
2141 s._post_init(opts)
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
2142
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2143 if len(commandAndArgs) == 0:
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2144 _argParser.print_help()
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2145 return
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
2146
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2147 command = commandAndArgs[0]
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2148 command_args = commandAndArgs[1:]
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
2149
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2150 if not commands.has_key(command):
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2151 abort('mx: unknown command \'{0}\'\n{1}use "mx help" for more options'.format(command, _format_commands()))
5032
e2de9649f0a9 Integrated mxtool updates from Maxine project.
Doug Simon <doug.simon@oracle.com>
parents: 4664
diff changeset
2152
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2153 c, _ = commands[command][:2]
4293
d4906ea4255b Handle SIGTERM : killing mx will properly kill subprocesses
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4271
diff changeset
2154 def term_handler(signum, frame):
d4906ea4255b Handle SIGTERM : killing mx will properly kill subprocesses
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4271
diff changeset
2155 abort(1)
d4906ea4255b Handle SIGTERM : killing mx will properly kill subprocesses
Gilles Duboscq <gilles.m.duboscq@gmail.com>
parents: 4271
diff changeset
2156 signal.signal(signal.SIGTERM, term_handler)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2157 try:
4270
2158e26b50cf Made generated NetBeans projects use project cross referencing.
Doug Simon <doug.simon@oracle.com>
parents: 4269
diff changeset
2158 if opts.timeout != 0:
4239
676feaf8adee Made the --timeout option apply to the whole mx command as opposed to each subprocess executed (the new --ptimeout does the latter).
Doug Simon <doug.simon@oracle.com>
parents: 4236
diff changeset
2159 def alarm_handler(signum, frame):
676feaf8adee Made the --timeout option apply to the whole mx command as opposed to each subprocess executed (the new --ptimeout does the latter).
Doug Simon <doug.simon@oracle.com>
parents: 4236
diff changeset
2160 abort('Command timed out after ' + str(opts.timeout) + ' seconds: ' + ' '.join(commandAndArgs))
676feaf8adee Made the --timeout option apply to the whole mx command as opposed to each subprocess executed (the new --ptimeout does the latter).
Doug Simon <doug.simon@oracle.com>
parents: 4236
diff changeset
2161 signal.signal(signal.SIGALRM, alarm_handler)
676feaf8adee Made the --timeout option apply to the whole mx command as opposed to each subprocess executed (the new --ptimeout does the latter).
Doug Simon <doug.simon@oracle.com>
parents: 4236
diff changeset
2162 signal.alarm(opts.timeout)
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2163 retcode = c(command_args)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2164 if retcode is not None and retcode != 0:
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2165 abort(retcode)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2166 except KeyboardInterrupt:
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2167 # no need to show the stack trace when the user presses CTRL-C
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2168 abort(1)
3723
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2169
6c5f528c7aac Added a copy of the mxtool to repo.
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2170 if __name__ == '__main__':
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2171 # rename this module as 'mx' so it is not imported twice by the commands.py modules
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2172 sys.modules['mx'] = sys.modules.pop('__main__')
4242
3e25132be4b4 Disabled eager resolution of libraries as they are defined.
Doug Simon <doug.simon@oracle.com>
parents: 4241
diff changeset
2173
4144
34527a24bcf8 Adopted mxtool changes.
Doug Simon <doug.simon@oracle.com>
parents: 3732
diff changeset
2174 main()