579c5f50d6e3af58cfe0dd98f13d4fdc4c48b7f0
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.
39 package org
.tianocore
.CheckTools
;
43 public class CheckTools
{
44 private static int DEBUG
= 0;
46 private static final String copyright
= "Copyright (c) 2006, Intel Corporation All rights reserved.";
48 private static final String version
= "Version 0.1";
50 private int VERBOSE
= 0;
52 // private String argv[];
54 private final int DEFAULT
= 1;
56 private final int TEST
= 2;
58 private final int SCAN
= 4;
60 private final int INTERACTIVE
= 8;
62 private boolean USERFILE
= false;
64 private String inFile
= "";
66 private final int PASS
= 0;
68 private final int FAIL
= 1;
70 private String SEP
= System
.getProperty("file.separator");
72 public static void main(String
[] argv
) {
73 int exitCode
= new CheckTools().checkTool(argv
);
75 new CheckTools().usage();
78 System
.exit(exitCode
);
81 private int checkTool(String
[] arguments
) {
82 String WORKSPACE
= System
.getenv("WORKSPACE");
83 if ((DEBUG
> 0) || (VERBOSE
> 0))
84 System
.out
.println("Verifying Tool Chains for WORKSPACE: " + WORKSPACE
);
87 if (WORKSPACE
== null) {
88 System
.out
.println("Please set the environment variable, WORKSPACE and run again.");
91 String targetTxt
= WORKSPACE
+ SEP
+ "Tools" + SEP
+ "Conf" + SEP
+ "target.txt";
93 if ((DEBUG
> 1) && (arguments
.length
> 0))
94 System
.out
.println("Arguments: ");
95 int cmdCode
= DEFAULT
;
96 if (arguments
.length
> 0) {
98 for (int i
= 0; i
< arguments
.length
; i
++) {
99 String arg
= arguments
[i
];
101 System
.out
.println(" [" + i
+ "] " + arg
);
102 if (!(arg
.toLowerCase().startsWith("-t") || arg
.toLowerCase().startsWith("-s")
103 || arg
.toLowerCase().startsWith("-i") || arg
.toLowerCase().startsWith("-v")
104 || arg
.toLowerCase().startsWith("-h") || arg
.toLowerCase().startsWith("-f"))) {
105 // Only allow valid option flags
106 System
.out
.println("Invalid argument: " + arg
);
111 if (arg
.toLowerCase().startsWith("-h")) {
116 if (arg
.toLowerCase().startsWith("-t")) {
117 if (cmdCode
== DEFAULT
) {
120 System
.out
.println("Invalid Options");
125 if (arg
.toLowerCase().startsWith("-s")) {
126 if (cmdCode
== DEFAULT
) {
129 System
.out
.println("Invalid Options");
134 if (arg
.toLowerCase().startsWith("-i")) {
135 // Interactive can be specified with any
136 // other option - it turns on the query
138 cmdCode
= cmdCode
| INTERACTIVE
;
140 if (arg
.toLowerCase().startsWith("-f")) {
142 inFile
= arguments
[i
];
145 if (arg
.startsWith("-v")) {
146 // Verbose level can be increased to print
147 // more INFO messages.
150 if (arg
.startsWith("-V")) {
151 System
.out
.println(copyright
);
152 System
.out
.println("CheckTools, " + version
);
158 if (inFile
.length() < 1) {
160 // Check the target.txt file for a Tool Configuration File.
161 // If not set, we use tools_def.txt, unless we are running with the
162 // INTERACTIVE flag - where we check the template file before copying over to the
163 // tools_def.txt file.
165 inFile
= "tools_def.txt";
166 File target
= new File(targetTxt
);
167 String readLine
= null;
168 String fileLine
[] = new String
[2];
169 if (target
.exists()) {
171 FileReader fileReader
= new FileReader(targetTxt
);
172 BufferedReader bufReader
= new BufferedReader(fileReader
);
173 while ((readLine
= bufReader
.readLine()) != null) {
174 if (readLine
.startsWith("TOOL_CHAIN_CONF")) {
175 fileLine
= readLine
.trim().split("=");
176 if (fileLine
[1].trim().length() > 0) {
177 if (fileLine
[1].trim().contains("Tools/Conf/"))
178 inFile
= fileLine
[1].replace("Tools/Conf/", "").trim();
180 inFile
= fileLine
[1].trim();
185 } catch (IOException e
) {
186 System
.out
.println(" [target.txt] Read Error: " + e
);
192 // OK, now check the infile of we had one.
193 String toolsDef
= WORKSPACE
+ SEP
+ "Tools" + SEP
+ "Conf" + SEP
+ inFile
;
194 File toolsFile
= new File(toolsDef
);
195 if (!toolsFile
.exists()) {
196 // use the template file
198 System
.out
.println("Could not locate the specified file: " + inFile
);
199 System
.out
.println(" It must be located in the WORKSPACE" + SEP
+ "Tools" + SEP
+ "Conf directory");
202 toolsDef
= WORKSPACE
+ SEP
+ "Tools" + SEP
+ "Conf" + SEP
+ "tools_def.template";
203 File toolsTemplate
= new File(toolsDef
);
204 if (!toolsTemplate
.exists()) {
205 System
.out
.println("Your WORKSPACE is not properly configured!");
208 System
.out
.println("**** WARNING: No Tool Configuration File was found, using the template file, "
214 // at this point the file, toolsDef points to a tool configuration file of some sort.
216 // check tool configuration file
218 System
.out
.println("Calling checkTools(" + toolsDef
+ ", " + cmdCode
+ ", " + VERBOSE
+ ")");
219 returnCode
= new ToolChecks().checkTools(toolsDef
, cmdCode
, VERBOSE
);
224 private void usage() {
225 System
.out
.println("Usage: checkTools [-h] [-i] [-v] [-s | -scan] [-t | -test] [[-f | -filename] filename.txt]");
226 System
.out
.println(" Where");
227 System
.out
.println(" -h Help - display this screen.");
228 System
.out
.println(" -i Interactive query - not yet implemented!");
229 System
.out
.println(" -v Verbose - add up to 3 -v options to increase info messages.");
230 System
.out
.println(" -s Scan - search the usual places on your system for tools.");
231 System
.out
.println(" The Scan feature not yet implemented!.");
232 System
.out
.println(" -t Test - checks that PATH entries in the tool configuration file exist.");
233 System
.out
.println(" -f filename Use filename instead of the file specified in target.txt or");
234 System
.out
.println(" tools_def.txt or tools_def.template.");
235 System
.out
.println(" By Rule, all tool configuration files must reside in the");
236 System
.out
.println(" WORKSPACE" + SEP
+ "Tools" + SEP
+ "Conf directory.");