]>
Commit | Line | Data |
---|---|---|
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 | */ | |
39 | package org.tianocore.CheckTools; | |
40 | ||
41 | import java.io.*; | |
42 | ||
43 | public class CheckTools { | |
44 | private static int DEBUG = 0; | |
45 | ||
46 | private static final String copyright = "Copyright (c) 2006, Intel Corporation All rights reserved."; | |
47 | ||
48 | private static final String version = "Version 0.1"; | |
49 | ||
50 | private int VERBOSE = 0; | |
51 | ||
52 | // private String argv[]; | |
53 | ||
54 | private final int DEFAULT = 1; | |
55 | ||
56 | private final int TEST = 2; | |
57 | ||
58 | private final int SCAN = 4; | |
59 | ||
60 | private final int INTERACTIVE = 8; | |
61 | ||
62 | private boolean USERFILE = false; | |
63 | ||
64 | private String inFile = ""; | |
65 | ||
66 | private final int PASS = 0; | |
67 | ||
68 | private final int FAIL = 1; | |
69 | ||
70 | private String SEP = System.getProperty("file.separator"); | |
71 | ||
72 | public static void main(String[] argv) { | |
73 | int exitCode = new CheckTools().checkTool(argv); | |
74 | if (exitCode == -1) { | |
75 | new CheckTools().usage(); | |
76 | System.exit(1); | |
77 | } | |
78 | System.exit(exitCode); | |
79 | } | |
80 | ||
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); | |
85 | int returnCode = 0; | |
86 | ||
87 | if (WORKSPACE == null) { | |
88 | System.out.println("Please set the environment variable, WORKSPACE and run again."); | |
89 | System.exit(FAIL); | |
90 | } | |
91 | String targetTxt = WORKSPACE + SEP + "Tools" + SEP + "Conf" + SEP + "target.txt"; | |
92 | ||
93 | if ((DEBUG > 1) && (arguments.length > 0)) | |
94 | System.out.println("Arguments: "); | |
95 | int cmdCode = DEFAULT; | |
96 | if (arguments.length > 0) { | |
97 | cmdCode = DEFAULT; | |
98 | for (int i = 0; i < arguments.length; i++) { | |
99 | String arg = arguments[i]; | |
100 | if (DEBUG > 1) | |
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); | |
107 | usage(); | |
108 | System.exit(FAIL); | |
109 | } | |
110 | ||
111 | if (arg.toLowerCase().startsWith("-h")) { | |
112 | usage(); | |
113 | System.exit(PASS); | |
114 | } | |
115 | ||
116 | if (arg.toLowerCase().startsWith("-t")) { | |
117 | if (cmdCode == DEFAULT) { | |
118 | cmdCode = TEST; | |
119 | } else { | |
120 | System.out.println("Invalid Options"); | |
121 | usage(); | |
122 | System.exit(FAIL); | |
123 | } | |
124 | } | |
125 | if (arg.toLowerCase().startsWith("-s")) { | |
126 | if (cmdCode == DEFAULT) { | |
127 | cmdCode = SCAN; | |
128 | } else { | |
129 | System.out.println("Invalid Options"); | |
130 | usage(); | |
131 | System.exit(FAIL); | |
132 | } | |
133 | } | |
134 | if (arg.toLowerCase().startsWith("-i")) { | |
135 | // Interactive can be specified with any | |
136 | // other option - it turns on the query | |
137 | // on fail mode. | |
138 | cmdCode = cmdCode | INTERACTIVE; | |
139 | } | |
140 | if (arg.toLowerCase().startsWith("-f")) { | |
141 | i++; | |
142 | inFile = arguments[i]; | |
143 | USERFILE = true; | |
144 | } | |
145 | if (arg.startsWith("-v")) { | |
146 | // Verbose level can be increased to print | |
147 | // more INFO messages. | |
148 | VERBOSE += 1; | |
149 | } | |
150 | if (arg.startsWith("-V")) { | |
151 | System.out.println(copyright); | |
152 | System.out.println("CheckTools, " + version); | |
153 | System.exit(PASS); | |
154 | } | |
155 | } | |
156 | } | |
157 | ||
158 | if (inFile.length() < 1) { | |
159 | // | |
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. | |
164 | // | |
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()) { | |
170 | try { | |
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(); | |
179 | else | |
180 | inFile = fileLine[1].trim(); | |
181 | } | |
182 | } | |
183 | } | |
184 | bufReader.close(); | |
185 | } catch (IOException e) { | |
186 | System.out.println(" [target.txt] Read Error: " + e); | |
187 | System.exit(FAIL); | |
188 | } | |
189 | } | |
190 | } | |
191 | ||
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 | |
197 | if (USERFILE) { | |
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"); | |
200 | System.exit(FAIL); | |
201 | } | |
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!"); | |
206 | System.exit(FAIL); | |
207 | } else { | |
208 | System.out.println("**** WARNING: No Tool Configuration File was found, using the template file, " | |
209 | + toolsDef); | |
210 | } | |
211 | } | |
212 | ||
213 | // | |
214 | // at this point the file, toolsDef points to a tool configuration file of some sort. | |
215 | // | |
216 | // check tool configuration file | |
217 | if (DEBUG > 2) | |
218 | System.out.println("Calling checkTools(" + toolsDef + ", " + cmdCode + ", " + VERBOSE + ")"); | |
219 | returnCode = new ToolChecks().checkTools(toolsDef, cmdCode, VERBOSE); | |
220 | ||
221 | return returnCode; | |
222 | } | |
223 | ||
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."); | |
237 | } | |
238 | } |