]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/GenBuild/org/tianocore/build/global/Spd.java
Change GenBuildLogger format.
[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
391dbbb1 96 throw new BuildException("Package file [" + packageFile.getPath() + "] does not exist!");\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
391dbbb1 104 throw new BuildException("Package Surface Area file [" + packageFile.getPath() + "] format 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
83fba802 109 SurfaceAreaQuery saq = new SurfaceAreaQuery(spdDocMap);\r
a29c47e0 110 //\r
111 //\r
112 //\r
83fba802 113 packageId = saq.getSpdHeader();\r
a29c47e0 114 packageId.setSpdFile(packageFile);\r
115 \r
116 //\r
117 // initialize Msa Files\r
118 // MSA file is absolute file path\r
119 //\r
83fba802 120 String[] msaFilenames = saq.getSpdMsaFile();\r
a29c47e0 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
83fba802 124 saq.push(msaDoc);\r
125 ModuleIdentification moduleId = saq.getMsaHeader();\r
126 saq.pop();\r
a29c47e0 127 moduleId.setPackage(packageId);\r
128 moduleId.setMsaFile(msaFile);\r
129 if (msaInfo.containsKey(moduleId)) {\r
391dbbb1 130 throw new BuildException("Found two modules with the same GUID and Version in package " + packageId + ".\nThey are module [" + msaInfo.get(moduleId) + "] and MSA file [" + 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
83fba802 138 Map<String, String> packageHeaders = saq.getSpdPackageHeaderFiles();\r
a29c47e0 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
83fba802 156 guidInfo.putAll(saq.getSpdGuid());\r
a29c47e0 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
83fba802 172 ppiInfo.putAll(saq.getSpdPpi());\r
a29c47e0 173 \r
174 //\r
175 // initialize Protocol info\r
176 //\r
83fba802 177 protocolInfo.putAll(saq.getSpdProtocol());\r
a29c47e0 178 \r
179 //\r
180 // initialize library class declaration\r
181 //\r
83fba802 182 Map<String, String[]> libraryClassHeaders = saq.getSpdLibraryClasses();\r
a29c47e0 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
e485bb4b 201 throw new BuildException("Parse of the package description file [" + packageFile.getPath() + "] failed!\n"\r
a29c47e0 202 + e.getMessage());\r
878ddf1f 203 }\r
878ddf1f 204 }\r
205\r
a29c47e0 206 public PackageIdentification getPackageId() {\r
207 return packageId;\r
878ddf1f 208 }\r
209\r
a29c47e0 210 public File getModuleFile(ModuleIdentification moduleId) {\r
211 return msaInfo.get(moduleId);\r
212 }\r
213 \r
214 public Set<ModuleIdentification> getModules(){\r
215 return msaInfo.keySet();\r
878ddf1f 216 }\r
217\r
218 /**\r
a29c47e0 219 return two value {CName, Guid}. If not found, return null.\r
220 **/\r
221 public String[] getPpi(String ppiName) {\r
222 return ppiInfo.get(ppiName);\r
878ddf1f 223 }\r
224\r
225 /**\r
a29c47e0 226 return two value {CName, Guid}. If not found, return null.\r
878ddf1f 227 **/\r
a29c47e0 228 public String[] getProtocol(String protocolName) {\r
229 return protocolInfo.get(protocolName);\r
878ddf1f 230 }\r
231\r
232 /**\r
a29c47e0 233 return two value {CName, Guid}. If not found, return null.\r
878ddf1f 234 **/\r
a29c47e0 235 public String[] getGuid(String guidName) {\r
236 return guidInfo.get(guidName);\r
878ddf1f 237 }\r
238\r
136adffc 239 /**\r
240 * return Guid Value. \r
241 */\r
242 public String getGuidFromCname(String cName){\r
243 return guidCnameInfo.get(cName);\r
244 }\r
245 \r
878ddf1f 246 /**\r
a29c47e0 247 getLibClassInclude \r
248 \r
249 This function is to get the library exposed header file name according \r
250 library class name.\r
251 \r
252 @param libName Name of library class \r
253 @return Name of header file\r
878ddf1f 254 **/\r
a29c47e0 255 String[] getLibClassIncluder(String libName) {\r
878ddf1f 256 return libClassHeaderList.get(libName);\r
257 }\r
258\r
259 /**\r
260 getModuleTypeIncluder\r
a29c47e0 261 \r
878ddf1f 262 This function is to get the header file name from module info map \r
263 according to module type.\r
a29c47e0 264 \r
878ddf1f 265 @param moduleType Module type.\r
266 @return Name of header file.\r
267 **/\r
a29c47e0 268 String getPackageIncluder(String moduleType) {\r
269 return packageHeaderInfo.get(moduleType);\r
878ddf1f 270 }\r
a29c47e0 271 \r
878ddf1f 272\r
878ddf1f 273}\r