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