From 61528a1be326a5a7ddd7cbcac16f91c4e62060b3 Mon Sep 17 00:00:00 2001 From: qouyang Date: Thu, 7 Sep 2006 08:02:44 +0000 Subject: [PATCH] Unify the logger and exception in AutoGen. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@1493 6f19259b-4bc3-4df7-8a09-765794883524 --- .../org/tianocore/build/autogen/AutoGen.java | 387 ++++++++---------- .../build/autogen/AutogenLibOrder.java | 10 +- .../build/exception/GenBuildException.java | 2 +- .../build/exception/PcdAutogenException.java | 2 +- .../PlatformPcdPreprocessBuildException.java | 2 +- .../build/exception/TianoToolsException.java | 2 +- .../build/exception/XmlParseException.java | 2 +- 7 files changed, 189 insertions(+), 218 deletions(-) diff --git a/Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java b/Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java index 117b6bfe17..cf83a871c5 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java +++ b/Tools/Source/GenBuild/org/tianocore/build/autogen/AutoGen.java @@ -208,29 +208,28 @@ public class AutoGen { @throws BuildException Failed to creat AutoGen.c & AutoGen.h. **/ - public void genAutogen() throws BuildException { + public void genAutogen() throws EdkException { try { // // If outputPath do not exist, create it. // File path = new File(outputPath); path.mkdirs(); - - // - // Check current is library or not, then call the corresponding - // function. - // - if (this.moduleId.isLibrary()) { - libGenAutogen(); - } else { - moduleGenAutogen(); - } - - } catch (Exception e) { - throw new BuildException( - "Failed to create AutoGen.c & AutoGen.h!\n" - + e.getMessage()); + } catch (Exception e) { + throw new AutoGenException( + "Failed to create " + + outputPath + " directory"); } + + // + // Check current is library or not, then call the corresponding + // function. + // + if (this.moduleId.isLibrary()) { + libGenAutogen(); + } else { + moduleGenAutogen(); + } } /** @@ -241,17 +240,10 @@ public class AutoGen { @throws BuildException Faile to create module AutoGen.c & AutoGen.h. **/ - void moduleGenAutogen() throws BuildException { - - try { - collectLibInstanceInfo(); - moduleGenAutogenC(); - moduleGenAutogenH(); - } catch (Exception e) { - throw new BuildException( - "Faile to create module AutoGen.c & AutoGen.h!\n" - + e.getMessage()); - } + void moduleGenAutogen() throws EdkException { + collectLibInstanceInfo(); + moduleGenAutogenC(); + moduleGenAutogenH(); } /** @@ -262,15 +254,9 @@ public class AutoGen { @throws BuildException Faile to create library AutoGen.c & AutoGen.h **/ - void libGenAutogen() throws BuildException { - try { - libGenAutogenC(); - libGenAutogenH(); - } catch (Exception e) { - throw new BuildException( - "Failed to create library AutoGen.c & AutoGen.h!\n" - + e.getMessage()); - } + void libGenAutogen() throws EdkException { + libGenAutogenC(); + libGenAutogenH(); } /** @@ -281,7 +267,7 @@ public class AutoGen { @throws BuildException Failed to generate AutoGen.h. **/ - void moduleGenAutogenH() throws EdkException, AutoGenException { + void moduleGenAutogenH() throws EdkException { Set libClassIncludeH; String moduleType; @@ -395,7 +381,7 @@ public class AutoGen { // Save string buffer content in AutoGen.h. // if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) { - throw new BuildException("Failed to generate AutoGen.h !!!"); + throw new AutoGenException("Failed to generate AutoGen.h !!!"); } } @@ -407,7 +393,7 @@ public class AutoGen { @throws BuildException Failed to generate AutoGen.c. **/ - void moduleGenAutogenC() throws EdkException, AutoGenException { + void moduleGenAutogenC() throws EdkException { StringBuffer fileBuffer = new StringBuffer(8192); // @@ -511,19 +497,15 @@ public class AutoGen { false, null, pcdDriverType); - try { - this.myPcdAutogen.execute(); - } catch (Exception exp) { - throw new PcdAutogenException (exp.getMessage()); - } - + + this.myPcdAutogen.execute(); if (this.myPcdAutogen != null) { fileBuffer.append("\r\n"); fileBuffer.append(this.myPcdAutogen.getCAutoGenString()); } if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) { - throw new BuildException("Failed to generate AutoGen.c !!!"); + throw new AutoGenException("Failed to generate AutoGen.c !!!"); } } @@ -536,7 +518,7 @@ public class AutoGen { @throws BuildException Failed to generate AutoGen.c. **/ - void libGenAutogenH() throws EdkException, AutoGenException { + void libGenAutogenH() throws EdkException { Set libClassIncludeH; String moduleType; @@ -641,7 +623,7 @@ public class AutoGen { // Save content of string buffer to AutoGen.h file. // if (!saveFile(outputPath + File.separatorChar + "AutoGen.h", fileBuffer)) { - throw new BuildException("Failed to generate AutoGen.h !!!"); + throw new AutoGenException("Failed to generate AutoGen.h !!!"); } } @@ -653,7 +635,7 @@ public class AutoGen { @throws BuildException Failed to generate AutoGen.c. **/ - void libGenAutogenC() throws BuildException, PcdAutogenException { + void libGenAutogenC() throws EdkException { StringBuffer fileBuffer = new StringBuffer(10240); // @@ -672,19 +654,14 @@ public class AutoGen { true, saq.getModulePcdEntryNameArray(), pcdDriverType); - try { - this.myPcdAutogen.execute(); - } catch (Exception e) { - throw new PcdAutogenException(e.getMessage()); - } - + this.myPcdAutogen.execute(); if (this.myPcdAutogen != null) { fileBuffer.append(ToolDefinitions.LINE_SEPARATOR); fileBuffer.append(this.myPcdAutogen.getCAutoGenString()); } if (!saveFile(outputPath + File.separatorChar + "AutoGen.c", fileBuffer)) { - throw new BuildException("Failed to generate AutoGen.c !!!"); + throw new AutoGenException("Failed to generate AutoGen.c !!!"); } } @@ -700,7 +677,7 @@ public class AutoGen { @return includeStrList List of *.h file. **/ Set LibraryClassToAutogenH(String[] libClassList) - throws EdkException, AutoGenException { + throws EdkException { Set includeStrList = new LinkedHashSet(); String includeName[]; String str = ""; @@ -781,7 +758,7 @@ public class AutoGen { @throws Exception **/ void EntryPointToAutoGen(String[] entryPointList, String[] unloadImageList, StringBuffer fileBuffer) - throws BuildException { + throws EdkException { String typeStr = saq.getModuleType(); int unloadImageCount = 0; @@ -795,7 +772,7 @@ public class AutoGen { case CommonDefinition.ModuleTypePeiCore: if (entryPointList == null ||entryPointList.length != 1 ) { - throw new BuildException( + throw new AutoGenException( "Module type = 'PEI_CORE', can have only one module entry point!"); } else { fileBuffer.append("EFI_STATUS\r\n"); @@ -827,7 +804,7 @@ public class AutoGen { case CommonDefinition.ModuleTypeDxeCore: fileBuffer.append("const UINT32 _gUefiDriverRevision = 0;\r\n"); if (entryPointList == null || entryPointList.length != 1) { - throw new BuildException( + throw new AutoGenException( "Module type = 'DXE_CORE', can have only one module entry point!"); } else { @@ -1294,7 +1271,7 @@ public class AutoGen { @throws BuildException Protocol name must set. **/ - void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws BuildException { + void ProtocolGuidToAutogenC(StringBuffer fileBuffer) throws EdkException { String[] cNameGuid = null; String[] protocolList = saq.getProtocolArray(this.arch); @@ -1334,7 +1311,7 @@ public class AutoGen { // // If can't find protocol GUID declaration in every package // - throw new BuildException("Can not find protocol Guid [" + throw new AutoGenException("Can not find protocol Guid [" + protocolKeyWord + "] declaration in any SPD package!"); } } @@ -1395,21 +1372,17 @@ public class AutoGen { String buffer for AutoGen.c @throws BuildException **/ - void LibInstanceToAutogenC(StringBuffer fileBuffer) throws BuildException { - try { - String moduleType = this.moduleId.getModuleType(); - // - // Add library constructor to AutoGen.c - // - LibConstructorToAutogenC(libConstructList, moduleType, - fileBuffer/* autogenC */); - // - // Add library destructor to AutoGen.c - // - LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */); - } catch (Exception e) { - throw new BuildException(e.getMessage()); - } + void LibInstanceToAutogenC(StringBuffer fileBuffer) throws EdkException { + String moduleType = this.moduleId.getModuleType(); + // + // Add library constructor to AutoGen.c + // + LibConstructorToAutogenC(libConstructList, moduleType, + fileBuffer/* autogenC */); + // + // Add library destructor to AutoGen.c + // + LibDestructorToAutogenC(libDestructList, moduleType, fileBuffer/* autogenC */); } /** @@ -1427,7 +1400,7 @@ public class AutoGen { @throws Exception **/ void LibConstructorToAutogenC(List libInstanceList, - String moduleType, StringBuffer fileBuffer) throws Exception { + String moduleType, StringBuffer fileBuffer) throws EdkException { boolean isFirst = true; // @@ -1568,7 +1541,7 @@ public class AutoGen { @throws Exception **/ void LibDestructorToAutogenC(List libInstanceList, - String moduleType, StringBuffer fileBuffer) throws Exception { + String moduleType, StringBuffer fileBuffer) throws EdkException { boolean isFirst = true; for (int i = 0; i < libInstanceList.size(); i++) { switch (CommonDefinition.getModuleType(moduleType)) { @@ -1663,7 +1636,7 @@ public class AutoGen { String buffer for AutoGen.c **/ void ExternsDriverBindingToAutoGenC(StringBuffer fileBuffer) - throws BuildException { + throws EdkException { // // Check what contains. And the number of following elements @@ -1702,7 +1675,7 @@ public class AutoGen { // if (compNamList != null && compNamList.length != 0) { if (drvBindList.length != compNamList.length) { - throw new BuildException( + throw new AutoGenException( "Different number of Driver Binding and Component Name protocols!"); } @@ -1719,7 +1692,7 @@ public class AutoGen { // if (compConfList != null && compConfList.length != 0) { if (drvBindList.length != compConfList.length) { - throw new BuildException( + throw new AutoGenException( "Different number of Driver Binding and Driver Configuration protocols!"); } @@ -1736,7 +1709,7 @@ public class AutoGen { // if (compDiagList != null && compDiagList.length != 0) { if (drvBindList.length != compDiagList.length) { - throw new BuildException( + throw new AutoGenException( "Different number of Driver Binding and Driver Diagnosis protocols!"); } @@ -1818,7 +1791,7 @@ public class AutoGen { @throws BuildException **/ void ExternCallBackToAutoGenC(StringBuffer fileBuffer) - throws BuildException { + throws EdkException { // // Collect module's and // and add to setVirtualAddList @@ -1879,20 +1852,21 @@ public class AutoGen { // do nothing. // if ((!outFile.exists()) ||(inFile.lastModified() - outFile.lastModified()) >= 0) { - try { - if (inFile.exists()) { - FileInputStream fis = new FileInputStream (inFile); - fis.read(buffer); - FileOutputStream fos = new FileOutputStream(outFile); - fos.write(buffer); - fis.close(); - fos.close(); - } else { - throw new AutoGenException("The file, flashMap.h doesn't exist!"); - } - } catch (Exception e) { - throw new AutoGenException(e.getMessage()); - } + if (inFile.exists()) { + try{ + FileInputStream fis = new FileInputStream (inFile); + fis.read(buffer); + FileOutputStream fos = new FileOutputStream(outFile); + fos.write(buffer); + fis.close(); + fos.close(); + } catch (IOException e){ + throw new AutoGenException("The file, flashMap.h can't be open!"); + } + + } else { + throw new AutoGenException("The file, flashMap.h doesn't exist!"); + } } } @@ -1914,119 +1888,114 @@ public class AutoGen { String[] exitBoots = null; ModuleIdentification[] libraryIdList = saq.getLibraryInstance(this.arch); - try { - if (libraryIdList != null) { - // - // Reorder library instance sequence. - // - AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList, - this.arch); - List orderList = libOrder - .orderLibInstance(); - - if (orderList != null) { - // - // Process library instance one by one. - // - for (int i = 0; i < orderList.size(); i++) { - - // - // Get library instance basename. - // - ModuleIdentification libInstanceId = orderList.get(i); - - // - // Get override map - // - - Map libDoc = GlobalData.getDoc(libInstanceId, this.arch); - saq.push(libDoc); - // - // Get , , list of this library - // instance. - // - String[] ppiList = saq.getPpiArray(this.arch); - String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch); - String[] protocolList = saq.getProtocolArray(this.arch); - String[] protocolNotifyList = saq.getProtocolNotifyArray(this.arch); - String[] guidList = saq.getGuidEntryArray(this.arch); - PackageIdentification[] pkgList = saq.getDependencePkg(this.arch); - - // - // Add those ppi, protocol, guid in global ppi, - // protocol, guid - // list. - // - for (index = 0; index < ppiList.length; index++) { - this.mPpiList.add(ppiList[index]); - } - - for (index = 0; index < ppiNotifyList.length; index++) { - this.mPpiList.add(ppiNotifyList[index]); - } - - for (index = 0; index < protocolList.length; index++) { - this.mProtocolList.add(protocolList[index]); - } - - for (index = 0; index < protocolNotifyList.length; index++) { - this.mProtocolList.add(protocolNotifyList[index]); - } - for (index = 0; index < guidList.length; index++) { - this.mGuidList.add(guidList[index]); - } - for (index = 0; index < pkgList.length; index++) { - if (!this.mDepPkgList.contains(pkgList[index])) { - this.mDepPkgList.add(pkgList[index]); - } - } - - // - // If not yet parse this library instance's constructor - // element,parse it. - // - libConstructName = saq.getLibConstructorName(); - libDestructName = saq.getLibDestructorName(); - - // - // Collect SetVirtualAddressMapCallBack and - // ExitBootServiceCallBack. - // - setVirtuals = saq.getSetVirtualAddressMapCallBackArray(); - exitBoots = saq.getExitBootServicesCallBackArray(); - if (setVirtuals != null) { - for (int j = 0; j < setVirtuals.length; j++) { - this.setVirtalAddList.add(setVirtuals[j]); - } - } - if (exitBoots != null) { - for (int k = 0; k < exitBoots.length; k++) { - this.exitBootServiceList.add(exitBoots[k]); - } - } - saq.pop(); - // - // Add dependent library instance constructor function. - // - if (libConstructName != null) { - this.libConstructList.add(libConstructName); - } - // - // Add dependent library instance destructor fuction. - // - if (libDestructName != null) { - this.libDestructList.add(libDestructName); - } - } - } - - } + if (libraryIdList != null) { + // + // Reorder library instance sequence. + // + AutogenLibOrder libOrder = new AutogenLibOrder(libraryIdList, + this.arch); + List orderList = libOrder + .orderLibInstance(); + + if (orderList != null) { + // + // Process library instance one by one. + // + for (int i = 0; i < orderList.size(); i++) { + + // + // Get library instance basename. + // + ModuleIdentification libInstanceId = orderList.get(i); + + // + // Get override map + // + + Map libDoc = GlobalData.getDoc(libInstanceId, this.arch); + saq.push(libDoc); + // + // Get , , list of this library + // instance. + // + String[] ppiList = saq.getPpiArray(this.arch); + String[] ppiNotifyList = saq.getPpiNotifyArray(this.arch); + String[] protocolList = saq.getProtocolArray(this.arch); + String[] protocolNotifyList = saq.getProtocolNotifyArray(this.arch); + String[] guidList = saq.getGuidEntryArray(this.arch); + PackageIdentification[] pkgList = saq.getDependencePkg(this.arch); + + // + // Add those ppi, protocol, guid in global ppi, + // protocol, guid + // list. + // + for (index = 0; index < ppiList.length; index++) { + this.mPpiList.add(ppiList[index]); + } + + for (index = 0; index < ppiNotifyList.length; index++) { + this.mPpiList.add(ppiNotifyList[index]); + } + + for (index = 0; index < protocolList.length; index++) { + this.mProtocolList.add(protocolList[index]); + } + + for (index = 0; index < protocolNotifyList.length; index++) { + this.mProtocolList.add(protocolNotifyList[index]); + } + + for (index = 0; index < guidList.length; index++) { + this.mGuidList.add(guidList[index]); + } + for (index = 0; index < pkgList.length; index++) { + if (!this.mDepPkgList.contains(pkgList[index])) { + this.mDepPkgList.add(pkgList[index]); + } + } + + // + // If not yet parse this library instance's constructor + // element,parse it. + // + libConstructName = saq.getLibConstructorName(); + libDestructName = saq.getLibDestructorName(); + + // + // Collect SetVirtualAddressMapCallBack and + // ExitBootServiceCallBack. + // + setVirtuals = saq.getSetVirtualAddressMapCallBackArray(); + exitBoots = saq.getExitBootServicesCallBackArray(); + if (setVirtuals != null) { + for (int j = 0; j < setVirtuals.length; j++) { + this.setVirtalAddList.add(setVirtuals[j]); + } + } + if (exitBoots != null) { + for (int k = 0; k < exitBoots.length; k++) { + this.exitBootServiceList.add(exitBoots[k]); + } + } + saq.pop(); + // + // Add dependent library instance constructor function. + // + if (libConstructName != null) { + this.libConstructList.add(libConstructName); + } + // + // Add dependent library instance destructor fuction. + // + if (libDestructName != null) { + this.libDestructList.add(libDestructName); + } + } + } - } catch (Exception e) { - System.out.println(e.getMessage()); - System.out.println("Collect library instance failed!"); - } + } } private void setVirtualAddressToAutogenC(StringBuffer fileBuffer){ // diff --git a/Tools/Source/GenBuild/org/tianocore/build/autogen/AutogenLibOrder.java b/Tools/Source/GenBuild/org/tianocore/build/autogen/AutogenLibOrder.java index 28e2a296f1..bddea90aab 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/autogen/AutogenLibOrder.java +++ b/Tools/Source/GenBuild/org/tianocore/build/autogen/AutogenLibOrder.java @@ -22,9 +22,11 @@ import java.util.List; import java.util.Map; import org.apache.xmlbeans.XmlObject; +import org.tianocore.build.exception.AutoGenException; import org.tianocore.build.global.GlobalData; import org.tianocore.build.global.SurfaceAreaQuery; import org.tianocore.build.id.ModuleIdentification; +import org.tianocore.common.exception.EdkException; /** This class This class is to reorder library instance sequence according to @@ -55,7 +57,7 @@ public class AutogenLibOrder { @param libraryList List of the library instance. @throws Exception **/ - AutogenLibOrder(ModuleIdentification[] libraryList, String arch) throws Exception { + AutogenLibOrder(ModuleIdentification[] libraryList, String arch) throws EdkException { LibraryInstanceNode libInstanceNode; String[] libClassDeclList = null; String[] libClassConsmList = null; @@ -80,9 +82,9 @@ public class AutogenLibOrder { classStr[k] = libClassConsmList[k]; } if (this.libInstanceMap.containsKey(libraryList[i])) { - throw new Exception( + throw new AutoGenException( libraryList[i].getName() - + "this library instance already exists, please check the library instance list!"); + + "-- this library instance already exists, please check the library instance list!"); } else { this.libInstanceMap.put(libraryList[i], classStr); } @@ -98,7 +100,7 @@ public class AutogenLibOrder { System.out.println(libClassDeclList[j] + " class is already implement by " + this.libClassMap.get(libClassDeclList[j])); - throw new Exception("Library Class: " + libClassDeclList + throw new AutoGenException("Library Class: " + libClassDeclList + " already has a library instance!"); } else { this.libClassMap.put(libClassDeclList[j], libraryList[i]); diff --git a/Tools/Source/GenBuild/org/tianocore/build/exception/GenBuildException.java b/Tools/Source/GenBuild/org/tianocore/build/exception/GenBuildException.java index c1d77444f1..b81d54cba2 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/exception/GenBuildException.java +++ b/Tools/Source/GenBuild/org/tianocore/build/exception/GenBuildException.java @@ -28,7 +28,7 @@ public class GenBuildException extends EdkException { @param expStr exception message string. **/ public GenBuildException(String expStr) { - super("[GenBuildException]:" + expStr); + super(expStr); } public GenBuildException() { diff --git a/Tools/Source/GenBuild/org/tianocore/build/exception/PcdAutogenException.java b/Tools/Source/GenBuild/org/tianocore/build/exception/PcdAutogenException.java index 558cff990e..3a3430c820 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/exception/PcdAutogenException.java +++ b/Tools/Source/GenBuild/org/tianocore/build/exception/PcdAutogenException.java @@ -26,7 +26,7 @@ public class PcdAutogenException extends AutoGenException { @param expStr exception message string. **/ public PcdAutogenException(String expStr) { - super("\r\n[PcdAutogenException] #############################\r\n" + expStr); + super(expStr); } public PcdAutogenException() { diff --git a/Tools/Source/GenBuild/org/tianocore/build/exception/PlatformPcdPreprocessBuildException.java b/Tools/Source/GenBuild/org/tianocore/build/exception/PlatformPcdPreprocessBuildException.java index 894f25e034..6bf6110148 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/exception/PlatformPcdPreprocessBuildException.java +++ b/Tools/Source/GenBuild/org/tianocore/build/exception/PlatformPcdPreprocessBuildException.java @@ -27,7 +27,7 @@ public class PlatformPcdPreprocessBuildException extends GenBuildException { @param expStr exception message string. **/ public PlatformPcdPreprocessBuildException(String expStr) { - super("\r\n[PlatformPcdPreprocess Failure] #############################\r\n" + expStr); + super(expStr); } public PlatformPcdPreprocessBuildException() { diff --git a/Tools/Source/GenBuild/org/tianocore/build/exception/TianoToolsException.java b/Tools/Source/GenBuild/org/tianocore/build/exception/TianoToolsException.java index 077905a8e8..bcfe37a8d6 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/exception/TianoToolsException.java +++ b/Tools/Source/GenBuild/org/tianocore/build/exception/TianoToolsException.java @@ -28,7 +28,7 @@ public class TianoToolsException extends EdkException { @param expStr exception message string. **/ public TianoToolsException(String expStr) { - super("[TianoToolsException]:" + expStr); + super(expStr); } public TianoToolsException() { diff --git a/Tools/Source/GenBuild/org/tianocore/build/exception/XmlParseException.java b/Tools/Source/GenBuild/org/tianocore/build/exception/XmlParseException.java index 0ba1a787aa..44d3fdc389 100644 --- a/Tools/Source/GenBuild/org/tianocore/build/exception/XmlParseException.java +++ b/Tools/Source/GenBuild/org/tianocore/build/exception/XmlParseException.java @@ -26,7 +26,7 @@ public class XmlParseException extends GenBuildException { @param expStr exception message string. **/ public XmlParseException(String expStr) { - super("[XmlParseException]:" + expStr); + super(expStr); } public XmlParseException() { -- 2.39.2