]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/CheckTools/src/org/tianocore/CheckTools/CheckTools.java
Added the DbTools that will update the FrameworkDatabase.db file based on what is...
[mirror_edk2.git] / Tools / Java / Source / CheckTools / src / org / tianocore / CheckTools / CheckTools.java
1 /** @file
2 Verify the tool configuration file for location of the correct tools.
3
4 Copyright (c) 2006, Intel Corporation
5 All rights reserved. This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 /**
16 * This tool checks to see if specified tool chain paths exist.
17 * It will check all specified paths, as indicated by the last field of the
18 * tool property line equal to _PATH
19 *
20 * no option = check 1) the file specified in target.txt or 2) tools_def.txt
21 * if neither is found, we check the tools_def.template file.
22 * -i = INTERACTIVE checks the "active" tools_def.txt file and lets the
23 * user modify invalid entries.
24 *
25 * -s = SCAN will check all standard locations for tool chains
26 * C:\Program Files\Microsoft Visual Studio *
27 * C:\WINDDK
28 * C:\Bin
29 * C:\ASL
30 * C:\MASM*
31 * /opt/tiano
32 *
33 * -f = FILE check the tools in this file instead of tools_def.txt, or
34 * a file that was specified in target.txt
35 *
36 * -t = TEST can be used with -f or -s, not with -i.
37 *
38 * -d = DUMP can be used with -f, not with -i
39 *
40 * -q = QUIET - turns off all System.out.print statements, the return code
41 * is the only thing that will determine PASS or FAIL
42 *
43 */
44 package org.tianocore.CheckTools;
45
46 import java.io.*;
47
48 public class CheckTools {
49 private static int DEBUG = 0;
50
51 private static final String copyright = "Copyright (c) 2006, Intel Corporation All rights reserved.";
52
53 private static final String version = "Version 0.1";
54
55 private int VERBOSE = 0;
56
57 private boolean QUIET = false;
58
59 // private String argv[];
60
61 private final int DEFAULT = 1;
62
63 private final int TEST = 2;
64
65 private final int SCAN = 4;
66
67 private final int DUMP = 8;
68
69 private final int INTERACTIVE = 16;
70
71 private boolean USERFILE = false;
72
73 private String inFile = "";
74
75 private final int PASS = 0;
76
77 private final int FAIL = 1;
78
79 private String SEP = System.getProperty("file.separator");
80
81 public static void main(String[] argv) {
82 CheckTools cts = new CheckTools();
83 int exitCode = cts.checkTool(argv);
84 if (DEBUG > 10)
85 System.out.println("Exit Code: " + exitCode);
86 if (exitCode == -1) {
87 new CheckTools().usage();
88 System.exit(1);
89 }
90 System.exit(exitCode);
91 }
92
93 private int checkTool(String[] arguments) {
94 if ((DEBUG > 1) && (arguments.length > 0))
95 System.out.println("Arguments: ");
96 int cmdCode = DEFAULT;
97 if (arguments.length > 0) {
98 cmdCode = DEFAULT;
99 for (int i = 0; i < arguments.length; i++)
100 if (arguments[i].toLowerCase().startsWith("-q"))
101 QUIET = true;
102 for (int i = 0; i < arguments.length; i++) {
103 String arg = arguments[i];
104 if (DEBUG > 1)
105 System.out.println(" [" + i + "] " + arg);
106 if (!(arg.toLowerCase().startsWith("-t") || arg.toLowerCase().startsWith("-s")
107 || arg.toLowerCase().startsWith("-d") || arg.toLowerCase().startsWith("-i")
108 || arg.toLowerCase().startsWith("-v") || arg.toLowerCase().startsWith("-q")
109 || arg.toLowerCase().startsWith("-h") || arg.toLowerCase().startsWith("-f"))) {
110 // Only allow valid option flags
111 if (QUIET == false) {
112 System.out.println("Invalid argument: " + arg);
113 usage();
114 }
115 System.exit(FAIL);
116 }
117
118 if (arg.toLowerCase().startsWith("-d")) {
119 if (cmdCode == DEFAULT) {
120 cmdCode = DUMP;
121 } else {
122 if (QUIET == false)
123 System.out.println("Invalid Options");
124 usage();
125 System.exit(FAIL);
126 }
127 }
128 if (arg.toLowerCase().startsWith("-f")) {
129 i++;
130 inFile = arguments[i];
131 USERFILE = true;
132 }
133 if (arg.toLowerCase().startsWith("-h")) {
134 usage();
135 System.exit(PASS);
136 }
137 if (arg.toLowerCase().startsWith("-i")) {
138 // Interactive can be specified with any
139 // other option - it turns on the query
140 // on fail mode.
141 cmdCode = cmdCode | INTERACTIVE;
142 }
143 if (arg.toLowerCase().startsWith("-q")) {
144 QUIET = true;
145 }
146 if (arg.toLowerCase().startsWith("-s")) {
147 if (cmdCode == DEFAULT) {
148 cmdCode = SCAN;
149 } else {
150 if (!QUIET) {
151 System.out.println("Invalid Options");
152 usage();
153 }
154 System.exit(FAIL);
155 }
156 }
157 if (arg.toLowerCase().startsWith("-t")) {
158 if (cmdCode == DEFAULT) {
159 cmdCode = TEST;
160 } else {
161 if (!QUIET) {
162 System.out.println("Invalid Options");
163 usage();
164 }
165 System.exit(FAIL);
166 }
167 }
168 if (arg.startsWith("-v")) {
169 // Verbose level can be increased to print
170 // more INFO messages.
171 VERBOSE += 1;
172 }
173 if (arg.startsWith("-V")) {
174 if (!QUIET) {
175 System.out.println(copyright);
176 System.out.println("CheckTools, " + version);
177 }
178 System.exit(PASS);
179 }
180 }
181 }
182 if (QUIET)
183 VERBOSE = 0;
184
185 String WORKSPACE = System.getenv("WORKSPACE");
186 if ((DEBUG > 0) || (VERBOSE > 0))
187 System.out.println("Verifying Tool Chains for WORKSPACE: " + WORKSPACE);
188 int returnCode = 0;
189
190 if (WORKSPACE == null) {
191 if (QUIET == false)
192 System.out.println("Please set the environment variable, WORKSPACE and run again.");
193 System.exit(FAIL);
194 }
195 String targetTxt = WORKSPACE + SEP + "Tools" + SEP + "Conf" + SEP + "target.txt";
196
197
198 if (inFile.length() < 1) {
199 //
200 // Check the target.txt file for a Tool Configuration File.
201 // If not set, we use tools_def.txt, unless we are running with the
202 // INTERACTIVE flag - where we check the template file before copying over to the
203 // tools_def.txt file.
204 //
205 inFile = "tools_def.txt";
206 File target = new File(targetTxt);
207 String readLine = null;
208 String fileLine[] = new String[2];
209 if (target.exists()) {
210 try {
211 FileReader fileReader = new FileReader(targetTxt);
212 BufferedReader bufReader = new BufferedReader(fileReader);
213 while ((readLine = bufReader.readLine()) != null) {
214 if (readLine.startsWith("TOOL_CHAIN_CONF")) {
215 fileLine = readLine.trim().split("=");
216 if (fileLine[1].trim().length() > 0) {
217 if (fileLine[1].trim().contains("Tools/Conf/"))
218 inFile = fileLine[1].replace("Tools/Conf/", "").trim();
219 else
220 inFile = fileLine[1].trim();
221 }
222 }
223 }
224 bufReader.close();
225 } catch (IOException e) {
226 if (QUIET == false)
227 System.out.println(" [target.txt] Read Error: " + e);
228 System.exit(FAIL);
229 }
230 }
231 }
232
233 // OK, now check the infile of we had one.
234 String toolsDef = WORKSPACE + SEP + "Tools" + SEP + "Conf" + SEP + inFile;
235 File toolsFile = new File(toolsDef);
236 if (!toolsFile.exists()) {
237 // use the template file
238 if (USERFILE) {
239 if (QUIET == false) {
240 System.out.println("Could not locate the specified file: " + inFile);
241 System.out.println(" It must be located in the WORKSPACE" + SEP + "Tools" + SEP + "Conf directory");
242 }
243 System.exit(FAIL);
244 }
245 toolsDef = WORKSPACE + SEP + "Tools" + SEP + "Conf" + SEP + "tools_def.template";
246 File toolsTemplate = new File(toolsDef);
247 if (!toolsTemplate.exists()) {
248 if (QUIET == false)
249 System.out.println("Your WORKSPACE is not properly configured!");
250 System.exit(FAIL);
251 } else {
252 if (QUIET == false)
253 System.out.println("**** WARNING: No Tool Configuration File was found, using the template file, "
254 + toolsDef);
255 }
256 }
257
258 //
259 // at this point the file, toolsDef points to a tool configuration file of some sort.
260 //
261 // check tool configuration file
262 if (DEBUG > 2)
263 System.out.println("Calling checkTools(" + toolsDef + ", " + cmdCode + ", " + VERBOSE + ")");
264 ToolChecks tc = new ToolChecks();
265 returnCode = tc.checkTools(toolsDef, cmdCode, VERBOSE, QUIET);
266
267 if (VERBOSE > 10)
268 System.out.println(" checkTools returned: " + returnCode);
269 return returnCode;
270 }
271
272 private void usage() {
273 if (QUIET)
274 return;
275 System.out
276 .println("Usage: checkTools [-h] [-d] [-i] [-v] [-s | -scan] [-t | -test] [-q | -quiet] [[-f | -filename] filename.txt]");
277 System.out.println(" Where");
278 System.out.println(" -h Help - display this screen.");
279 System.out.println(" -d Dump - display the tool defintion file in user readable format");
280 System.out.println(" -i Interactive query - not yet implemented!");
281 System.out.println(" -v Verbose - add up to 3 -v options to increase info messages.");
282 System.out.println(" -s Scan - search the usual places on your system for tools.");
283 System.out.println(" The Scan feature not yet implemented!.");
284 System.out.println(" -t Test - checks that PATH entries in the tool configuration file exist.");
285 System.out
286 .println(" -q Quiet - no messages get printed, the return value determines pass or fail.");
287 System.out.println(" -f filename Use filename instead of the file specified in target.txt or");
288 System.out.println(" tools_def.txt or tools_def.template.");
289 System.out.println(" By Rule, all tool configuration files must reside in the");
290 System.out.println(" WORKSPACE" + SEP + "Tools" + SEP + "Conf directory.");
291 }
292 }