]>
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 = INIT checks the tools_def.template file | |
23 | * | |
24 | * -s = SCAN will check all standard locations for tool chains | |
25 | * C:\Program Files\Microsoft Visual Studio * | |
26 | * C:\WINDDK | |
27 | * C:\Bin | |
28 | * C:\ASL | |
29 | * C:\MASM* | |
30 | * /opt/tiano | |
31 | * | |
32 | * -f = FILE check the tools in this file instead of tools_def.txt, or | |
33 | * a file that was specified in target.txt | |
34 | */ | |
35 | package org.tianocore.CheckTools; | |
36 | ||
37 | import java.io.*; | |
38 | import java.util.*; | |
39 | ||
40 | public class ToolChecks { | |
41 | private static int DEBUG = 0; | |
42 | ||
43 | private final int DEFAULT = 1; | |
44 | ||
45 | private final int TEST = 2; | |
46 | ||
47 | private final int SCAN = 4; | |
48 | ||
49 | private final int INTERACTIVE = 8; | |
50 | ||
51 | private final int PASS = 0; | |
52 | ||
53 | private final int FAIL = 1; | |
54 | ||
55 | private ArrayList<String> errLog = new ArrayList<String>(); | |
56 | ||
57 | private ArrayList<String> goodLog = new ArrayList<String>(); | |
58 | ||
59 | public int checkTools(String toolConfFile, int cmdCode, int VERBOSE) { | |
60 | ||
61 | int returnCode = FAIL; | |
62 | boolean interActive = false; | |
63 | ||
64 | if ((DEBUG > 0) || (VERBOSE > 0)) { | |
65 | System.out.println("Using Tool Configuration File: " + toolConfFile); | |
66 | } | |
67 | ||
68 | if (DEBUG > 2) | |
69 | System.out.println("The cmdCode: " + cmdCode); | |
70 | ||
71 | if ((cmdCode & INTERACTIVE) == INTERACTIVE) { | |
72 | interActive = true; | |
73 | System.out.println("***** WARNING ***** The Interactive function has not been implemented yet!"); | |
74 | } | |
75 | ||
76 | if ((cmdCode & SCAN) == SCAN) { | |
77 | returnCode = scanFile(toolConfFile, interActive, VERBOSE); | |
78 | } | |
79 | ||
80 | if (((cmdCode & TEST) == TEST) || ((cmdCode & DEFAULT) == DEFAULT)) | |
81 | returnCode = testFile(toolConfFile, interActive, VERBOSE); | |
82 | ||
83 | if (!errLog.isEmpty()) { | |
84 | System.out.println("Tool Configuration File: " + toolConfFile); | |
85 | for (int i = 0; i < goodLog.size(); i++) | |
86 | System.out.println("Tool Chain Tag Name: " + goodLog.get(i) + " is valid!"); | |
87 | for (int i = 0; i < errLog.size(); i++) | |
88 | System.out.println(errLog.get(i)); | |
89 | if (VERBOSE > 0) { | |
90 | System.out.println(); | |
91 | System.out.println("You can remove these WARNING messages by editing the file:"); | |
92 | System.out.println(" " + toolConfFile); | |
93 | System.out.println("and commenting out out or deleting the entries for the tool"); | |
94 | System.out.println("chain tag names that do not apply to your system."); | |
95 | } | |
96 | } else { | |
97 | System.out.println(""); | |
98 | System.out.println(" Tool Configuration File: " + toolConfFile + " is valid!"); | |
99 | } | |
100 | ||
101 | return returnCode; | |
102 | } | |
103 | ||
104 | private int scanFile(String testFile, boolean interActive, int VERBOSE) { | |
105 | if ((DEBUG > 0) || (VERBOSE > 0)) | |
106 | System.out.println("Scanning the Normal Installation Locations ..."); | |
107 | System.out.println("The Scan function has not been implemented yet!"); | |
108 | return FAIL; | |
109 | } | |
110 | private int testFile(String testFile, boolean interActive, int VERBOSE) { | |
111 | ||
112 | int retCode = PASS; | |
113 | String readLine = ""; | |
114 | String fileLine[] = new String[2]; | |
115 | try { | |
116 | FileReader toolConfFile = new FileReader(testFile); | |
117 | BufferedReader reader = new BufferedReader(toolConfFile); | |
118 | String path = ""; | |
119 | String props[] = new String[5]; | |
120 | String lastErrTag = "barf"; | |
121 | String lastTag = "barf"; | |
122 | while ((readLine = reader.readLine()) != null) { | |
123 | if ((!readLine.startsWith("#")) && (readLine.contains("_PATH"))) { | |
124 | if (DEBUG > 2) { | |
125 | System.out.println(" PATH LINE: " + readLine); | |
126 | } | |
127 | readLine = readLine.trim(); | |
128 | fileLine = readLine.split("="); | |
129 | path = fileLine[1].trim(); | |
130 | props = fileLine[0].split("_"); | |
131 | File testPath = new File(path); | |
132 | if (!testPath.exists()) { | |
133 | if (!props[1].trim().contentEquals(lastErrTag)) | |
134 | errLog.add(" -- WARNING: Tool Chain Tag Name: " + props[1].trim() + " is NOT valid!"); | |
135 | if (VERBOSE > 1) | |
136 | errLog.add(" Tool Code: [" + props[3].trim() + "] Path: " + path + " does not exist!"); | |
137 | retCode = 1; | |
138 | lastErrTag = props[1].trim(); | |
139 | } else { | |
140 | if ((DEBUG > 0) || (VERBOSE > 0)) { | |
141 | if ((!props[1].trim().contentEquals(lastTag)) | |
142 | && (!props[1].trim().contentEquals(lastErrTag))) | |
143 | System.out.println("Tool Chain: " + props[1].trim() + " is valid"); | |
144 | } | |
145 | if (!props[1].trim().contentEquals(lastTag)) | |
146 | goodLog.add(props[1].trim()); | |
147 | lastTag = props[1].trim(); | |
148 | } | |
149 | } | |
150 | } | |
151 | } catch (IOException e) { | |
152 | System.out.println(" [" + testFile + "] " + e); | |
153 | System.exit(FAIL); | |
154 | } | |
155 | if (errLog.size() > 0) | |
156 | for (int i = 0; i < goodLog.size(); i++) { | |
157 | for (int j = 0; j < errLog.size(); j++) { | |
158 | if (errLog.get(j).contains(goodLog.get(i).trim())) { | |
159 | goodLog.remove(i); | |
160 | break; | |
161 | } | |
162 | } | |
163 | } | |
164 | return retCode; | |
165 | ||
166 | } | |
167 | ||
168 | } |