]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/global/Spd.java
Fixed grammar in messages.
[mirror_edk2.git] / Tools / Source / GenBuild / org / tianocore / build / global / Spd.java
CommitLineData
878ddf1f 1/** @file\r
2 Spd class.\r
3\r
4 This class is to generate a global table for the content of spd file.\r
5 \r
6 Copyright (c) 2006, Intel Corporation\r
7 All rights reserved. This program and the accompanying materials\r
8 are licensed and made available under the terms and conditions of the BSD License\r
9 which accompanies this distribution. The full text of the license may be found at\r
10 http://opensource.org/licenses/bsd-license.php\r
11 \r
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15 **/\r
16package org.tianocore.build.global;\r
a29c47e0 17\r
18import java.io.File;\r
878ddf1f 19import java.util.HashMap;\r
a29c47e0 20import java.util.Iterator;\r
878ddf1f 21import java.util.Map;\r
a29c47e0 22import java.util.Set;\r
878ddf1f 23\r
a29c47e0 24import org.apache.tools.ant.BuildException;\r
25import org.apache.xmlbeans.XmlObject;\r
26import org.tianocore.build.id.ModuleIdentification;\r
27import org.tianocore.build.id.PackageIdentification;\r
878ddf1f 28\r
29/**\r
30 \r
a29c47e0 31 This class is to generate a global table for the content of spd file.\r
32 \r
33 **/\r
878ddf1f 34public class Spd {\r
35 ///\r
878ddf1f 36 ///\r
a29c47e0 37 ///\r
38 Map<ModuleIdentification, File> msaInfo = new HashMap<ModuleIdentification, File>();\r
878ddf1f 39\r
40 ///\r
41 /// Map of module info. \r
42 /// Key : moduletype\r
43 /// Value: moduletype related include file\r
44 ///\r
a29c47e0 45 Map<String, String> packageHeaderInfo = new HashMap<String, String>();\r
878ddf1f 46\r
47 ///\r
48 /// Map of PPI info.\r
49 /// Key : PPI name\r
50 /// value: String[] a. PPI C_NAME; b. PPI GUID;\r
51 ///\r
52 Map<String, String[]> ppiInfo = new HashMap<String, String[]>();\r
53\r
54 ///\r
55 /// Map of Protocol info.\r
56 /// Key : Protocol name\r
57 /// value: String[] a. Protocol C_NAME; b. Protocol GUID;\r
58 ///\r
59 Map<String, String[]> protocolInfo = new HashMap<String, String[]>();\r
60\r
61 ///\r
62 /// Map of Guid info.\r
63 /// Key : Guid name\r
64 /// value: String[] a. Guid C_NAME; b. Guid's GUID;\r
65 ///\r
66 Map<String, String[]> guidInfo = new HashMap<String, String[]>();\r
67\r
878ddf1f 68 ///\r
136adffc 69 /// Map of Guid info\r
70 /// Key: GuidCName\r
71 /// value: String Guid's GUID\r
72 ///\r
73 Map<String, String> guidCnameInfo = new HashMap<String, String>();\r
74 \r
878ddf1f 75 /// Map of library class and its exposed header file.\r
76 /// Key : library class name\r
77 /// value : library class corresponding header file\r
78 ///\r
a29c47e0 79 Map<String, String[]> libClassHeaderList = new HashMap<String, String[]>();\r
878ddf1f 80\r
81 ///\r
82 /// Package path.\r
83 ///\r
a29c47e0 84 PackageIdentification packageId;\r
878ddf1f 85\r
86 /**\r
a29c47e0 87 Constructor function\r
88 \r
89 This function mainly initialize some member variables. \r
878ddf1f 90 **/\r
a29c47e0 91 Spd(File packageFile) throws BuildException {\r
92 //\r
93 // If specified package file not exists\r
94 //\r
95 if ( ! packageFile.exists()) {\r
96 throw new BuildException("Package file [" + packageFile.getPath() + "] not exists. ");\r
878ddf1f 97 }\r
a29c47e0 98 try {\r
99 XmlObject spdDoc = XmlObject.Factory.parse(packageFile);\r
100 //\r
101 // Verify SPD file, if is invalid, throw Exception\r
102 //\r
103 if (! spdDoc.validate()) {\r
104 throw new BuildException("Package Surface Area file [" + packageFile.getPath() + "] is invalid. ");\r
878ddf1f 105 }\r
a29c47e0 106 // We can change Map to XmlObject\r
107 Map<String, XmlObject> spdDocMap = new HashMap<String, XmlObject>();\r
108 spdDocMap.put("PackageSurfaceArea", spdDoc);\r
109 SurfaceAreaQuery.setDoc(spdDocMap);\r
110 //\r
111 //\r
112 //\r
113 packageId = SurfaceAreaQuery.getSpdHeader();\r
114 packageId.setSpdFile(packageFile);\r
115 \r
116 //\r
117 // initialize Msa Files\r
118 // MSA file is absolute file path\r
119 //\r
120 String[] msaFilenames = SurfaceAreaQuery.getSpdMsaFile();\r
121 for (int i = 0; i < msaFilenames.length; i++){\r
122 File msaFile = new File(packageId.getPackageDir() + File.separatorChar + msaFilenames[i]);\r
123 Map<String, XmlObject> msaDoc = GlobalData.getNativeMsa( msaFile );\r
124 SurfaceAreaQuery.push(msaDoc);\r
125 ModuleIdentification moduleId = SurfaceAreaQuery.getMsaHeader();\r
126 SurfaceAreaQuery.pop();\r
127 moduleId.setPackage(packageId);\r
128 moduleId.setMsaFile(msaFile);\r
129 if (msaInfo.containsKey(moduleId)) {\r
130 throw new BuildException("Find two modules with the same GUID and Version in " + packageId + ". They are [" + msaInfo.get(moduleId) + "] and [" + msaFile + "] ");\r
878ddf1f 131 }\r
a29c47e0 132 msaInfo.put(moduleId, msaFile);\r
878ddf1f 133 }\r
878ddf1f 134 \r
a29c47e0 135 //\r
136 // initialize Package header files\r
137 //\r
138 Map<String, String> packageHeaders = SurfaceAreaQuery.getSpdPackageHeaderFiles();\r
139 Set keys = packageHeaders.keySet();\r
140 Iterator iter = keys.iterator();\r
141 while (iter.hasNext()){\r
142 String moduleType = (String)iter.next();\r
143 String header = packageId.getPackageRelativeDir() + File.separatorChar + packageHeaders.get(moduleType);\r
144 \r
145 //\r
146 // Change path seperator to system-dependent path separator\r
147 //\r
148 File file = new File (header);\r
136adffc 149 header = file.getPath();\r
a29c47e0 150 packageHeaderInfo.put(moduleType, header);\r
878ddf1f 151 }\r
a29c47e0 152 \r
153 //\r
154 // initialize Guid Info\r
155 //\r
156 guidInfo.putAll(SurfaceAreaQuery.getSpdGuid());\r
157 \r
136adffc 158 //\r
159 // For Pcd get TokenSpaceGuid\r
160 //\r
161 Set<String> key = guidInfo.keySet();\r
162 Iterator item = key.iterator();\r
163 String [] nameValue = new String[2];\r
164 while(item.hasNext()){\r
165 nameValue = guidInfo.get(item.next());\r
166 guidCnameInfo.put(nameValue[0], nameValue[1]);\r
167 }\r
168 \r
a29c47e0 169 //\r
170 // initialize PPI info\r
171 //\r
172 ppiInfo.putAll(SurfaceAreaQuery.getSpdPpi());\r
173 \r
174 //\r
175 // initialize Protocol info\r
176 //\r
177 protocolInfo.putAll(SurfaceAreaQuery.getSpdProtocol());\r
178 \r
179 //\r
180 // initialize library class declaration\r
181 //\r
182 Map<String, String[]> libraryClassHeaders = SurfaceAreaQuery.getSpdLibraryClasses();\r
183 keys = libraryClassHeaders.keySet();\r
184 iter = keys.iterator();\r
185 while (iter.hasNext()){\r
186 String libraryClassName = (String)iter.next();\r
187 String[] headerFiles = libraryClassHeaders.get(libraryClassName);\r
188 for (int i = 0; i < headerFiles.length; i++){\r
189 headerFiles[i] = packageId.getPackageRelativeDir() + File.separatorChar + headerFiles[i];\r
190 \r
191 //\r
192 // Change path separator to system system-dependent path separator. \r
193 //\r
194 File file = new File (headerFiles[i]);\r
195 headerFiles[i] = file.getPath();\r
878ddf1f 196 }\r
a29c47e0 197 libClassHeaderList.put(libraryClassName, headerFiles);\r
878ddf1f 198 }\r
199 }\r
a29c47e0 200 catch (Exception e) {\r
201 e.setStackTrace(e.getStackTrace());\r
202 throw new BuildException("Parse package description file [" + packageId.getSpdFile() + "] Error.\n"\r
203 + e.getMessage());\r
878ddf1f 204 }\r
878ddf1f 205 }\r
206\r
a29c47e0 207 public PackageIdentification getPackageId() {\r
208 return packageId;\r
878ddf1f 209 }\r
210\r
a29c47e0 211 public File getModuleFile(ModuleIdentification moduleId) {\r
212 return msaInfo.get(moduleId);\r
213 }\r
214 \r
215 public Set<ModuleIdentification> getModules(){\r
216 return msaInfo.keySet();\r
878ddf1f 217 }\r
218\r
219 /**\r
a29c47e0 220 return two value {CName, Guid}. If not found, return null.\r
221 **/\r
222 public String[] getPpi(String ppiName) {\r
223 return ppiInfo.get(ppiName);\r
878ddf1f 224 }\r
225\r
226 /**\r
a29c47e0 227 return two value {CName, Guid}. If not found, return null.\r
878ddf1f 228 **/\r
a29c47e0 229 public String[] getProtocol(String protocolName) {\r
230 return protocolInfo.get(protocolName);\r
878ddf1f 231 }\r
232\r
233 /**\r
a29c47e0 234 return two value {CName, Guid}. If not found, return null.\r
878ddf1f 235 **/\r
a29c47e0 236 public String[] getGuid(String guidName) {\r
237 return guidInfo.get(guidName);\r
878ddf1f 238 }\r
239\r
136adffc 240 /**\r
241 * return Guid Value. \r
242 */\r
243 public String getGuidFromCname(String cName){\r
244 return guidCnameInfo.get(cName);\r
245 }\r
246 \r
878ddf1f 247 /**\r
a29c47e0 248 getLibClassInclude \r
249 \r
250 This function is to get the library exposed header file name according \r
251 library class name.\r
252 \r
253 @param libName Name of library class \r
254 @return Name of header file\r
878ddf1f 255 **/\r
a29c47e0 256 String[] getLibClassIncluder(String libName) {\r
878ddf1f 257 return libClassHeaderList.get(libName);\r
258 }\r
259\r
260 /**\r
261 getModuleTypeIncluder\r
a29c47e0 262 \r
878ddf1f 263 This function is to get the header file name from module info map \r
264 according to module type.\r
a29c47e0 265 \r
878ddf1f 266 @param moduleType Module type.\r
267 @return Name of header file.\r
268 **/\r
a29c47e0 269 String getPackageIncluder(String moduleType) {\r
270 return packageHeaderInfo.get(moduleType);\r
878ddf1f 271 }\r
a29c47e0 272 \r
878ddf1f 273\r
878ddf1f 274}\r