Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/sourcetools/com.ibm.uma/com/ibm/j9/uma/Main.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2001, 2018 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
package com.ibm.j9.uma;
23
24
import com.ibm.j9.uma.configuration.ConfigurationImpl;
25
import com.ibm.j9tools.om.Flag;
26
import com.ibm.uma.UMA;
27
import com.ibm.uma.UMAException;
28
import com.ibm.uma.util.Logger;
29
import java.io.File;
30
import java.util.HashMap;
31
32
public class Main {
33
static String applicationVersion = "2.5.1";
34
static String applicationNameLong = "Universal Makefile Adapter - for J9";
35
static String applicationNameShort = "$(J9UMA)";
36
37
static String option_quiet = "-quiet";
38
static String option_quiet_short = "-q";
39
static String option_verbose = "-verbose";
40
static String option_verbose_short = "-v";
41
static String option_help = "-help";
42
static String option_help_short = "-h";
43
static String option_rootDir = "-rootDir";
44
static String option_rootDir_short = "-r";
45
static String option_configDir = "-configDir";
46
static String option_configDir_short = "-c";
47
static String option_buildSpecId = "-buildSpecId";
48
static String option_buildSpecId_short = "-b";
49
static String option_buildId = "-buildId";
50
static String option_buildId_short = "-bid";
51
static String option_buildDate = "-buildDate";
52
static String option_buildDate_short = "-bd";
53
static String option_buildTag = "-buildTag";
54
static String option_buildTag_short = "-bt";
55
static String option_jitVersionFile = "-jitVersionFile";
56
static String option_jitVersionFile_short = "-jvf";
57
static String option_excludeArtifacts = "-excludeArtifacts";
58
static String option_excludeArtifacts_short = "-ea";
59
static String option_define = "-D";
60
static String option_undefine = "-U";
61
static String option_macro = "-M";
62
63
static boolean splashed = false;
64
static boolean quiet = false;
65
static boolean verbose = false;
66
static String buildSpecId = null;
67
static String configDirectory = null;
68
static String rootDir = ".";
69
static String buildId = "0";
70
static String buildDate = "12150101";
71
static String buildTag = "dev_12150101_0000_B0";
72
static String jitVersionFile = "";
73
static String excludeArtifacts = "";
74
static HashMap<String, Boolean> overrideFlags = new HashMap<String,Boolean>();
75
static HashMap<String, String> extraMacros = new HashMap<String, String>();
76
static Logger logger;
77
78
static void dumpSplash() {
79
if (splashed||quiet) {
80
return;
81
}
82
System.out.println( applicationNameLong + ", version " + applicationVersion );
83
System.out.println( "" );
84
splashed = true;
85
}
86
87
static void dumpHelp() {
88
dumpSplash();
89
System.err.println(applicationNameShort + " [options] " + option_rootDir + " <directory> " + option_configDir + " <directory> " + option_buildSpecId + " <specId>" );
90
System.err.println("options:");
91
System.err.println("\t-quiet");
92
System.err.println("\t-verbose");
93
System.err.println("\t-help");
94
System.err.println("\t" +"{" + option_define + "|" + option_undefine + "} <flagName>");
95
System.err.println("\t" + option_rootDir + " <directory>");
96
System.err.println("\t" + option_configDir + " <directory>");
97
System.err.println("\t" + option_buildSpecId + " <specId>");
98
System.err.println("\t" + option_buildId + " <buildId>");
99
System.err.println("\t" + option_buildDate + " <buildDate>");
100
System.err.println("\t" + option_buildTag + " <buildTag>");
101
System.err.println("\t" + option_macro + " <name>=<value>");
102
System.err.println("");
103
}
104
105
static boolean parseOptions(String[] args) {
106
107
for (int i=0; i<args.length; i++) {
108
String arg = args[i];
109
if (!arg.startsWith("-")) {
110
System.err.println("Badly formatted command line.\n");
111
return false;
112
}
113
if (arg.equalsIgnoreCase(option_quiet)||arg.equalsIgnoreCase(option_quiet_short)) {
114
quiet = true;
115
continue;
116
} else if (arg.equalsIgnoreCase(option_verbose)||arg.equalsIgnoreCase(option_verbose_short)) {
117
verbose = true;
118
continue;
119
} else if (arg.equalsIgnoreCase(option_help) || arg.equalsIgnoreCase(option_help_short)) {
120
return false;
121
} else if (arg.equalsIgnoreCase(option_rootDir) || arg.equalsIgnoreCase(option_rootDir_short)) {
122
if ( i+1 >= args.length ) {
123
System.err.println("Must provide an argument for option " + arg + "\n");
124
return false;
125
}
126
rootDir = args[++i];
127
rootDir = rootDir.trim();
128
continue;
129
} else if (arg.equalsIgnoreCase(option_configDir) || arg.equalsIgnoreCase(option_configDir_short)) {
130
if ( i+1 >= args.length ) {
131
System.err.println("Must provide an argument for option " + arg + "\n");
132
return false;
133
}
134
configDirectory = args[++i];
135
configDirectory = configDirectory.trim();
136
continue;
137
} else if (arg.equalsIgnoreCase(option_buildSpecId) || arg.equalsIgnoreCase(option_buildSpecId_short)) {
138
if ( i+1 >= args.length ) {
139
System.err.println("Must provide an argument for option " + arg + "\n");
140
return false;
141
}
142
buildSpecId = args[++i];
143
buildSpecId = buildSpecId.trim();
144
continue;
145
} else if (arg.equalsIgnoreCase(option_buildDate) || arg.equalsIgnoreCase(option_buildDate_short)) {
146
if ( i+1 >= args.length ) {
147
System.err.println("Must provide an argument for option " + arg + "\n");
148
return false;
149
}
150
buildDate = args[++i];
151
buildDate = buildDate.trim();
152
continue;
153
} else if (arg.equalsIgnoreCase(option_buildId) || arg.equalsIgnoreCase(option_buildId_short)) {
154
if ( i+1 >= args.length ) {
155
System.err.println("Must provide an argument for option " + arg + "\n");
156
return false;
157
}
158
buildId = args[++i];
159
buildId = buildId.trim();
160
continue;
161
} else if (arg.equalsIgnoreCase(option_buildTag) || arg.equalsIgnoreCase(option_buildTag_short)) {
162
if ( i+1 >= args.length ) {
163
System.err.println("Must provide an argument for option " + arg + "\n");
164
return false;
165
}
166
buildTag = args[++i];
167
buildTag = buildTag.trim();
168
continue;
169
} else if (arg.equalsIgnoreCase(option_jitVersionFile) || arg.equalsIgnoreCase(option_jitVersionFile_short)) {
170
if ( i+1 >= args.length ) {
171
System.err.println("Must provide an argument for option " + arg + "\n");
172
return false;
173
}
174
jitVersionFile = args[++i];
175
jitVersionFile = jitVersionFile.trim();
176
continue;
177
} else if (arg.equalsIgnoreCase(option_excludeArtifacts) || arg.equalsIgnoreCase(option_excludeArtifacts_short)) {
178
if ( i+1 >= args.length ) {
179
System.err.println("Must provide an argument for option " + arg + "\n");
180
return false;
181
}
182
excludeArtifacts = args[++i];
183
excludeArtifacts = excludeArtifacts.trim();
184
continue;
185
} else if (arg.equalsIgnoreCase(option_define) ) {
186
if ( i+1 >= args.length ) {
187
System.err.println("Must provide an argument for option " + arg + "\n");
188
return false;
189
}
190
overrideFlags.put(args[++i], true);
191
continue;
192
} else if (arg.equalsIgnoreCase(option_undefine) ) {
193
if ( i+1 >= args.length ) {
194
System.err.println("Must provide an argument for option " + arg + "\n");
195
return false;
196
}
197
overrideFlags.put(args[++i], false);
198
continue;
199
} else if (arg.equalsIgnoreCase(option_macro)) {
200
i += 1;
201
if (i >= args.length) {
202
System.err.println("Must provide an argument for option " + arg + "\n");
203
return false;
204
}
205
String value = args[i].trim();
206
int eqIndex = value.indexOf('=');
207
if (eqIndex <= 0) {
208
System.err.println("Argument for option " + arg + " must be of the form 'name=value'\n");
209
return false;
210
}
211
extraMacros.put(value.substring(0, eqIndex), value.substring(eqIndex + 1));
212
continue;
213
} else {
214
System.err.println("Unknown command line option " + arg + "\n");
215
return false;
216
}
217
}
218
219
if ( rootDir == null || buildSpecId == null || configDirectory == null ) {
220
System.err.println("Missing a required command line option.\n");
221
return false;
222
}
223
224
return true;
225
}
226
227
public static void main(String[] args) {
228
229
if ( !parseOptions(args) ) {
230
System.out.print(applicationNameShort + " ");
231
for ( String arg : args ) {
232
System.out.print(" " + arg );
233
}
234
System.out.println();
235
dumpHelp();
236
System.exit(-1);
237
}
238
239
logger = Logger.initLogger(verbose?Logger.InformationL2Log:Logger.InformationL1Log);
240
241
dumpSplash();
242
243
if ( jitVersionFile.equals("") ) {
244
File tempJitVersionFile = new File(rootDir + "/compiler/build/version.h");
245
if(tempJitVersionFile.exists() && !tempJitVersionFile.isDirectory()) {
246
jitVersionFile = rootDir + "/compiler/build/version.h";
247
System.out.print("Using version.h as the jitVersionFile\n");
248
} else {
249
tempJitVersionFile = new File(rootDir + "/jit.version");
250
if(tempJitVersionFile.exists() && !tempJitVersionFile.isDirectory()) {
251
jitVersionFile = rootDir + "/jit.version";
252
System.out.print("Using jit.version as the jitVersionFile\n");
253
}
254
}
255
}
256
257
try {
258
ConfigurationImpl configuration = new ConfigurationImpl(configDirectory, buildSpecId, buildId, buildDate, buildTag, jitVersionFile, excludeArtifacts);
259
for(String flagString: overrideFlags.keySet()){
260
if(!configuration.isFlagValid(flagString)){
261
throw new UMAException("Invalid flag override: " + flagString);
262
}
263
Flag flag = configuration.getBuildSpec().getFlag(flagString);
264
flag.setState(overrideFlags.get(flagString));
265
}
266
267
for (java.util.Map.Entry<String, String> entry : extraMacros.entrySet()) {
268
String name = entry.getKey();
269
String value = entry.getValue();
270
271
configuration.defineMacro(name, value);
272
}
273
274
// Since we may have changed some flags, we need to re-verify them
275
configuration.verify();
276
277
new UMA(configuration, configuration, rootDir).generate();
278
} catch (NullPointerException e) {
279
logger.println(Logger.ErrorLog, "Internal error: null pointer exception");
280
e.printStackTrace();
281
System.exit(-1);
282
} catch (UMAException e) {
283
logger.println(Logger.ErrorLog, e.getMessage());
284
System.exit(-1);
285
}
286
}
287
}
288
289