Added more error check
authorjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Thu, 31 Jul 2008 08:21:31 +0000 (08:21 +0000)
committerjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Thu, 31 Jul 2008 08:21:31 +0000 (08:21 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1291 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/AutoGen/AutoGen.py
Source/Python/Workspace/WorkspaceDatabase.py
Source/Python/build/build.py

index 2f9d647..b54810f 100755 (executable)
@@ -36,6 +36,7 @@ from Common.EdkIIWorkspace import *
 from Common.DataType import *
 from Common.Misc import *
 from Common.String import *
+import Common.GlobalData as GlobalData
 from GenFds.FdfParser import *
 
 ## Regular expression for splitting Dependency Expression stirng into tokens
@@ -334,6 +335,7 @@ class PlatformAutoGen(AutoGen):
     #
     def _Init(self, Workspace, PlatformFile, Target, Toolchain, Arch):
         EdkLogger.verbose("\nAutoGen platform [%s] [%s]" % (PlatformFile, Arch))
+        GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (PlatformFile, Arch, Toolchain, Target)
 
         self._MetaFile = str(PlatformFile)
         self.Workspace = Workspace
@@ -620,7 +622,9 @@ class PlatformAutoGen(AutoGen):
     #
     def _GetBuildRule(self):
         if self._BuildRule == None:
-            BuildRuleFile = self.Workspace.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]
+            BuildRuleFile = None
+            if TAB_TAT_DEFINES_BUILD_RULE_CONF in self.Workspace.TargetTxt.TargetTxtDictionary:
+                BuildRuleFile = self.Workspace.TargetTxt.TargetTxtDictionary[TAB_TAT_DEFINES_BUILD_RULE_CONF]
             if BuildRuleFile in [None, '']:
                 BuildRuleFile = gBuildRuleFile
             self._BuildRule = BuildRule(BuildRuleFile)
@@ -791,21 +795,22 @@ class PlatformAutoGen(AutoGen):
                         LibraryPath = self.Platform.LibraryClasses[LibraryClassName, ModuleType]
                     if LibraryPath == None or LibraryPath == "":
                         LibraryPath = M.LibraryClasses[LibraryClassName]
-                        if LibraryPath == None:
+                        if LibraryPath == None or LibraryPath == "":
                             EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,
                                             "Instance of library class [%s] is not found" % LibraryClassName,
                                             File=self._MetaFile,
-                                            ExtraData="consumed by [%s] [%s]\n\t[%s]" % (str(M), self.Arch, str(Module)))
+                                            ExtraData="in [%s] [%s]\n\tconsumed by module [%s]" % (str(M), self.Arch, str(Module)))
 
                     LibraryModule = self.BuildDatabase[LibraryPath, self.Arch]
                     # for those forced library instance (NULL library), add a fake library class
                     if LibraryClassName.startswith("NULL"):
                         LibraryModule.LibraryClass.append(LibraryClassObject(LibraryClassName, [ModuleType]))
-                    elif ModuleType not in LibraryModule.LibraryClass[0].SupModList:
+                    elif LibraryModule.LibraryClass == None or len(LibraryModule.LibraryClass) == 0 \
+                         or ModuleType not in LibraryModule.LibraryClass[0].SupModList:
                         EdkLogger.error("build", OPTION_MISSING,
                                         "Module type [%s] is not supported by library instance [%s]" \
                                         % (ModuleType, LibraryPath), File=self._MetaFile,
-                                        ExtraData="\tconsumed by [%s]" % str(Module))
+                                        ExtraData="consumed by [%s]" % str(Module))
 
                     LibraryInstance[LibraryClassName] = LibraryModule
                     LibraryConsumerList.append(LibraryModule)
@@ -837,25 +842,7 @@ class PlatformAutoGen(AutoGen):
         Q = []
         for LibraryClassName in LibraryInstance:
             M = LibraryInstance[LibraryClassName]
-            #if M == None:
-            #    EdkLogger.error("build", RESOURCE_NOT_AVAILABLE,
-            #                    "Library instance of library class [%s] is not found" % LibraryClassName,
-            #                    File=self._MetaFile, ExtraData="consumed by [%s] [%s]" % (str(Module), self.Arch))
             LibraryList.append(M)
-            #
-            # check if there're library classes
-            #
-            #for Lc in M.LibraryClass:
-            #    if Lc.SupModList != None and ModuleType not in Lc.SupModList:
-            #        EdkLogger.error("build", OPTION_MISSING,
-            #                        "Module type [%s] is not supported by library instance [%s]" % (ModuleType, str(M)),
-            #                        File=self._MetaFile, ExtraData="\tconsumed by [%s]" % str(Module))
-
-                #if Lc.LibraryClass in LibraryInstance and str(M) != str(LibraryInstance[Lc.LibraryClass]):
-                #    EdkLogger.error("build", OPTION_CONFLICT,
-                #                    "More than one library instance found for library class [%s] in module [%s]" % (Lc.LibraryClass, str(Module)),
-                #                    ExtraData="\t%s\n\t%s" % (LibraryInstance[Lc.LibraryClass], str(M))
-                #                    )
             if ConsumedByList[M] == []:
                 Q.insert(0, M)
 
@@ -962,7 +949,9 @@ class PlatformAutoGen(AutoGen):
             EdkLogger.verbose("No MaxDatumSize specified for PCD %s.%s" \
                               % (ToPcd.TokenSpaceGuidCName, ToPcd.TokenCName))
             Value = ToPcd.DefaultValue
-            if Value[0] == 'L':
+            if Value in [None, '']:
+                ToPcd.MaxDatumSize = 1
+            elif Value[0] == 'L':
                 ToPcd.MaxDatumSize = str(len(Value) * 2)
             elif Value[0] == '{':
                 ToPcd.MaxDatumSize = str(len(Value.split(',')))
@@ -1040,7 +1029,9 @@ class PlatformAutoGen(AutoGen):
         while len(LibraryConsumerList) > 0:
             M = LibraryConsumerList.pop()
             for LibraryName in M.Libraries:
-                Library = self.Platform.LibraryClasses[LibraryName, ':dummy:']
+                Library = None
+                if (LibraryName, ':dummy:') in self.Platform.LibraryClasses:
+                    Library = self.Platform.LibraryClasses[LibraryName, ':dummy:']
                 if Library == None:
                     EdkLogger.warn("build", "Library [%s] is not found" % LibraryName, File=str(M),
                                     ExtraData="\t%s [%s]" % (str(Module), self.Arch))
@@ -1161,6 +1152,7 @@ class ModuleAutoGen(AutoGen):
     #
     def _Init(self, Workspace, ModuleFile, Target, Toolchain, Arch, PlatformFile):
         EdkLogger.verbose("\nAutoGen module [%s] [%s]" % (ModuleFile, Arch))
+        GlobalData.gProcessingFile = "%s [%s, %s, %s]" % (ModuleFile, Arch, Toolchain, Target)
 
         self.Workspace = Workspace
         self.WorkspaceDir = Workspace.WorkspaceDir
index 36170ef..d0f93ff 100644 (file)
@@ -409,6 +409,9 @@ class DscBuildData(PlatformBuildClassObject):
                 if not ValidFile(LibraryInstance, '.inf'):
                     EdkLogger.error('build', FILE_NOT_FOUND, File=self.DescFilePath,
                                     ExtraData=LibraryInstance, Line=LineNo)
+                if ModuleType != 'COMMON' and ModuleType not in SUP_MODULE_LIST:
+                    EdkLogger.error('build', OPTION_UNKNOWN, "Unknown module type [%s]" % ModuleType,
+                                    File=self.DescFilePath, ExtraData=LibraryInstance, Line=LineNo)
                 LibraryClassDict[Arch, ModuleType, LibraryClass] = LibraryInstance
                 if LibraryInstance not in self._LibraryInstances:
                     self._LibraryInstances.append(LibraryInstance)
index b9a7e48..65b9e07 100644 (file)
@@ -587,6 +587,12 @@ class BuildTask:
             # TRICK: hide the output of threads left runing, so that the user can
             #        catch the error message easily
             #
+            if not BuildTask._ErrorFlag.isSet():
+                GlobalData.gBuildingModule = "%s [%s, %s, %s]" % (str(self.BuildItem.BuildObject),
+                                                                  self.BuildItem.BuildObject.Arch,
+                                                                  self.BuildItem.BuildObject.ToolChain,
+                                                                  self.BuildItem.BuildObject.BuildTarget
+                                                                 )
             EdkLogger.SetLevel(EdkLogger.QUIET)
             BuildTask._ErrorFlag.set()
             BuildTask._ErrorMessage = "%s broken\n    %s [%s]" % \
@@ -998,7 +1004,7 @@ class Build():
                             ExitFlag.set()
                             BuildTask.WaitForComplete()
                             Pa.CreateMakeFile(False)
-                            EdkLogger.error("build", BUILD_ERROR, BuildTask.GetErrorMessage())
+                            EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)
                         # Start task scheduler
                         if not BuildTask.IsOnGoing():
                             BuildTask.StartScheduler(self.ThreadNumber, ExitFlag)
@@ -1006,7 +1012,7 @@ class Build():
                     # in case there's an interruption. we need a full version of makefile for platform
                     Pa.CreateMakeFile(False)
                     if BuildTask.HasError():
-                        EdkLogger.error("build", BUILD_ERROR, BuildTask.GetErrorMessage())
+                        EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)
 
                 #
                 # All modules have been put in build tasks queue. Tell task scheduler
@@ -1020,7 +1026,7 @@ class Build():
                 # has been signaled.
                 #
                 if BuildTask.HasError():
-                    EdkLogger.error("build", BUILD_ERROR, BuildTask.GetErrorMessage())
+                    EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)
 
                 # Generate FD image if there's a FDF file found
                 if self.Fdf != '' and self.Target in ["", "all", "fds"]:
@@ -1301,8 +1307,8 @@ def Main():
         EdkLogger.error(
                     "\nbuild",
                     CODE_ERROR,
-                    "Unknown fatal error",
-                    ExtraData="Please send email to dev@buildtools.tianocore.org for help, attaching following call stack trace!\n",
+                    "Unknown fatal error when processing [%s]" % GlobalData.gProcessingFile,
+                    ExtraData="\n(Please send email to dev@buildtools.tianocore.org for help, attaching following call stack trace!)\n",
                     RaiseError=False
                     )
         EdkLogger.quiet("(Python %s on %s) " % (platform.python_version(), sys.platform) + traceback.format_exc())