Update GlobalData, SPD, SurfaceAreaQuery to using EdkException.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1485 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
wuyizhong 2006-09-06 09:37:36 +00:00
parent 91f560c1c9
commit 892b0e7a05
11 changed files with 176 additions and 163 deletions

View File

@ -111,6 +111,13 @@ public class FrameworkBuildTask extends Task{
private String type = "all"; private String type = "all";
public void execute() throws BuildException { public void execute() throws BuildException {
//
// set Logger
//
GenBuildLogger logger = new GenBuildLogger(getProject());
EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL"));
EdkLog.setLogger(logger);
try { try {
processFrameworkBuild(); processFrameworkBuild();
} catch (PcdAutogenException e) { } catch (PcdAutogenException e) {
@ -142,13 +149,6 @@ public class FrameworkBuildTask extends Task{
} }
private void processFrameworkBuild() throws EdkException, GenBuildException, AutoGenException, PcdAutogenException, PlatformPcdPreprocessBuildException { private void processFrameworkBuild() throws EdkException, GenBuildException, AutoGenException, PcdAutogenException, PlatformPcdPreprocessBuildException {
//
// set Logger
//
GenBuildLogger logger = new GenBuildLogger(getProject());
EdkLog.setLogLevel(getProject().getProperty("env.LOGLEVEL"));
EdkLog.setLogger(logger);
// //
// Seach build.xml -> .FPD -> .MSA file // Seach build.xml -> .FPD -> .MSA file
// //
@ -180,8 +180,10 @@ public class FrameworkBuildTask extends Task{
} }
} }
} }
} catch (IOException e) { } catch (IOException ex) {
throw new BuildException(e.getMessage()); BuildException buildException = new BuildException("Scanning current directory error. \n" + ex.getMessage());
buildException.setStackTrace(ex.getStackTrace());
throw buildException;
} }
// //
@ -426,7 +428,7 @@ public class FrameworkBuildTask extends Task{
if (threadNum > 0) { if (threadNum > 0) {
MAX_CONCURRENT_THREAD_NUMBER = threadNum; MAX_CONCURRENT_THREAD_NUMBER = threadNum;
} }
} catch (Exception enuma) { } catch (Exception ex) {
} }
} }
} }

View File

@ -37,6 +37,10 @@ import org.tianocore.common.definitions.ToolDefinitions;
import org.tianocore.common.exception.EdkException; import org.tianocore.common.exception.EdkException;
import org.tianocore.common.logger.EdkLog; import org.tianocore.common.logger.EdkLog;
import org.tianocore.build.autogen.AutoGen; import org.tianocore.build.autogen.AutoGen;
import org.tianocore.build.exception.AutoGenException;
import org.tianocore.build.exception.GenBuildException;
import org.tianocore.build.exception.PcdAutogenException;
import org.tianocore.build.exception.PlatformPcdPreprocessBuildException;
import org.tianocore.build.fpd.FpdParserTask; import org.tianocore.build.fpd.FpdParserTask;
import org.tianocore.build.global.GlobalData; import org.tianocore.build.global.GlobalData;
import org.tianocore.build.global.OutputManager; import org.tianocore.build.global.OutputManager;
@ -126,6 +130,37 @@ public class GenBuildTask extends Ant {
From module build, exception from module surface area invalid. From module build, exception from module surface area invalid.
**/ **/
public void execute() throws BuildException { public void execute() throws BuildException {
try {
processGenBuild();
} catch (PcdAutogenException e) {
//
// Add more logic process here
//
throw new BuildException(e.getMessage());
} catch (AutoGenException e) {
//
// Add more logic process here
//
throw new BuildException(e.getMessage());
} catch (PlatformPcdPreprocessBuildException e) {
//
// Add more logic process here
//
throw new BuildException(e.getMessage());
} catch (GenBuildException e) {
//
// Add more logic process here
//
throw new BuildException(e.getMessage());
} catch (EdkException e) {
//
// Add more logic process here
//
throw new BuildException(e.getMessage());
}
}
private void processGenBuild() throws EdkException, BuildException, GenBuildException, AutoGenException, PcdAutogenException, PlatformPcdPreprocessBuildException {
if (!FrameworkBuildTask.multithread) { if (!FrameworkBuildTask.multithread) {
cleanupProperties(); cleanupProperties();
} }
@ -147,20 +182,26 @@ public class GenBuildTask extends Ant {
String moduleVersion = getProject().getProperty("MODULE_VERSION"); String moduleVersion = getProject().getProperty("MODULE_VERSION");
String packageGuid = getProject().getProperty("PACKAGE_GUID"); String packageGuid = getProject().getProperty("PACKAGE_GUID");
String packageVersion = getProject().getProperty("PACKAGE_VERSION"); String packageVersion = getProject().getProperty("PACKAGE_VERSION");
//
// If one of module Guid or package Guid is not specified, report error
//
if (moduleGuid == null || packageGuid == null) { if (moduleGuid == null || packageGuid == null) {
throw new BuildException("GenBuild parameter error."); throw new BuildException("GenBuild parameter error.");
} }
PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion); PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);
GlobalData.refreshPackageIdentification(packageId);
moduleId = new ModuleIdentification(moduleGuid, moduleVersion); moduleId = new ModuleIdentification(moduleGuid, moduleVersion);
moduleId.setPackage(packageId); moduleId.setPackage(packageId);
GlobalData.refreshModuleIdentification(moduleId);
Map<String, XmlObject> doc = GlobalData.getNativeMsa(moduleId); Map<String, XmlObject> doc = GlobalData.getNativeMsa(moduleId);
saq = new SurfaceAreaQuery(doc); saq = new SurfaceAreaQuery(doc);
moduleId = saq.getMsaHeader();
} else { } else {
Map<String, XmlObject> doc = GlobalData.getNativeMsa(msaFile); Map<String, XmlObject> doc = GlobalData.getNativeMsa(msaFile);
saq = new SurfaceAreaQuery(doc); saq = new SurfaceAreaQuery(doc);
moduleId = saq.getMsaHeader(); moduleId = saq.getMsaHeader();
} }
String[] producedLibraryClasses = saq.getLibraryClasses("ALWAYS_PRODUCED",null); String[] producedLibraryClasses = saq.getLibraryClasses("ALWAYS_PRODUCED",null);
if (producedLibraryClasses.length == 0) { if (producedLibraryClasses.length == 0) {
moduleId.setLibrary(false); moduleId.setLibrary(false);
@ -176,11 +217,6 @@ public class GenBuildTask extends Ant {
// Single Module build // Single Module build
// //
prepareSingleModuleBuild(); prepareSingleModuleBuild();
} else {
String packageGuid = getProject().getProperty("PACKAGE_GUID");
String packageVersion = getProject().getProperty("PACKAGE_VERSION");
PackageIdentification packageId = new PackageIdentification(packageGuid, packageVersion);
moduleId.setPackage(packageId);
} }
// //
@ -307,14 +343,15 @@ public class GenBuildTask extends Ant {
Database must be unique. </p> Database must be unique. </p>
**/ **/
private void prepareSingleModuleBuild(){ private void prepareSingleModuleBuild() throws EdkException {
// //
// Find out the package which the module belongs to // Find out the package which the module belongs to
// TBD: Enhance it!!!! // TBD: Enhance it!!!!
// //
PackageIdentification packageId = GlobalData.getPackageForModule(moduleId); PackageIdentification packageId = GlobalData.getPackageForModule(moduleId);
GlobalData.refreshPackageIdentification(packageId);
moduleId.setPackage(packageId); moduleId.setPackage(packageId);
GlobalData.refreshModuleIdentification(moduleId);
// //
// Read ACTIVE_PLATFORM's FPD file // Read ACTIVE_PLATFORM's FPD file
@ -540,7 +577,7 @@ public class GenBuildTask extends Ant {
this.type = type; this.type = type;
} }
private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws BuildException{ private void applyBuild(String buildTarget, String buildTagname, FpdModuleIdentification fpdModuleId) throws EdkException {
// //
// Call AutoGen to generate AutoGen.c and AutoGen.h // Call AutoGen to generate AutoGen.c and AutoGen.h
// //
@ -701,7 +738,7 @@ public class GenBuildTask extends Ant {
this.isSingleModuleBuild = isSingleModuleBuild; this.isSingleModuleBuild = isSingleModuleBuild;
} }
private String[] prepareIncludePaths(FpdModuleIdentification fpdModuleId) { private String[] prepareIncludePaths(FpdModuleIdentification fpdModuleId) throws EdkException{
// //
// Prepare the includes: PackageDependencies and Output debug direactory // Prepare the includes: PackageDependencies and Output debug direactory
// //

View File

@ -213,5 +213,4 @@ public class GenBuildThread implements Runnable {
public void setStatus(int status) { public void setStatus(int status) {
this.status = status; this.status = status;
} }
} }

View File

@ -34,6 +34,7 @@ import org.tianocore.build.global.SurfaceAreaQuery;
import org.tianocore.build.id.FpdModuleIdentification; import org.tianocore.build.id.FpdModuleIdentification;
import org.tianocore.build.id.ModuleIdentification; import org.tianocore.build.id.ModuleIdentification;
import org.tianocore.build.id.PackageIdentification; import org.tianocore.build.id.PackageIdentification;
import org.tianocore.common.exception.EdkException;
import org.w3c.dom.Comment; import org.w3c.dom.Comment;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.w3c.dom.Element; import org.w3c.dom.Element;
@ -296,7 +297,7 @@ public class ModuleBuildFileGenerator {
@param document current BaseName_build.xml XML document @param document current BaseName_build.xml XML document
@param root Root element for current @param root Root element for current
**/ **/
private void applyLibraryInstance(Document document, Node root) { private void applyLibraryInstance(Document document, Node root) throws EdkException {
ModuleIdentification[] libinstances = saq.getLibraryInstance(fpdModuleId.getArch()); ModuleIdentification[] libinstances = saq.getLibraryInstance(fpdModuleId.getArch());
for (int i = 0; i < libinstances.length; i++) { for (int i = 0; i < libinstances.length; i++) {
// //

View File

@ -42,6 +42,7 @@ import org.tianocore.build.id.PackageIdentification;
import org.tianocore.build.pcd.action.PCDAutoGenAction; import org.tianocore.build.pcd.action.PCDAutoGenAction;
import org.tianocore.common.logger.EdkLog; import org.tianocore.common.logger.EdkLog;
import org.tianocore.common.definitions.ToolDefinitions; import org.tianocore.common.definitions.ToolDefinitions;
import org.tianocore.common.exception.EdkException;
/** /**
This class is to generate Autogen.h and Autogen.c according to module surface This class is to generate Autogen.h and Autogen.c according to module surface
@ -280,7 +281,7 @@ public class AutoGen {
@throws BuildException @throws BuildException
Failed to generate AutoGen.h. Failed to generate AutoGen.h.
**/ **/
void moduleGenAutogenH() throws AutoGenException { void moduleGenAutogenH() throws EdkException, AutoGenException {
Set<String> libClassIncludeH; Set<String> libClassIncludeH;
String moduleType; String moduleType;
@ -406,7 +407,7 @@ public class AutoGen {
@throws BuildException @throws BuildException
Failed to generate AutoGen.c. Failed to generate AutoGen.c.
**/ **/
void moduleGenAutogenC() throws AutoGenException { void moduleGenAutogenC() throws EdkException, AutoGenException {
StringBuffer fileBuffer = new StringBuffer(8192); StringBuffer fileBuffer = new StringBuffer(8192);
// //
@ -535,7 +536,7 @@ public class AutoGen {
@throws BuildException @throws BuildException
Failed to generate AutoGen.c. Failed to generate AutoGen.c.
**/ **/
void libGenAutogenH() throws AutoGenException { void libGenAutogenH() throws EdkException, AutoGenException {
Set<String> libClassIncludeH; Set<String> libClassIncludeH;
String moduleType; String moduleType;
@ -699,7 +700,7 @@ public class AutoGen {
@return includeStrList List of *.h file. @return includeStrList List of *.h file.
**/ **/
Set<String> LibraryClassToAutogenH(String[] libClassList) Set<String> LibraryClassToAutogenH(String[] libClassList)
throws AutoGenException { throws EdkException, AutoGenException {
Set<String> includeStrList = new LinkedHashSet<String>(); Set<String> includeStrList = new LinkedHashSet<String>();
String includeName[]; String includeName[];
String str = ""; String str = "";
@ -1904,7 +1905,7 @@ public class AutoGen {
@param @param
@return @return
**/ **/
private void collectLibInstanceInfo(){ private void collectLibInstanceInfo() throws EdkException{
int index; int index;
String libConstructName = null; String libConstructName = null;

View File

@ -64,18 +64,10 @@ import org.tianocore.build.toolchain.ToolChainMap;
<p>The method parseFpdFile is also prepared for single module build. </p> <p>The method parseFpdFile is also prepared for single module build. </p>
<p>The usage is (take NT32 Platform for example):</p>
<pre>
&lt;FPDParser platformName="Nt32" /&gt;
</pre>
@since GenBuild 1.0 @since GenBuild 1.0
**/ **/
public class FpdParserTask extends Task { public class FpdParserTask extends Task {
private String platformName;
private File fpdFile = null; private File fpdFile = null;
PlatformIdentification platformId; PlatformIdentification platformId;
@ -123,18 +115,6 @@ public class FpdParserTask extends Task {
Surface area is not valid. Surface area is not valid.
**/ **/
public void execute() throws BuildException { public void execute() throws BuildException {
//
// If fpdFile is not specified,
// then try to get FPD file by platformName
//
if ( fpdFile == null) {
if (platformName == null) {
throw new BuildException("FpdParserTask parameter error. Please specify either the platform name or FPD file!");
}
platformId = GlobalData.getPlatformByName(platformName);
fpdFile = platformId.getFpdFile();
}
// //
// Parse FPD file // Parse FPD file
// //
@ -178,7 +158,6 @@ public class FpdParserTask extends Task {
// //
// Ant call ${PLATFORM}_build.xml // Ant call ${PLATFORM}_build.xml
// //
Ant ant = new Ant(); Ant ant = new Ant();
ant.setProject(getProject()); ant.setProject(getProject());
ant.setAntfile(platformId.getFpdFile().getParent() + File.separatorChar + platformId.getName() + "_build.xml"); ant.setAntfile(platformId.getFpdFile().getParent() + File.separatorChar + platformId.getName() + "_build.xml");
@ -554,10 +533,6 @@ public class FpdParserTask extends Task {
properties.addElement(p); properties.addElement(p);
} }
public void setPlatformName(String platformName) {
this.platformName = platformName;
}
public void setFpdFile(File fpdFile) { public void setFpdFile(File fpdFile) {
this.fpdFile = fpdFile; this.fpdFile = fpdFile;
} }

View File

@ -17,6 +17,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
package org.tianocore.build.global; package org.tianocore.build.global;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
@ -24,7 +25,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.tools.ant.BuildException; import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlObject;
import org.tianocore.common.exception.EdkException; import org.tianocore.common.exception.EdkException;
@ -139,7 +140,7 @@ public class GlobalData {
@throws BuildException @throws BuildException
Framework Dababase or SPD or MSA file is not valid 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 // ensure this method will be revoked only once
// //
@ -161,12 +162,9 @@ public class GlobalData {
// CONF dir + tools definition file name // CONF dir + tools definition file name
// //
File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename); File toolsDefFile = new File(workspaceDir + File.separatorChar + toolsDefFilename);
EdkLog.log("Init", "Using tool definiton file [" + toolsDefFile.getPath() + "]."); EdkLog.log("Init", "Using tool definition file [" + toolsDefFile.getPath() + "].");
try { toolsDef = new ToolChainConfig(toolsDefFile);
toolsDef = new ToolChainConfig(toolsDefFile);
} catch (Exception e) {
throw new BuildException(e.getMessage());
}
// //
// Parse Framework Database // Parse Framework Database
@ -178,7 +176,7 @@ public class GlobalData {
// validate FrameworkDatabaseFile // validate FrameworkDatabaseFile
// //
if (!db.validate()) { 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 // Get package list
@ -190,6 +188,15 @@ public class GlobalData {
String fileName = iter.next().getStringValue().trim(); String fileName = iter.next().getStringValue().trim();
Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName)); Spd spd = new Spd(new File(workspaceDir + File.separatorChar + fileName));
packageList.add(spd.getPackageId()); 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); spdTable.put(spd.getPackageId(), spd);
} }
} }
@ -204,31 +211,43 @@ public class GlobalData {
String fileName = iter.next().getStringValue().trim(); String fileName = iter.next().getStringValue().trim();
File fpdFile = new File(workspaceDir + File.separatorChar + fileName); File fpdFile = new File(workspaceDir + File.separatorChar + fileName);
if ( !fpdFile.exists() ) { 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); XmlObject fpdDoc = XmlObject.Factory.parse(fpdFile);
// //
// Verify FPD file, if is invalid, throw Exception // Verify FPD file, if is invalid, throw Exception
// //
if (!fpdDoc.validate()) { 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 // We can change Map to XmlObject
// //
//
// TBD check SPD or FPD is existed in FS
//
Map<String, XmlObject> fpdDocMap = new HashMap<String, XmlObject>(); Map<String, XmlObject> fpdDocMap = new HashMap<String, XmlObject>();
fpdDocMap.put("PlatformSurfaceArea", fpdDoc); fpdDocMap.put("PlatformSurfaceArea", fpdDoc);
SurfaceAreaQuery saq = new SurfaceAreaQuery(fpdDocMap); SurfaceAreaQuery saq = new SurfaceAreaQuery(fpdDocMap);
PlatformIdentification platformId = saq.getFpdHeader(); PlatformIdentification platformId = saq.getFpdHeader();
platformId.setFpdFile(fpdFile); 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); platformList.add(platformId);
} }
} }
} catch (Exception e) { } catch(IOException ex) {
throw new BuildException("Parse WORKSPACE Database file [" + dbFile.getPath() + "] Error.\n" + e.getMessage()); 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;
} }
} }
@ -245,7 +264,7 @@ public class GlobalData {
/** /**
Get the MSA file name with absolute path 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; File msaFile = null;
// //
// TBD. Do only when package is null. // TBD. Do only when package is null.
@ -260,13 +279,13 @@ public class GlobalData {
} }
} }
if (msaFile == null){ 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 { } else {
return msaFile; return msaFile;
} }
} }
public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) { public synchronized static PackageIdentification getPackageForModule(ModuleIdentification moduleId) throws EdkException {
// //
// If package already defined in module // If package already defined in module
// //
@ -285,7 +304,7 @@ public class GlobalData {
} }
} }
if (packageId == 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 { } else {
return packageId; return packageId;
} }
@ -303,7 +322,7 @@ public class GlobalData {
} }
public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) { public synchronized static void registerFpdModuleSA(FpdModuleIdentification fpdModuleId, Map<String, XmlObject> doc) throws EdkException{
Map<String, XmlObject> result = new HashMap<String, XmlObject>(); Map<String, XmlObject> result = new HashMap<String, XmlObject>();
Set keySet = doc.keySet(); Set keySet = doc.keySet();
Iterator iter = keySet.iterator(); Iterator iter = keySet.iterator();
@ -329,7 +348,7 @@ public class GlobalData {
@return ModuleSA info and MSA info for fpdModuleId @return ModuleSA info and MSA info for fpdModuleId
@throws BuildException Can't find MSA @throws BuildException Can't find MSA
**/ **/
public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws BuildException { public synchronized static Map<String, XmlObject> getDoc(FpdModuleIdentification fpdModuleId) throws EdkException{
if (parsedModules.containsKey(fpdModuleId)) { if (parsedModules.containsKey(fpdModuleId)) {
return parsedModules.get(fpdModuleId); return parsedModules.get(fpdModuleId);
} }
@ -359,10 +378,11 @@ public class GlobalData {
return doc; return doc;
} }
public synchronized static Map<String, XmlObject> getDoc(ModuleIdentification moduleId, String arch) throws BuildException { public synchronized static Map<String, XmlObject> getDoc(ModuleIdentification moduleId, String arch) throws EdkException{
FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch); FpdModuleIdentification fpdModuleId = new FpdModuleIdentification(moduleId, arch);
return getDoc(fpdModuleId); return getDoc(fpdModuleId);
} }
/** /**
Query the native MSA information with module base name. Query the native MSA information with module base name.
@ -374,7 +394,7 @@ public class GlobalData {
@throws BuildException @throws BuildException
MSA file is not valid MSA file is not valid
**/ **/
public synchronized static Map<String, XmlObject> getNativeMsa(ModuleIdentification moduleId) throws BuildException { public synchronized static Map<String, XmlObject> getNativeMsa(ModuleIdentification moduleId) throws EdkException {
if (nativeMsa.containsKey(moduleId)) { if (nativeMsa.containsKey(moduleId)) {
return nativeMsa.get(moduleId); return nativeMsa.get(moduleId);
} }
@ -384,9 +404,9 @@ public class GlobalData {
return msaMap; return msaMap;
} }
public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws BuildException { public synchronized static Map<String, XmlObject> getNativeMsa(File msaFile) throws EdkException {
if (!msaFile.exists()) { 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 { try {
ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile); ModuleSurfaceAreaDocument doc = (ModuleSurfaceAreaDocument)XmlObject.Factory.parse(msaFile);
@ -394,7 +414,7 @@ public class GlobalData {
// Validate File if they accord with XML Schema // Validate File if they accord with XML Schema
// //
if ( !doc.validate()){ 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 // parse MSA file
@ -412,9 +432,14 @@ public class GlobalData {
msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true)); msaMap.put("Externs", cloneXmlObject(msa.getExterns(), true));
msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true)); msaMap.put("PcdCoded", cloneXmlObject(msa.getPcdCoded(), true));
return msaMap; return msaMap;
} } catch(IOException ex) {
catch (Exception ex){ EdkException edkException = new EdkException("Parsing MSA file [" + msaFile.getPath() + "] error. \n" + ex.getMessage());
throw new BuildException("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;
} }
} }
@ -422,7 +447,7 @@ public class GlobalData {
return fpdBuildOptionsMap; return fpdBuildOptionsMap;
} }
public static void setFpdBuildOptions(XmlObject fpdBuildOptions) { public static void setFpdBuildOptions(XmlObject fpdBuildOptions) throws EdkException {
GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true); GlobalData.fpdBuildOptions = cloneXmlObject(fpdBuildOptions, true);
fpdBuildOptionsMap.put("BuildOptions", GlobalData.fpdBuildOptions); fpdBuildOptionsMap.put("BuildOptions", GlobalData.fpdBuildOptions);
} }
@ -449,8 +474,7 @@ public class GlobalData {
* The header file path is relative to workspace dir * The header file path is relative to workspace dir
*/ */
public static String[] getLibraryClassHeaderFiles( public static String[] getLibraryClassHeaderFiles(
PackageIdentification[] packages, String name) PackageIdentification[] packages, String name) throws EdkException{
throws BuildException {
if (packages == null) { if (packages == null) {
// throw Exception or not???? // throw Exception or not????
return new String[0]; return new String[0];
@ -468,7 +492,7 @@ public class GlobalData {
// //
// If can't find library class declaration in every package // 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!"); + "] declaration in any SPD package!");
} }
@ -476,7 +500,7 @@ public class GlobalData {
* The header file path is relative to workspace dir * The header file path is relative to workspace dir
*/ */
public static String getPackageHeaderFiles(PackageIdentification packages, public static String getPackageHeaderFiles(PackageIdentification packages,
String moduleType) throws BuildException { String moduleType) {
if (packages == null) { if (packages == null) {
return new String(""); return new String("");
} }
@ -500,8 +524,7 @@ public class GlobalData {
/** /**
* return two values: {cName, GuidValue} * return two values: {cName, GuidValue}
*/ */
public static String[] getGuid(List<PackageIdentification> packages, String name) public static String[] getGuid(List<PackageIdentification> packages, String name) {
throws BuildException {
if (packages == null) { if (packages == null) {
// throw Exception or not???? // throw Exception or not????
return new String[0]; return new String[0];
@ -525,7 +548,7 @@ public class GlobalData {
* return two values: {cName, GuidValue} * return two values: {cName, GuidValue}
*/ */
public static String[] getPpiGuid(List<PackageIdentification> packages, public static String[] getPpiGuid(List<PackageIdentification> packages,
String name) throws BuildException { String name) {
if (packages == null) { if (packages == null) {
return new String[0]; return new String[0];
} }
@ -547,7 +570,7 @@ public class GlobalData {
* return two values: {cName, GuidValue} * return two values: {cName, GuidValue}
*/ */
public static String[] getProtocolGuid(List<PackageIdentification> packages, public static String[] getProtocolGuid(List<PackageIdentification> packages,
String name) throws BuildException { String name) {
if (packages == null) { if (packages == null) {
return new String[0]; return new String[0];
} }
@ -566,7 +589,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(); Iterator iter = platformList.iterator();
while(iter.hasNext()){ while(iter.hasNext()){
PlatformIdentification platformId = (PlatformIdentification)iter.next(); PlatformIdentification platformId = (PlatformIdentification)iter.next();
@ -574,10 +597,10 @@ public class GlobalData {
return platformId; 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); File file = new File(workspaceDir + File.separatorChar + filename);
Iterator iter = platformList.iterator(); Iterator iter = platformList.iterator();
while(iter.hasNext()){ while(iter.hasNext()){
@ -586,10 +609,10 @@ public class GlobalData {
return platformId; 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(); Iterator iter = packageList.iterator();
while(iter.hasNext()){ while(iter.hasNext()){
PackageIdentification packageItem = (PackageIdentification)iter.next(); PackageIdentification packageItem = (PackageIdentification)iter.next();
@ -599,15 +622,15 @@ public class GlobalData {
return packageId; return packageId;
} }
} }
throw new BuildException("Can't find package GUID value " + packageId.toGuidString() + " 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); PackageIdentification packageId = getPackageForModule(moduleId);
moduleId.setPackage(packageId); moduleId.setPackage(packageId);
Spd spd = spdTable.get(packageId); Spd spd = spdTable.get(packageId);
if (spd == null) { if (spd == null) {
throw new BuildException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!"); throw new EdkException("Can't find package GUID value " + packageId.toGuidString() + " in the current workspace!");
} }
Set<ModuleIdentification> modules = spd.getModules(); Set<ModuleIdentification> modules = spd.getModules();
Iterator<ModuleIdentification> iter = modules.iterator(); Iterator<ModuleIdentification> iter = modules.iterator();
@ -620,7 +643,7 @@ public class GlobalData {
return moduleId; return moduleId;
} }
} }
throw new BuildException("Can't find module GUID value " + moduleId.toGuidString() + " in " + packageId + " under the current workspace!"); throw new EdkException("Can't find module GUID value " + moduleId.toGuidString() + " in " + packageId + " under the current workspace!");
} }
public synchronized static Set<PackageIdentification> getPackageList(){ public synchronized static Set<PackageIdentification> getPackageList(){
@ -636,7 +659,7 @@ public class GlobalData {
@return XmlObject after clone @return XmlObject after clone
@throws BuildException parse original XmlObject error. @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) { if ( object == null) {
return null; return null;
} }
@ -644,8 +667,10 @@ public class GlobalData {
try { try {
result = XmlObject.Factory.parse(object.getDomNode() result = XmlObject.Factory.parse(object.getDomNode()
.cloneNode(deep)); .cloneNode(deep));
} catch (Exception ex) { } catch (XmlException ex) {
throw new BuildException(ex.getMessage()); EdkException edkException = new EdkException(ex.getMessage());
edkException.setStackTrace(ex.getStackTrace());
throw edkException;
} }
return result; return result;
} }

View File

@ -16,21 +16,23 @@
package org.tianocore.build.global; package org.tianocore.build.global;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.apache.tools.ant.BuildException; import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlObject;
import org.tianocore.build.id.ModuleIdentification; import org.tianocore.build.id.ModuleIdentification;
import org.tianocore.build.id.PackageIdentification; 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 { public class Spd {
/// ///
/// ///
@ -88,12 +90,12 @@ public class Spd {
This function mainly initialize some member variables. This function mainly initialize some member variables.
**/ **/
Spd(File packageFile) throws BuildException { Spd(File packageFile) throws EdkException {
// //
// If specified package file not exists // If specified package file not exists
// //
if ( ! packageFile.exists()) { if ( ! packageFile.exists()) {
throw new BuildException("Package file [" + packageFile.getPath() + "] does not exist!"); throw new EdkException("Package file [" + packageFile.getPath() + "] does not exist!");
} }
try { try {
XmlObject spdDoc = XmlObject.Factory.parse(packageFile); XmlObject spdDoc = XmlObject.Factory.parse(packageFile);
@ -101,15 +103,15 @@ public class Spd {
// Verify SPD file, if is invalid, throw Exception // Verify SPD file, if is invalid, throw Exception
// //
if (! spdDoc.validate()) { if (! spdDoc.validate()) {
throw new BuildException("Package Surface Area file [" + packageFile.getPath() + "] format is invalid!"); throw new EdkException("Package Surface Area file [" + packageFile.getPath() + "] format is invalid!");
} }
//
// We can change Map to XmlObject // We can change Map to XmlObject
//
Map<String, XmlObject> spdDocMap = new HashMap<String, XmlObject>(); Map<String, XmlObject> spdDocMap = new HashMap<String, XmlObject>();
spdDocMap.put("PackageSurfaceArea", spdDoc); spdDocMap.put("PackageSurfaceArea", spdDoc);
SurfaceAreaQuery saq = new SurfaceAreaQuery(spdDocMap); SurfaceAreaQuery saq = new SurfaceAreaQuery(spdDocMap);
//
//
//
packageId = saq.getSpdHeader(); packageId = saq.getSpdHeader();
packageId.setSpdFile(packageFile); packageId.setSpdFile(packageFile);
@ -127,7 +129,7 @@ public class Spd {
moduleId.setPackage(packageId); moduleId.setPackage(packageId);
moduleId.setMsaFile(msaFile); moduleId.setMsaFile(msaFile);
if (msaInfo.containsKey(moduleId)) { if (msaInfo.containsKey(moduleId)) {
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 + "]!"); 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); msaInfo.put(moduleId, msaFile);
} }
@ -196,10 +198,14 @@ public class Spd {
} }
libClassHeaderList.put(libraryClassName, headerFiles); libClassHeaderList.put(libraryClassName, headerFiles);
} }
} } catch (IOException ex) {
catch (Exception e) { EdkException edkException = new EdkException("Parse of the package description file [" + packageFile.getPath() + "] failed!\n" + ex.getMessage());
throw new BuildException("Parse of the package description file [" + packageFile.getPath() + "] failed!\n" edkException.setStackTrace(ex.getStackTrace());
+ e.getMessage()); 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;
} }
} }

View File

@ -62,6 +62,7 @@ import org.tianocore.ProtocolsDocument.Protocols.Protocol;
import org.tianocore.ProtocolsDocument.Protocols.ProtocolNotify; import org.tianocore.ProtocolsDocument.Protocols.ProtocolNotify;
import org.tianocore.PcdDriverTypes; import org.tianocore.PcdDriverTypes;
import org.tianocore.common.exception.EdkException;
import org.tianocore.common.logger.EdkLog; import org.tianocore.common.logger.EdkLog;
import org.tianocore.build.id.FpdModuleIdentification; import org.tianocore.build.id.FpdModuleIdentification;
import org.tianocore.build.id.ModuleIdentification; import org.tianocore.build.id.ModuleIdentification;
@ -556,7 +557,7 @@ public class SurfaceAreaQuery {
* @returns package name list if elements are found at the known xpath * @returns package name list if elements are found at the known xpath
* @returns null if nothing is there * @returns null if nothing is there
*/ */
public PackageIdentification[] getDependencePkg(String arch) { public PackageIdentification[] getDependencePkg(String arch) throws EdkException {
String[] xPath; String[] xPath;
String packageGuid = null; String packageGuid = null;
String packageVersion = null; String packageVersion = null;
@ -579,19 +580,13 @@ public class SurfaceAreaQuery {
if (arch == null || archList == null || contains(archList, arch)) { if (arch == null || archList == null || contains(archList, arch)) {
packageGuid = item.getPackageGuid(); packageGuid = item.getPackageGuid();
packageVersion = item.getPackageVersion(); packageVersion = item.getPackageVersion();
packageIdList.add(new PackageIdentification(null, packageGuid, PackageIdentification pkgId = new PackageIdentification(null, packageGuid, packageVersion);
packageVersion)); GlobalData.refreshPackageIdentification(pkgId);
packageIdList.add(pkgId);
} }
} }
// return packageIdList.toArray(new PackageIdentification[packageIdList.size()]);
// transfer packageIdentification list to array.
//
PackageIdentification[] packageIdArray = new PackageIdentification[packageIdList.size()];
for (int i = 0; i < packageIdList.size(); i++) {
packageIdArray[i] = new PackageIdentification(null, packageIdList.get(i).getGuid(),packageIdList.get(i).getVersion());
}
return packageIdArray;
} }
/** /**
@ -1107,7 +1102,7 @@ public class SurfaceAreaQuery {
* xpath * xpath
* @returns null if nothing is there * @returns null if nothing is there
*/ */
public ModuleIdentification[] getLibraryInstance(String arch) { public ModuleIdentification[] getLibraryInstance(String arch) throws EdkException {
String[] xPath; String[] xPath;
String saGuid = null; String saGuid = null;
String saVersion = null; String saVersion = null;
@ -1144,7 +1139,9 @@ public class SurfaceAreaQuery {
saVersion); saVersion);
PackageIdentification pkgId = new PackageIdentification(null, PackageIdentification pkgId = new PackageIdentification(null,
pkgGuid, pkgVersion); pkgGuid, pkgVersion);
GlobalData.refreshPackageIdentification(pkgId);
saId.setPackage(pkgId); saId.setPackage(pkgId);
GlobalData.refreshModuleIdentification(saId);
saIdList[i] = saId; saIdList[i] = saId;
@ -1308,7 +1305,7 @@ public class SurfaceAreaQuery {
* @returns ModuleSA objects list if elements are found at the known xpath * @returns ModuleSA objects list if elements are found at the known xpath
* @returns Empty ModuleSA list if nothing is there * @returns Empty ModuleSA list if nothing is there
*/ */
public Map<FpdModuleIdentification, Map<String, XmlObject>> getFpdModules() { public Map<FpdModuleIdentification, Map<String, XmlObject>> getFpdModules() throws EdkException {
String[] xPath = new String[] { "/FrameworkModules/ModuleSA" }; String[] xPath = new String[] { "/FrameworkModules/ModuleSA" };
Object[] result = get("PlatformSurfaceArea", xPath); Object[] result = get("PlatformSurfaceArea", xPath);
String arch = null; String arch = null;
@ -1362,7 +1359,9 @@ public class SurfaceAreaQuery {
// identification. // identification.
// //
PackageIdentification pkgId = new PackageIdentification(null, pkgGuid, pkgVersion); PackageIdentification pkgId = new PackageIdentification(null, pkgGuid, pkgVersion);
GlobalData.refreshPackageIdentification(pkgId);
ModuleIdentification saId = new ModuleIdentification(null, saGuid, saVersion); ModuleIdentification saId = new ModuleIdentification(null, saGuid, saVersion);
GlobalData.refreshModuleIdentification(saId);
saId.setPackage(pkgId); saId.setPackage(pkgId);

View File

@ -15,7 +15,6 @@ package org.tianocore.build.id;
import java.io.File; import java.io.File;
import org.tianocore.build.global.GlobalData;
/** /**
This class is used to identify a module with Module Guid, Module Version, This class is used to identify a module with Module Guid, Module Version,
Package Guid, Package Version. Package Guid, Package Version.
@ -88,7 +87,6 @@ public class ModuleIdentification extends Identification {
@return MSA File @return MSA File
**/ **/
public File getMsaFile() { public File getMsaFile() {
prepareMsaFile();
return msaFile; return msaFile;
} }
@ -96,19 +94,12 @@ public class ModuleIdentification extends Identification {
@return Module relative path to package @return Module relative path to package
**/ **/
public String getModuleRelativePath() { public String getModuleRelativePath() {
prepareMsaFile();
if (msaFile.getParent().length() == packageId.getPackageDir().length()) { if (msaFile.getParent().length() == packageId.getPackageDir().length()) {
return "."; return ".";
} }
return msaFile.getParent().substring(packageId.getPackageDir().length() + 1); return msaFile.getParent().substring(packageId.getPackageDir().length() + 1);
} }
private void prepareMsaFile(){
if (msaFile == null) {
GlobalData.refreshModuleIdentification(this);
}
}
/** /**
@param msaFile Set Msa File @param msaFile Set Msa File
**/ **/
@ -137,10 +128,7 @@ public class ModuleIdentification extends Identification {
} }
} }
public String toString(){ public String toString() {
if (name == null) {
GlobalData.refreshModuleIdentification(this);
}
if (version == null || version.trim().equalsIgnoreCase("")) { if (version == null || version.trim().equalsIgnoreCase("")) {
return "Module [" + name + "] in " + packageId; return "Module [" + name + "] in " + packageId;
} }
@ -167,9 +155,6 @@ public class ModuleIdentification extends Identification {
@return get module type @return get module type
**/ **/
public String getModuleType() { public String getModuleType() {
if (moduleType == null) {
GlobalData.refreshModuleIdentification(this);
}
return moduleType; return moduleType;
} }
@ -181,9 +166,6 @@ public class ModuleIdentification extends Identification {
} }
public String getName() { public String getName() {
if (name == null) {
GlobalData.refreshModuleIdentification(this);
}
return name; return name;
} }
} }

View File

@ -84,9 +84,6 @@ public class PackageIdentification extends Identification{
} }
public String toString(){ public String toString(){
if (name == null) {
GlobalData.refreshPackageIdentification(this);
}
if (version == null || version.trim().equalsIgnoreCase("")) { if (version == null || version.trim().equalsIgnoreCase("")) {
return "package [" + name + "]"; return "package [" + name + "]";
} }
@ -100,7 +97,6 @@ public class PackageIdentification extends Identification{
@return Package Directory @return Package Directory
**/ **/
public String getPackageDir(){ public String getPackageDir(){
prepareSpdFile();
return spdFile.getParent(); return spdFile.getParent();
} }
@ -109,7 +105,6 @@ public class PackageIdentification extends Identification{
@return package relative directory @return package relative directory
**/ **/
public String getPackageRelativeDir(){ public String getPackageRelativeDir(){
prepareSpdFile();
String relativeDir =spdFile.getParent().substring(GlobalData.getWorkspacePath().length()); String relativeDir =spdFile.getParent().substring(GlobalData.getWorkspacePath().length());
if(relativeDir.startsWith("\\") || relativeDir.startsWith("/")) { if(relativeDir.startsWith("\\") || relativeDir.startsWith("/")) {
relativeDir = relativeDir.substring(1); relativeDir = relativeDir.substring(1);
@ -117,16 +112,7 @@ public class PackageIdentification extends Identification{
return relativeDir; return relativeDir;
} }
private void prepareSpdFile(){
if (spdFile == null) {
GlobalData.refreshPackageIdentification(this);
}
}
public String getName() { public String getName() {
if (name == null) {
GlobalData.refreshPackageIdentification(this);
}
return name; return name;
} }
} }