X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2Fglobal%2FSpd.java;h=965e8ef499233ba5c81a41c7051b56d82635af52;hb=892b0e7a05eb655d9734b0e24c7d8bea1ae4929b;hp=54c13910941c1a18d871d86674034c6c0a9bb4c5;hpb=878ddf1fc3540a715f63594ed22b6929e881afb4;p=mirror_edk2.git diff --git a/Tools/Source/GenBuild/org/tianocore/build/global/Spd.java b/Tools/Source/GenBuild/org/tianocore/build/global/Spd.java index 54c1391094..965e8ef499 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/global/Spd.java +++ b/Tools/Source/GenBuild/org/tianocore/build/global/Spd.java @@ -14,39 +14,37 @@ **/ package org.tianocore.build.global; + +import java.io.File; +import java.io.IOException; import java.util.HashMap; -import java.util.List; +import java.util.Iterator; import java.util.Map; +import java.util.Set; -import org.tianocore.PackageSurfaceAreaDocument; -import org.tianocore.GuidDeclarationsDocument.GuidDeclarations; -import org.tianocore.IncludeHeaderDocument.IncludeHeader; -import org.tianocore.LibraryClassDeclarationDocument.LibraryClassDeclaration; -import org.tianocore.LibraryClassDeclarationsDocument.LibraryClassDeclarations; -import org.tianocore.PackageHeadersDocument.PackageHeaders; -import org.tianocore.PackageSurfaceAreaDocument.PackageSurfaceArea; -import org.tianocore.PpiDeclarationsDocument.PpiDeclarations; -import org.tianocore.ProtocolDeclarationsDocument.ProtocolDeclarations; +import org.apache.xmlbeans.XmlException; +import org.apache.xmlbeans.XmlObject; +import org.tianocore.build.id.ModuleIdentification; +import org.tianocore.build.id.PackageIdentification; +import org.tianocore.common.exception.EdkException; /** - This class is to generate a global table for the content of spd file. - + This class is to generate a global table for the content of spd file. + **/ public class Spd { /// - /// Map of module name and package it belongs to. - /// Key : Module BaseName - /// Value: Relative Path to Package /// - Map msaInfo = new HashMap(); + /// + Map msaInfo = new HashMap(); /// /// Map of module info. /// Key : moduletype /// Value: moduletype related include file /// - Map moduleInfo = new HashMap(); + Map packageHeaderInfo = new HashMap(); /// /// Map of PPI info. @@ -69,346 +67,213 @@ public class Spd { /// Map guidInfo = new HashMap(); - /// + /// Map of Guid info + /// Key: GuidCName + /// value: String Guid's GUID + /// + Map guidCnameInfo = new HashMap(); + /// Map of library class and its exposed header file. /// Key : library class name /// value : library class corresponding header file /// - Map libClassHeaderList = new HashMap(); + Map libClassHeaderList = new HashMap(); /// /// Package path. /// - String packagePath = null; + PackageIdentification packageId; /** - Constructor function - - This function mainly initialize some member variables. - - @param spdDoc Handle of spd document. - @param spdPath Path of spd file. - **/ - Spd (PackageSurfaceAreaDocument spdDoc, String spdPath) { - - PackageSurfaceArea spd = spdDoc.getPackageSurfaceArea(); - this.packagePath = spdPath; - - GuidDeclarations spdGuidInfo = spd.getGuidDeclarations(); - genGuidInfoList(spdGuidInfo); - - PpiDeclarations spdPpiInfo = spd.getPpiDeclarations(); - genPpiInfoList(spdPpiInfo); - - ProtocolDeclarations spdProtocolInfo = spd.getProtocolDeclarations(); - genProtocolInfoList(spdProtocolInfo); - - LibraryClassDeclarations spdLibClassDeclare = spd - .getLibraryClassDeclarations(); - genLibClassDeclare(spdLibClassDeclare); - - PackageHeaders spdPackageHeaderInfo = spd.getPackageHeaders(); - genModuleInfoList(spdPackageHeaderInfo); - - } - - /** - genModuleInfoList - - This function is to generate Module info map. - - @param packageHeader The information of packageHeader which descripted - in spd file. + Constructor function + + This function mainly initialize some member variables. **/ - public void genModuleInfoList(PackageHeaders packageHeader) { - - if (packageHeader != null) { - List headerList = packageHeader.getIncludeHeaderList(); - for (int i = 0; i < headerList.size(); i++) { - try { - this.moduleInfo - .put(headerList.get(i).getModuleType() - .toString(), headerList.get(i) - .getStringValue()); - } catch (Exception e) { - System.out - .print("can't find ModuleHeaders ModuleType & includeHeader!\n"); - } - } + Spd(File packageFile) throws EdkException { + // + // If specified package file not exists + // + if ( ! packageFile.exists()) { + throw new EdkException("Package file [" + packageFile.getPath() + "] does not exist!"); } - } - - /** - genPpiInfoList - - This function is to generate Ppi info map. - - @param ppiInfo The information of PpiDeclarations which descripted - in spd file. - **/ - public void genPpiInfoList(PpiDeclarations ppiInfo) { - String[] cNameGuid = new String[2]; - - if (ppiInfo != null) { - List ppiEntryList = ppiInfo.getEntryList(); - for (int i = 0; i < ppiEntryList.size(); i++) { - try { - cNameGuid[0] = ppiEntryList.get(i).getCName(); - cNameGuid[1] = formatGuidName(ppiEntryList.get(i) - .getGuid().getStringValue()); - this.ppiInfo.put(ppiEntryList.get(i).getName(), new String[] { - cNameGuid[0], cNameGuid[1] }); - } catch (Exception e) { - System.out - .print("can't find GuidDeclarations C_Name & Guid!\n"); - } + try { + XmlObject spdDoc = XmlObject.Factory.parse(packageFile); + // + // Verify SPD file, if is invalid, throw Exception + // + if (! spdDoc.validate()) { + throw new EdkException("Package Surface Area file [" + packageFile.getPath() + "] format is invalid!"); } - } - } - - /** - genProtocolInfoList - - This function is to generate Protocol info map. - - @param proInfo The information of ProtocolDeclarations which - descripted in spd file. - **/ - public void genProtocolInfoList(ProtocolDeclarations proInfo) { - String[] cNameGuid = new String[2]; - if (proInfo != null) { - List protocolEntryList = proInfo.getEntryList(); - for (int i = 0; i < protocolEntryList.size(); i++) { - try { - cNameGuid[0] = protocolEntryList.get(i).getCName(); - cNameGuid[1] = formatGuidName(protocolEntryList.get(i) - .getGuid().getStringValue()); + // + // We can change Map to XmlObject + // + Map spdDocMap = new HashMap(); + spdDocMap.put("PackageSurfaceArea", spdDoc); + SurfaceAreaQuery saq = new SurfaceAreaQuery(spdDocMap); - String temp = new String(protocolEntryList.get(i).getName()); - this.protocolInfo.put(temp, new String[] { cNameGuid[0], - cNameGuid[1] }); - } catch (Exception e) { - System.out - .print("can't find ProtocolDeclarations C_Name & Guid!\n"); + packageId = saq.getSpdHeader(); + packageId.setSpdFile(packageFile); + + // + // initialize Msa Files + // MSA file is absolute file path + // + String[] msaFilenames = saq.getSpdMsaFile(); + for (int i = 0; i < msaFilenames.length; i++){ + File msaFile = new File(packageId.getPackageDir() + File.separatorChar + msaFilenames[i]); + Map msaDoc = GlobalData.getNativeMsa( msaFile ); + saq.push(msaDoc); + ModuleIdentification moduleId = saq.getMsaHeader(); + saq.pop(); + moduleId.setPackage(packageId); + moduleId.setMsaFile(msaFile); + if (msaInfo.containsKey(moduleId)) { + throw new EdkException("Found two modules with the same GUID and Version in package " + packageId + ".\nThey are module [" + msaInfo.get(moduleId) + "] and MSA file [" + msaFile + "]!"); } + msaInfo.put(moduleId, msaFile); } - } - } - - /** - genGuidInfoList - - This function is to generate GUID inf map. - - @param guidInfo The information of GuidDeclarations which descripted - in spd file. - - **/ - public void genGuidInfoList(GuidDeclarations guidInfo) { - String[] cNameGuid = new String[2]; - if (guidInfo != null) { - List guidEntryList = guidInfo.getEntryList(); - for (int i = 0; i < guidEntryList.size(); i++) { - cNameGuid[0] = guidEntryList.get(i).getCName(); - cNameGuid[1] = formatGuidName(guidEntryList.get(i) - .getGuid().getStringValue()); - this.guidInfo.put(guidEntryList.get(i).getName(), new String[] { - cNameGuid[0], cNameGuid[1] }); + // + // initialize Package header files + // + Map packageHeaders = saq.getSpdPackageHeaderFiles(); + Set keys = packageHeaders.keySet(); + Iterator iter = keys.iterator(); + while (iter.hasNext()){ + String moduleType = (String)iter.next(); + String header = packageId.getPackageRelativeDir() + File.separatorChar + packageHeaders.get(moduleType); + + // + // Change path seperator to system-dependent path separator + // + File file = new File (header); + header = file.getPath(); + packageHeaderInfo.put(moduleType, header); } - } - } - - /** - genLibClassDeclare - - This function is to generate the libClassHeader list. - - @param libClassDeclares The information of LibraryClassDeclarations which - descripted in spd file. - **/ - public void genLibClassDeclare(LibraryClassDeclarations libClassDeclares) { - if (libClassDeclares != null && libClassDeclares.getLibraryClassDeclarationList() != null) { - if (libClassDeclares.getLibraryClassDeclarationList().size() > 0) { - List libDeclareList = libClassDeclares.getLibraryClassDeclarationList(); - for (int i = 0; i < libDeclareList.size(); i++) { - libClassHeaderList.put(libDeclareList.get(i).getLibraryClass() - .getStringValue(), libDeclareList.get(i) - .getIncludeHeader().getStringValue()); + + // + // initialize Guid Info + // + guidInfo.putAll(saq.getSpdGuid()); + + // + // For Pcd get TokenSpaceGuid + // + Set key = guidInfo.keySet(); + Iterator item = key.iterator(); + String [] nameValue = new String[2]; + while(item.hasNext()){ + nameValue = guidInfo.get(item.next()); + guidCnameInfo.put(nameValue[0], nameValue[1]); + } + + // + // initialize PPI info + // + ppiInfo.putAll(saq.getSpdPpi()); + + // + // initialize Protocol info + // + protocolInfo.putAll(saq.getSpdProtocol()); + + // + // initialize library class declaration + // + Map libraryClassHeaders = saq.getSpdLibraryClasses(); + keys = libraryClassHeaders.keySet(); + iter = keys.iterator(); + while (iter.hasNext()){ + String libraryClassName = (String)iter.next(); + String[] headerFiles = libraryClassHeaders.get(libraryClassName); + for (int i = 0; i < headerFiles.length; i++){ + headerFiles[i] = packageId.getPackageRelativeDir() + File.separatorChar + headerFiles[i]; + + // + // Change path separator to system system-dependent path separator. + // + File file = new File (headerFiles[i]); + headerFiles[i] = file.getPath(); } + libClassHeaderList.put(libraryClassName, headerFiles); } + } catch (IOException ex) { + EdkException edkException = new EdkException("Parse of the package description file [" + packageFile.getPath() + "] failed!\n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; + } catch (XmlException ex) { + EdkException edkException = new EdkException("Parse of the package description file [" + packageFile.getPath() + "] failed!\n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; } } - /** - getPpiGuid - - This function is to get ppi GUID according ppi name. - - @param ppiStr Name of ppi. - @return PPi's GUID. - **/ - public String getPpiGuid(String ppiStr) { - if (ppiInfo.get(ppiStr) != null) { - return ppiInfo.get(ppiStr)[1]; - } else { - return null; - } - + public PackageIdentification getPackageId() { + return packageId; } - /** - getPpiCnameGuidArray - - This function is to get the ppi CName and it's GUID according to ppi name. - - @param ppiName Name of ppi. - @return Ppi CName and it's GUID. - **/ - public String[] getPpiCnameGuidArray(String ppiName) { - return this.ppiInfo.get(ppiName); + public File getModuleFile(ModuleIdentification moduleId) { + return msaInfo.get(moduleId); + } + + public Set getModules(){ + return msaInfo.keySet(); } /** - getProtocolGuid - - This function is to get the protocol GUID according to protocol's name. - - @param protocolStr Name of protocol. - @return Protocol's GUID. - **/ - public String getProtocolGuid(String protocolStr) { - if (protocolInfo.get(protocolStr) != null) { - return this.protocolInfo.get(protocolStr)[0]; - } else { - return null; - } + return two value {CName, Guid}. If not found, return null. + **/ + public String[] getPpi(String ppiName) { + return ppiInfo.get(ppiName); } /** - getProtocolNameGuidArray - - This function is to get the protocol's CName ant it's GUID according to - protocol's namej. - - @param protocolName Name of protocl. - @return Protocol's CName and it's GUID. + return two value {CName, Guid}. If not found, return null. **/ - public String[] getProtocolNameGuidArray(String protocolName) { - return this.protocolInfo.get(protocolName); + public String[] getProtocol(String protocolName) { + return protocolInfo.get(protocolName); } /** - getGUIDGuid - - This function is to get the GUID according to GUID's name - - @param guidStr Name of GUID - @return GUID. + return two value {CName, Guid}. If not found, return null. **/ - public String getGUIDGuid(String guidStr) { - if (guidInfo.get(guidStr) != null) { - return guidInfo.get(guidStr)[1]; - } else { - return null; - } - + public String[] getGuid(String guidName) { + return guidInfo.get(guidName); } /** - getGuidNameArray - - This function is to get the GUID's CName and it's GUID according to - GUID's name - - @param guidName Name of GUID - @return CName and GUID. - **/ - public String[] getGuidNameArray(String guidName) { - return this.guidInfo.get(guidName); + * return Guid Value. + */ + public String getGuidFromCname(String cName){ + return guidCnameInfo.get(cName); } - + /** - getLibClassInclude - - This function is to get the library exposed header file name according - library class name. - - @param libName Name of library class - @return Name of header file + getLibClassInclude + + This function is to get the library exposed header file name according + library class name. + + @param libName Name of library class + @return Name of header file **/ - String getLibClassIncluder(String libName) { + String[] getLibClassIncluder(String libName) { return libClassHeaderList.get(libName); } /** getModuleTypeIncluder - + This function is to get the header file name from module info map according to module type. - + @param moduleType Module type. @return Name of header file. **/ - String getModuleTypeIncluder(String moduleType) { - return moduleInfo.get(moduleType); + String getPackageIncluder(String moduleType) { + return packageHeaderInfo.get(moduleType); } + - /** - formateGuidName - - This function is to formate GUID to ANSI c form. - - @param guidNameCon String of GUID. - @return Formated GUID. - **/ - public static String formatGuidName (String guidNameConv) { - String[] strList; - String guid = ""; - int index = 0; - if (guidNameConv - .matches("[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}")) { - strList = guidNameConv.split("-"); - guid = "0x" + strList[0] + ", "; - guid = guid + "0x" + strList[1] + ", "; - guid = guid + "0x" + strList[2] + ", "; - guid = guid + "{"; - guid = guid + "0x" + strList[3].substring(0, 2) + ", "; - guid = guid + "0x" + strList[3].substring(2, 4); - - while (index < strList[4].length()) { - guid = guid + ", "; - guid = guid + "0x" + strList[4].substring(index, index + 2); - index = index + 2; - } - guid = guid + "}"; - return guid; - } else if (guidNameConv - .matches("0x[a-fA-F0-9]{1,8},( )*0x[a-fA-F0-9]{1,4},( )*0x[a-fA-F0-9]{1,4}(,( )*\\{)?(,?( )*0x[a-fA-F0-9]{1,2}){8}( )*(\\})?")) { - strList = guidNameConv.split(","); - - // - // chang Microsoft specific form to ANSI c form - // - for (int i = 0; i < 3; i++){ - guid = guid + strList[i] + ","; - } - guid = guid + "{"; - - for (int i = 3; i < strList.length; i++){ - if (i == strList.length - 1){ - guid = guid + strList[i]; - } else { - guid = guid + strList[i] + ","; - } - } - guid = guid + "}"; - return guid; - } else { - System.out.println("Check GUID Value, it don't conform to the schema!!!"); - return "0"; - - } - } }