X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=Tools%2FSource%2FGenBuild%2Forg%2Ftianocore%2Fbuild%2Fglobal%2FGlobalData.java;h=fb283fd4c650e03e27b44f85373511fb8c81385e;hb=34913f248c5297dd8976c095763b7e44ed645d92;hp=9778eaf8a042104db28a157d0206e85adec4e55a;hpb=825168879302d78f47b0f1dea6009aecae0b62de;p=mirror_edk2.git diff --git a/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java b/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java index 9778eaf8a0..fb283fd4c6 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java +++ b/Tools/Source/GenBuild/org/tianocore/build/global/GlobalData.java @@ -17,15 +17,15 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. package org.tianocore.build.global; import java.io.File; +import java.io.IOException; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.logging.Logger; -import org.apache.tools.ant.BuildException; +import org.apache.xmlbeans.XmlException; import org.apache.xmlbeans.XmlObject; import org.tianocore.common.exception.EdkException; @@ -57,9 +57,6 @@ import org.tianocore.build.toolchain.ToolChainMap; @since GenBuild 1.0 **/ public class GlobalData { - - public static Logger log = Logger.getAnonymousLogger(); - /// /// Record current WORKSPACE Directory /// @@ -91,6 +88,8 @@ public class GlobalData { private static Map> fpdModuleSA= new HashMap>(); + private static Map fpdBuildOptionsMap = new HashMap(); + private static XmlObject fpdBuildOptions; private static XmlObject fpdDynamicPcds; @@ -141,7 +140,7 @@ public class GlobalData { @throws BuildException Framework Dababase or SPD or MSA file is not valid **/ - public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename ) throws BuildException { + public synchronized static void initInfo(String workspaceDatabaseFile, String workspaceDir, String toolsDefFilename ) throws EdkException { // // ensure this method will be revoked only once // @@ -163,7 +162,7 @@ public class GlobalData { // CONF dir + tools definition file name // File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename); - System.out.println("Using tool definiton file [" + toolsDefFile.getPath() + "]."); + EdkLog.log("Init", EdkLog.EDK_ALWAYS, "Using tool definition file [" + toolsDefFile.getPath() + "]."); toolsDef = new ToolChainConfig(toolsDefFile); // @@ -176,7 +175,7 @@ public class GlobalData { // validate FrameworkDatabaseFile // if (!db.validate()) { - throw new BuildException("Framework Database file [" + dbFile.getPath() + "] format is invalid!"); + throw new EdkException("Framework Database file [" + dbFile.getPath() + "] format is invalid!"); } // // Get package list @@ -185,9 +184,18 @@ public class GlobalData { List packages = db.getFrameworkDatabase().getPackageList().getFilenameList(); Iterator iter = packages.iterator(); while (iter.hasNext()) { - String fileName = iter.next().getStringValue(); + String fileName = iter.next().getStringValue().trim(); Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName)); packageList.add(spd.getPackageId()); + // + // Report warning if existing two packages with same GUID and Version + // + if (spdTable.containsKey(spd.getPackageId())) { + // + // BUGBUG + // + EdkLog.log("Init", EdkLog.EDK_WARNING, "Warning: Existing two packages with same GUID and Version. They are ... " + spd.getPackageId().getSpdFile().getPath()); + } spdTable.put(spd.getPackageId(), spd); } } @@ -199,34 +207,46 @@ public class GlobalData { List platforms = db.getFrameworkDatabase().getPlatformList().getFilenameList(); Iterator iter = platforms.iterator(); while (iter.hasNext()) { - String fileName = iter.next().getStringValue(); + String fileName = iter.next().getStringValue().trim(); File fpdFile = new File(workspaceDir + File.separatorChar + fileName); if ( !fpdFile.exists() ) { - throw new BuildException("Platform file [" + fpdFile.getPath() + "] not exists. "); + throw new EdkException("Platform file [" + fpdFile.getPath() + "] not exists. "); } XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile); // // Verify FPD file, if is invalid, throw Exception // if (!fpdDoc.validate()) { - throw new BuildException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!"); + throw new EdkException("Framework Platform Surface Area file [" + fpdFile.getPath() + "] format is invalid!"); } // // We can change Map to XmlObject // - // - // TBD check SPD or FPD is existed in FS - // Map fpdDocMap = new HashMap(); fpdDocMap.put("PlatformSurfaceArea", fpdDoc); - SurfaceAreaQuery.setDoc(fpdDocMap); - PlatformIdentification platformId = SurfaceAreaQuery.getFpdHeader(); + SurfaceAreaQuery saq = new SurfaceAreaQuery(fpdDocMap); + PlatformIdentification platformId = saq.getFpdHeader(); platformId.setFpdFile(fpdFile); + // + // Report warning if existing two platfrom with same GUID and Version + // + if (platformList.contains(platformId)) { + // + // BUGBUG + // + EdkLog.log("Init", EdkLog.EDK_WARNING, "Warning: Existing two platforms with same GUID and Version. They are ... " + fpdFile.getPath()); + } platformList.add(platformId); } } - } catch (Exception e) { - throw new BuildException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + e.getMessage()); + } catch(IOException ex) { + EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; + } catch(XmlException ex) { + EdkException edkException = new EdkException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; } } @@ -243,7 +263,7 @@ public class GlobalData { /** Get the MSA file name with absolute path */ - public synchronized static File getMsaFile(ModuleIdentification moduleId) throws BuildException { + public synchronized static File getMsaFile(ModuleIdentification moduleId) throws EdkException { File msaFile = null; // // TBD. Do only when package is null. @@ -258,13 +278,13 @@ public class GlobalData { } } if (msaFile == null){ - throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!"); + throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!"); } else { return msaFile; } } - public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) { + public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) throws EdkException { // // If package already defined in module // @@ -278,12 +298,16 @@ public class GlobalData { packageId = (PackageIdentification)iter.next(); moduleId.setPackage(packageId); Spd spd = spdTable.get(packageId); - if (spd.getModuleFile(moduleId) != null ) { - break ; + File tempMsaFile = null; + if ((tempMsaFile = spd.getModuleFile(moduleId)) != null ) { + if (tempMsaFile.getParent().equalsIgnoreCase(moduleId.getMsaFile().getParent())) { + break ; + } + tempMsaFile = null; } } if (packageId == null){ - throw new BuildException("Can't find Module [" + moduleId.getName() + "] in any SPD package!"); + throw new EdkException("Can't find Module [" + moduleId.getName() + "] in any SPD package!"); } else { return packageId; } @@ -301,7 +325,7 @@ public class GlobalData { } - public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map doc) { + public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map doc) throws EdkException{ Map result = new HashMap(); Set keySet = doc.keySet(); Iterator iter = keySet.iterator(); @@ -327,7 +351,7 @@ public class GlobalData { @return ModuleSA info and MSA info for fpdModuleId @throws BuildException Can't find MSA **/ - public synchronized static Map getDoc(FpdModuleIdentification fpdModuleId) throws BuildException { + public synchronized static Map getDoc(FpdModuleIdentification fpdModuleId) throws EdkException{ if (parsedModules.containsKey(fpdModuleId)) { return parsedModules.get(fpdModuleId); } @@ -357,10 +381,11 @@ public class GlobalData { return doc; } - public synchronized static Map getDoc(ModuleIdentification moduleId, String arch) throws BuildException { + public synchronized static Map getDoc(ModuleIdentification moduleId, String arch) throws EdkException{ FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch); return getDoc(fpdModuleId); } + /** Query the native MSA information with module base name. @@ -372,7 +397,7 @@ public class GlobalData { @throws BuildException MSA file is not valid **/ - public synchronized static Map getNativeMsa(ModuleIdentification moduleId) throws BuildException { + public synchronized static Map getNativeMsa(ModuleIdentification moduleId) throws EdkException { if (nativeMsa.containsKey(moduleId)) { return nativeMsa.get(moduleId); } @@ -382,9 +407,9 @@ public class GlobalData { return msaMap; } - public synchronized static Map getNativeMsa(File msaFile) throws BuildException { + public synchronized static Map getNativeMsa(File msaFile) throws EdkException { if (!msaFile.exists()) { - throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!"); + throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] can't be found!"); } try { ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile); @@ -392,7 +417,7 @@ public class GlobalData { // Validate File if they accord with XML Schema // if ( !doc.validate()){ - throw new BuildException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!"); + throw new EdkException("Module Surface Area file [" + msaFile.getPath() + "] format is invalid!"); } // // parse MSA file @@ -410,20 +435,24 @@ public class GlobalData { msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true)); msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true)); return msaMap; - } - catch (Exception ex){ - throw new BuildException(ex.getMessage()); + } catch(IOException ex) { + EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; + } catch(XmlException ex) { + EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; } } - public static Map getFpdBuildOptions() { - Map map = new HashMap(); - map.put("BuildOptions", fpdBuildOptions); - return map; + public static Map getFpdBuildOptionsMap() { + return fpdBuildOptionsMap; } - public static void setFpdBuildOptions(XmlObject fpdBuildOptions) { + public static void setFpdBuildOptions(XmlObject fpdBuildOptions) throws EdkException { GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true); + fpdBuildOptionsMap.put("BuildOptions", GlobalData.fpdBuildOptions); } public static XmlObject getFpdDynamicPcds() { @@ -448,8 +477,7 @@ public class GlobalData { * The header file path is relative to workspace dir */ public static String[] getLibraryClassHeaderFiles( - PackageIdentification[] packages, String name) - throws BuildException { + PackageIdentification[] packages, String name) throws EdkException{ if (packages == null) { // throw Exception or not???? return new String[0]; @@ -467,7 +495,7 @@ public class GlobalData { // // If can't find library class declaration in every package // - throw new BuildException("Can not find library class [" + name + throw new EdkException("Can not find library class [" + name + "] declaration in any SPD package!"); } @@ -475,7 +503,7 @@ public class GlobalData { * The header file path is relative to workspace dir */ public static String getPackageHeaderFiles(PackageIdentification packages, - String moduleType) throws BuildException { + String moduleType) { if (packages == null) { return new String(""); } @@ -499,8 +527,7 @@ public class GlobalData { /** * return two values: {cName, GuidValue} */ - public static String[] getGuid(List packages, String name) - throws BuildException { + public static String[] getGuid(List packages, String name) { if (packages == null) { // throw Exception or not???? return new String[0]; @@ -524,7 +551,7 @@ public class GlobalData { * return two values: {cName, GuidValue} */ public static String[] getPpiGuid(List packages, - String name) throws BuildException { + String name) { if (packages == null) { return new String[0]; } @@ -540,14 +567,13 @@ public class GlobalData { } } return null; - } /** * return two values: {cName, GuidValue} */ public static String[] getProtocolGuid(List packages, - String name) throws BuildException { + String name) { if (packages == null) { return new String[0]; } @@ -566,7 +592,7 @@ public class GlobalData { } - public synchronized static PlatformIdentification getPlatformByName(String name) throws BuildException { + public synchronized static PlatformIdentification getPlatformByName(String name) throws EdkException { Iterator iter = platformList.iterator(); while(iter.hasNext()){ PlatformIdentification platformId = (PlatformIdentification)iter.next(); @@ -574,10 +600,10 @@ public class GlobalData { return platformId; } } - throw new BuildException("Can't find platform [" + name + "] in the current WORKSPACE database!"); + throw new EdkException("Can't find platform [" + name + "] in the current WORKSPACE database!"); } - public synchronized static PlatformIdentification getPlatform(String filename) throws BuildException { + public synchronized static PlatformIdentification getPlatform(String filename) throws EdkException { File file = new File(workspaceDir + File.separatorChar + filename); Iterator iter = platformList.iterator(); while(iter.hasNext()){ @@ -586,10 +612,10 @@ public class GlobalData { return platformId; } } - throw new BuildException("Can't find platform file [" + filename + "] in the current WORKSPACE database!"); + throw new EdkException("Can't find platform file [" + filename + "] in the current WORKSPACE database!"); } - public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws BuildException { + public synchronized static PackageIdentification refreshPackageIdentification(PackageIdentification packageId) throws EdkException { Iterator iter = packageList.iterator(); while(iter.hasNext()){ PackageIdentification packageItem = (PackageIdentification)iter.next(); @@ -599,15 +625,15 @@ public class GlobalData { return packageId; } } - throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " in the current workspace!"); + throw new EdkException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!"); } - public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws BuildException { + public synchronized static ModuleIdentification refreshModuleIdentification(ModuleIdentification moduleId) throws EdkException { PackageIdentification packageId = getPackageForModule(moduleId); moduleId.setPackage(packageId); Spd spd = spdTable.get(packageId); if (spd == null) { - throw new BuildException("Can't find package GUID value " + packageId.getGuid() + " in the current workspace!"); + throw new EdkException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!"); } Set modules = spd.getModules(); Iterator iter = modules.iterator(); @@ -620,7 +646,7 @@ public class GlobalData { return moduleId; } } - throw new BuildException("Can't find module GUID value " + moduleId.getGuid() + " in package, " + packageId + ", in the current workspace!"); + throw new EdkException("Can't find module GUID value " + moduleId.toGuidString() + " in " + packageId + " under the current workspace!"); } public synchronized static Set getPackageList(){ @@ -636,7 +662,7 @@ public class GlobalData { @return XmlObject after clone @throws BuildException parse original XmlObject error. **/ - private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws BuildException { + private static XmlObject cloneXmlObject(XmlObject object, boolean deep) throws EdkException { if ( object == null) { return null; } @@ -644,16 +670,18 @@ public class GlobalData { try { result = XmlObject.Factory.parse(object.getDomNode() .cloneNode(deep)); - } catch (Exception ex) { - throw new BuildException(ex.getMessage()); + } catch (XmlException ex) { + EdkException edkException = new EdkException(ex.getMessage()); + edkException.setStackTrace(ex.getStackTrace()); + throw edkException; } return result; } - ////// Tool Chain Related, try to refine and put some logic process to ToolChainFactory - + /// + /// Tool Chain Related, try to refine and put some logic process to ToolChainFactory + /// public static ToolChainInfo getToolChainInfo() { -// GlobalData.log.info(toolsDef.getConfigInfo() + "" + toolChainEnvInfo + toolChainPlatformInfo); if (toolChainInfo == null) { toolChainInfo = toolsDef.getConfigInfo().intersection(toolChainEnvInfo); if (toolChainPlatformInfo != null) { @@ -661,13 +689,12 @@ public class GlobalData { } toolChainInfo.addCommands(toolsDef.getConfigInfo().getCommands()); toolChainInfo.normalize(); - GlobalData.log.info(toolChainInfo + ""); + EdkLog.log("Init", EdkLog.EDK_ALWAYS, "Current build tool chain information summary: "); + EdkLog.log("Init", EdkLog.EDK_ALWAYS, toolChainInfo + ""); } return toolChainInfo; } - - public static void setPlatformToolChainFamilyOption(ToolChainMap map) { platformToolChainFamilyOption = map; }