ddfdc8e6 |
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)); |
a8e1928c |
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 | } |
ddfdc8e6 |
96 | } |
97 | |
98 | return returnCode; |
99 | } |
100 | |
101 | private int scanFile(String testFile, boolean interActive, int VERBOSE) { |
102 | if ((DEBUG > 0) || (VERBOSE > 0)) |
103 | System.out.println("Scanning the Normal Installation Locations ..."); |
104 | System.out.println("The Scan function has not been implemented yet!"); |
105 | return FAIL; |
106 | } |
107 | private int testFile(String testFile, boolean interActive, int VERBOSE) { |
108 | |
109 | int retCode = PASS; |
110 | String readLine = ""; |
111 | String fileLine[] = new String[2]; |
112 | try { |
113 | FileReader toolConfFile = new FileReader(testFile); |
114 | BufferedReader reader = new BufferedReader(toolConfFile); |
115 | String path = ""; |
116 | String props[] = new String[5]; |
117 | String lastErrTag = "barf"; |
118 | String lastTag = "barf"; |
119 | while ((readLine = reader.readLine()) != null) { |
120 | if ((!readLine.startsWith("#")) && (readLine.contains("_PATH"))) { |
121 | if (DEBUG > 2) { |
122 | System.out.println(" PATH LINE: " + readLine); |
123 | } |
124 | readLine = readLine.trim(); |
125 | fileLine = readLine.split("="); |
126 | path = fileLine[1].trim(); |
127 | props = fileLine[0].split("_"); |
128 | File testPath = new File(path); |
129 | if (!testPath.exists()) { |
130 | if (!props[1].trim().contentEquals(lastErrTag)) |
c81d735d |
131 | errLog.add(" -- WARNING: Tool Chain Tag Name: " + props[1].trim() + " is NOT valid!"); |
a8e1928c |
132 | if (VERBOSE > 1) |
c81d735d |
133 | errLog.add(" Tool Code: [" + props[3].trim() + "] Path: " + path + " does not exist!"); |
ddfdc8e6 |
134 | retCode = 1; |
135 | lastErrTag = props[1].trim(); |
136 | } else { |
137 | if ((DEBUG > 0) || (VERBOSE > 0)) { |
138 | if ((!props[1].trim().contentEquals(lastTag)) |
139 | && (!props[1].trim().contentEquals(lastErrTag))) |
140 | System.out.println("Tool Chain: " + props[1].trim() + " is valid"); |
141 | } |
142 | if (!props[1].trim().contentEquals(lastTag)) |
143 | goodLog.add(props[1].trim()); |
144 | lastTag = props[1].trim(); |
145 | } |
146 | } |
147 | } |
148 | } catch (IOException e) { |
149 | System.out.println(" [" + testFile + "] " + e); |
150 | System.exit(1); |
151 | } |
152 | if (errLog.size() > 0) |
153 | for (int i = 0; i < goodLog.size(); i++) { |
154 | for (int j = 0; j < errLog.size(); j++) { |
155 | if (errLog.get(j).contains(goodLog.get(i).trim())) { |
156 | goodLog.remove(i); |
157 | break; |
158 | } |
159 | } |
160 | } |
161 | return retCode; |
162 | |
163 | } |
164 | |
165 | } |