]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/CheckTools/src/org/tianocore/CheckTools/CheckTools.java
2 Verify the tool configuration file for location of the correct tools.
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
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.
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
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.
25 * -s = SCAN will check all standard locations for tool chains
26 * C:\Program Files\Microsoft Visual Studio *
33 * -f = FILE check the tools in this file instead of tools_def.txt, or
34 * a file that was specified in target.txt
36 * -t = TEST can be used with -f or -s, not with -i.
38 * -d = DUMP can be used with -f, not with -i
40 * -q = QUIET - turns off all System.out.print statements, the return code
41 * is the only thing that will determine PASS or FAIL
44 package org
.tianocore
.CheckTools
;
48 public class CheckTools
{
49 private static int DEBUG
= 0;
51 private static final String copyright
= "Copyright (c) 2006, Intel Corporation All rights reserved.";
53 private static final String version
= "Version 0.1";
55 private int VERBOSE
= 0;
57 private boolean QUIET
= false;
59 // private String argv[];
61 private final int DEFAULT
= 1;
63 private final int TEST
= 2;
65 private final int SCAN
= 4;
67 private final int DUMP
= 8;
69 private final int INTERACTIVE
= 16;
71 private boolean USERFILE
= false;
73 private String inFile
= "";
75 private final int PASS
= 0;
77 private final int FAIL
= 1;
79 private String SEP
= System
.getProperty("file.separator");
81 public static void main(String
[] argv
) {
82 CheckTools cts
= new CheckTools();
83 int exitCode
= cts
.checkTool(argv
);
85 System
.out
.println("Exit Code: " + exitCode
);
87 new CheckTools().usage();
90 System
.exit(exitCode
);
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) {
99 for (int i
= 0; i
< arguments
.length
; i
++)
100 if (arguments
[i
].toLowerCase().startsWith("-q"))
102 for (int i
= 0; i
< arguments
.length
; i
++) {
103 String arg
= arguments
[i
];
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
);
118 if (arg
.toLowerCase().startsWith("-d")) {
119 if (cmdCode
== DEFAULT
) {
123 System
.out
.println("Invalid Options");
128 if (arg
.toLowerCase().startsWith("-f")) {
130 inFile
= arguments
[i
];
133 if (arg
.toLowerCase().startsWith("-h")) {
137 if (arg
.toLowerCase().startsWith("-i")) {
138 // Interactive can be specified with any
139 // other option - it turns on the query
141 cmdCode
= cmdCode
| INTERACTIVE
;
143 if (arg
.toLowerCase().startsWith("-q")) {
146 if (arg
.toLowerCase().startsWith("-s")) {
147 if (cmdCode
== DEFAULT
) {
151 System
.out
.println("Invalid Options");
157 if (arg
.toLowerCase().startsWith("-t")) {
158 if (cmdCode
== DEFAULT
) {
162 System
.out
.println("Invalid Options");
168 if (arg
.startsWith("-v")) {
169 // Verbose level can be increased to print
170 // more INFO messages.
173 if (arg
.startsWith("-V")) {
175 System
.out
.println(copyright
);
176 System
.out
.println("CheckTools, " + version
);
185 String WORKSPACE
= System
.getenv("WORKSPACE");
186 if ((DEBUG
> 0) || (VERBOSE
> 0))
187 System
.out
.println("Verifying Tool Chains for WORKSPACE: " + WORKSPACE
);
190 if (WORKSPACE
== null) {
192 System
.out
.println("Please set the environment variable, WORKSPACE and run again.");
195 String targetTxt
= WORKSPACE
+ SEP
+ "Tools" + SEP
+ "Conf" + SEP
+ "target.txt";
198 if (inFile
.length() < 1) {
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.
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()) {
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();
220 inFile
= fileLine
[1].trim();
225 } catch (IOException e
) {
227 System
.out
.println(" [target.txt] Read Error: " + e
);
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
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");
245 toolsDef
= WORKSPACE
+ SEP
+ "Tools" + SEP
+ "Conf" + SEP
+ "tools_def.template";
246 File toolsTemplate
= new File(toolsDef
);
247 if (!toolsTemplate
.exists()) {
249 System
.out
.println("Your WORKSPACE is not properly configured!");
253 System
.out
.println("**** WARNING: No Tool Configuration File was found, using the template file, "
259 // at this point the file, toolsDef points to a tool configuration file of some sort.
261 // check tool configuration file
263 System
.out
.println("Calling checkTools(" + toolsDef
+ ", " + cmdCode
+ ", " + VERBOSE
+ ")");
264 ToolChecks tc
= new ToolChecks();
265 returnCode
= tc
.checkTools(toolsDef
, cmdCode
, VERBOSE
, QUIET
);
268 System
.out
.println(" checkTools returned: " + returnCode
);
272 private void usage() {
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.");
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.");