]>
git.proxmox.com Git - mirror_edk2.git/blob - Tools/Java/Source/CheckTools/src/org/tianocore/CheckTools/CheckTools.java
4f61cc6b8839fe88ad58eaed0fafc069f712876a
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 public static void main(String
[] argv
) {
71 int exitCode
= new CheckTools().checkTool(argv
);
73 new CheckTools().usage();
76 System
.exit(exitCode
);
79 private int checkTool(String
[] arguments
) {
80 String WORKSPACE
= System
.getenv("WORKSPACE");
81 if ((DEBUG
> 0) || (VERBOSE
> 0))
82 System
.out
.println("Verifying Tool Chains for WORKSPACE: " + WORKSPACE
);
83 String SEP
= System
.getProperty("file.separator");
86 if (WORKSPACE
== null) {
87 System
.out
.println("Please set the environment variable, WORKSPACE and run again.");
90 String targetTxt
= WORKSPACE
+ SEP
+ "Tools" + SEP
+ "Conf" + SEP
+ "target.txt";
92 if ((DEBUG
> 1) && (arguments
.length
> 0))
93 System
.out
.println("Arguments: ");
94 int cmdCode
= DEFAULT
;
95 if (arguments
.length
> 0) {
97 for (int i
= 0; i
< arguments
.length
; i
++) {
98 String arg
= arguments
[i
];
100 System
.out
.println(" [" + i
+ "] " + arg
);
101 if (!(arg
.toLowerCase().startsWith("-t") || arg
.toLowerCase().startsWith("-s")
102 || arg
.toLowerCase().startsWith("-i") || arg
.toLowerCase().startsWith("-v") || arg
106 // Only allow valid option flags
107 System
.out
.println("Invalid argument: " + arg
);
111 if (arg
.toLowerCase().startsWith("-t")) {
112 if (cmdCode
== DEFAULT
) {
115 System
.out
.println("Invalid Options");
120 if (arg
.toLowerCase().startsWith("-s")) {
121 if (cmdCode
== DEFAULT
) {
124 System
.out
.println("Invalid Options");
129 if (arg
.toLowerCase().startsWith("-i")) {
130 // Interactive can be specified with any
131 // other option - it turns on the query
133 cmdCode
= cmdCode
| INTERACTIVE
;
135 if (arg
.toLowerCase().startsWith("-f")) {
137 inFile
= arguments
[i
];
140 if (arg
.startsWith("-v")) {
141 // Verbose level can be increased to print
142 // more INFO messages.
145 if (arg
.startsWith("-V")) {
146 System
.out
.println(copyright
);
147 System
.out
.println("CheckTools, " + version
);
153 if (inFile
.length() < 1) {
155 // Check the target.txt file for a Tool Configuration File.
156 // If not set, we use tools_def.txt, unless we are running with the
157 // INTERACTIVE flag - where we check the template file before copying over to the
158 // tools_def.txt file.
160 inFile
= "tools_def.txt";
161 File target
= new File(targetTxt
);
162 String readLine
= null;
163 String fileLine
[] = new String
[2];
164 if (target
.exists()) {
166 FileReader fileReader
= new FileReader(targetTxt
);
167 BufferedReader bufReader
= new BufferedReader(fileReader
);
168 while ((readLine
= bufReader
.readLine()) != null) {
169 if (readLine
.startsWith("TOOL_CHAIN_CONF")) {
170 fileLine
= readLine
.trim().split("=");
171 if (fileLine
[1].trim().length() > 0) {
172 if (fileLine
[1].trim().contains("Tools/Conf/"))
173 inFile
= fileLine
[1].replace("Tools/Conf/", "").trim();
175 inFile
= fileLine
[1].trim();
180 } catch (IOException e
) {
181 System
.out
.println(" [target.txt] Read Error: " + e
);
187 // OK, now check the infile of we had one.
188 String toolsDef
= WORKSPACE
+ SEP
+ "Tools" + SEP
+ "Conf" + SEP
+ inFile
;
189 File toolsFile
= new File(toolsDef
);
190 if (!toolsFile
.exists()) {
191 // use the template file
193 System
.out
.println("Could not locate the specified file: " + inFile
);
194 System
.out
.println(" It must be located in the WORKSPACE" + SEP
+ "Tools" + SEP
+ "Conf directory");
197 toolsDef
= WORKSPACE
+ SEP
+ "Tools" + SEP
+ "Conf" + SEP
+ "tools_def.template";
198 File toolsTemplate
= new File(toolsDef
);
199 if (!toolsTemplate
.exists()) {
200 System
.out
.println("Your WORKSPACE is not properly configured!");
203 System
.out
.println("**** WARNING: No Tool Configuration File was found, using the template file, "
209 // at this point the file, toolsDef points to a tool configuration file of some sort.
211 // check tool configuration file
213 System
.out
.println("Calling checkTools(" + toolsDef
+ ", " + cmdCode
+ ", " + VERBOSE
+ ")");
214 returnCode
= new ToolChecks().checkTools(toolsDef
, cmdCode
, VERBOSE
);
219 private void usage() {
220 System
.out
.println("Usage: checkTools [-i] [-s | -scan] [-t | -test] [[-f | -filename] filename.txt]");