Added check of library instance against NULL
authorjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 14 Apr 2008 09:05:14 +0000 (09:05 +0000)
committerjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Mon, 14 Apr 2008 09:05:14 +0000 (09:05 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1148 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/Workspace/WorkspaceDatabase.py

index eb0e1c2..56fa53f 100644 (file)
@@ -32,13 +32,13 @@ from MetaFileParser import *
 from BuildClassObject import *\r
 \r
 ## Check if gvien file exists or not\r
-# \r
+#\r
 #   @param      File    File name or path to be checked\r
 #   @param      Dir     The directory the file is relative to\r
-# \r
+#\r
 #   @retval     True    if file exists\r
 #   @retval     False   if file doesn't exists\r
-# \r
+#\r
 def ValidFile(File, Dir='.'):\r
     Wd = os.getcwd()\r
     os.chdir(Dir)\r
@@ -49,13 +49,13 @@ def ValidFile(File, Dir='.'):
     return True\r
 \r
 ## Get GUID value from given packages\r
-# \r
+#\r
 #   @param      CName           The CName of the GUID\r
 #   @param      PackageList     List of packages looking-up in\r
-# \r
+#\r
 #   @retval     GuidValue   if the CName is found in any given package\r
 #   @retval     None        if the CName is not found in all given packages\r
-# \r
+#\r
 def GuidValue(CName, PackageList):\r
     for P in PackageList:\r
         if CName in P.Guids:\r
@@ -106,15 +106,15 @@ class DscBuildData(PlatformBuildClassObject):
         S += "\tVer = %s\n" % self.Version\r
         S += "\n"\r
         S += "\tSpecification = %s\n" % self.DscSpecification\r
-        S += "\tOutputDirectory = %s\n" % self.OutputDirectory \r
-        S += "\tSupArchList = %s\n" % self.SupArchList     \r
-        S += "\tBuildTargets = %s\n" % self.BuildTargets    \r
-        S += "\tSkuName = %s\n" % self.SkuName           \r
-        S += "\tFlashDefinition = %s\n" % self.FlashDefinition \r
-        S += "\tBuildNumber = %s\n" % self.BuildNumber     \r
-        S += "\tMakefileName = %s\n" % self.MakefileName    \r
-        S += "\tBsBaseAddress = %s\n" % self.BsBaseAddress   \r
-        S += "\tRtBaseAddress = %s\n" % self.RtBaseAddress   \r
+        S += "\tOutputDirectory = %s\n" % self.OutputDirectory\r
+        S += "\tSupArchList = %s\n" % self.SupArchList\r
+        S += "\tBuildTargets = %s\n" % self.BuildTargets\r
+        S += "\tSkuName = %s\n" % self.SkuName\r
+        S += "\tFlashDefinition = %s\n" % self.FlashDefinition\r
+        S += "\tBuildNumber = %s\n" % self.BuildNumber\r
+        S += "\tMakefileName = %s\n" % self.MakefileName\r
+        S += "\tBsBaseAddress = %s\n" % self.BsBaseAddress\r
+        S += "\tRtBaseAddress = %s\n" % self.RtBaseAddress\r
 \r
         S += '  <SkuId>\n'\r
         for SkuName in self.SkuIds:\r
@@ -133,13 +133,13 @@ class DscBuildData(PlatformBuildClassObject):
         #for LibraryClass in LibraryClassList:\r
         #    for ModuleType in ModuleTypeList:\r
         #        if not (LibraryClass,ModuleType) in self.LibraryClasses:\r
-        #            continue \r
+        #            continue\r
         #        S += "\t%32s, %-24s = %s\n" % (LibraryClass, ModuleType, self.LibraryClasses[LibraryClass,ModuleType])\r
-        \r
+\r
         S += '  <PCD>\n'\r
         for Name, Guid in self.Pcds:\r
             S += "\t%s.%s\n\t\t%s\n" % (Guid, Name, str(self.Pcds[Name, Guid]))\r
-        \r
+\r
         S += '  <BuildOption>\n'\r
         for ToolChainFamily,ToolChain in self.BuildOptions:\r
             S += "\t%s:%s = %s\n" % (ToolChainFamily, ToolChain, self.BuildOptions[ToolChainFamily, ToolChain])\r
@@ -327,7 +327,7 @@ class DscBuildData(PlatformBuildClassObject):
                 ModuleId = Record[5]\r
                 LineNo = Record[6]\r
                 if not ValidFile(ModuleFile):\r
-                    EdkLogger.error('build', FILE_NOT_FOUND, File=self.DescFilePath, \r
+                    EdkLogger.error('build', FILE_NOT_FOUND, File=self.DescFilePath,\r
                                     ExtraData=ModuleFile, Line=LineNo)\r
                 if ModuleFile in self._Modules:\r
                     continue\r
@@ -398,6 +398,7 @@ class DscBuildData(PlatformBuildClassObject):
                     EdkLogger.verbose("\t" + str(LibraryClassName) + " : " + str(LibraryModule))\r
                 else:\r
                     LibraryModule = LibraryInstance[LibraryClassName]\r
+                if LibraryModule == None: continue\r
 \r
                 if LibraryModule.ConstructorList != [] and LibraryModule not in Constructor:\r
                     Constructor.append(LibraryModule)\r
@@ -532,7 +533,7 @@ class DscBuildData(PlatformBuildClassObject):
 \r
     ##\r
     # for R8.x modules\r
-    # \r
+    #\r
     def _ResolveLibraryReference(self, Module):\r
         EdkLogger.verbose("")\r
         EdkLogger.verbose("Library instances of module [%s] [%s]:" % (str(Module), self._Arch))\r
@@ -559,11 +560,11 @@ class DscBuildData(PlatformBuildClassObject):
             PcdInModule = Module.Pcds[Name,Guid]\r
             if (Name,Guid) in self.Pcds:\r
                 PcdInPlatform = self.Pcds[Name,Guid]\r
-                # \r
+                #\r
                 # in case there's PCDs coming from FDF file, which have no type given.\r
                 # at this point, PcdInModule.Type has the type found from dependent\r
                 # package\r
-                # \r
+                #\r
                 if PcdInPlatform.Type != None and PcdInPlatform.Type != '':\r
                     PcdInModule.Type = PcdInPlatform.Type\r
                 PcdInModule.MaxDatumSize = PcdInPlatform.MaxDatumSize\r
@@ -676,7 +677,7 @@ class DscBuildData(PlatformBuildClassObject):
                 ModuleTypeSet.add(ModuleType)\r
                 LibraryInstance = NormPath(LibraryInstance, self._Macros)\r
                 if not ValidFile(LibraryInstance):\r
-                    EdkLogger.error('build', FILE_NOT_FOUND, File=self.DescFilePath, \r
+                    EdkLogger.error('build', FILE_NOT_FOUND, File=self.DescFilePath,\r
                                     ExtraData=LibraryInstance, Line=LineNo)\r
                 LibraryClassDict[Arch, ModuleType, LibraryClass] = LibraryInstance\r
 \r
@@ -1169,14 +1170,14 @@ class InfBuildData(ModuleBuildClassObject):
         "APPLICATION"           :   "UEFI_APPLICATION",\r
         "LOGO"                  :   "BASE",\r
     }\r
-    \r
+\r
     _NMAKE_FLAG_PATTERN_ = re.compile("(?:EBC_)?([A-Z]+)_(?:STD_|PROJ_|ARCH_)?FLAGS(?:_DLL|_ASL|_EXE)?", re.UNICODE)\r
     _TOOL_CODE_ = {\r
         "C"         :   "CC",\r
         "LIB"       :   "SLINK",\r
         "LINK"      :   "DLINK",\r
     }\r
-    \r
+\r
 \r
     def __init__(self, FilePath, Table, Db, Arch='COMMON', Macros={}):\r
         self.DescFilePath = FilePath\r
@@ -1360,12 +1361,12 @@ class InfBuildData(ModuleBuildClassObject):
                 else:\r
                     if TokenList[0] not in ['MSFT', 'GCC']:\r
                         EdkLogger.error("build", FORMAT_NOT_SUPPORTED,\r
-                                        "No supported family [%s]" % TokenList[0], \r
+                                        "No supported family [%s]" % TokenList[0],\r
                                         File=self.DescFilePath, Line=Record[-1])\r
                     self._CustomMakefile[TokenList[0]] = TokenList[1]\r
-        # \r
+        #\r
         # R8.x modules\r
-        # \r
+        #\r
         if self._AutoGenVersion < 0x00010005:   # _AutoGenVersion may be None, which is less than anything\r
             if self._ComponentType in self._MODULE_TYPE_:\r
                 self._ModuleType = self._MODULE_TYPE_[self._ComponentType]\r
@@ -1389,7 +1390,7 @@ class InfBuildData(ModuleBuildClassObject):
                 else:\r
                     ToolList = self._NMAKE_FLAG_PATTERN_.findall(Name)\r
                     if len(ToolList) == 0 or len(ToolList) != 1:\r
-                        EdkLogger.warn("build", "Don't know how to do with macro [%s]" % Name, \r
+                        EdkLogger.warn("build", "Don't know how to do with macro [%s]" % Name,\r
                                        File=self.DescFilePath, Line=LineNo)\r
                     else:\r
                         if self._BuildOptions == None:\r
@@ -1530,7 +1531,7 @@ class InfBuildData(ModuleBuildClassObject):
             if self._DestructorList == None:\r
                 self._DestructorList = []\r
         return self._DestructorList\r
-                        \r
+\r
     def _GetBinaryFiles(self):\r
         if self._Binaries == None:\r
             self._Binaries = []\r
@@ -1741,13 +1742,13 @@ class InfBuildData(ModuleBuildClassObject):
 \r
             # get necessary info from package declaring this PCD\r
             for Package in self.Packages:\r
-                # \r
+                #\r
                 # 'dynamic' in INF means its type is determined by platform;\r
-                # if platform doesn't give its type, use 'lowest' one in the \r
+                # if platform doesn't give its type, use 'lowest' one in the\r
                 # following order, if any\r
-                # \r
+                #\r
                 #   "FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"\r
-                # \r
+                #\r
                 PcdType = self._PCD_TYPE_STRING_[Type]\r
                 if Type in [MODEL_PCD_DYNAMIC, MODEL_PCD_DYNAMIC_EX]:\r
                     for T in ["FixedAtBuild", "PatchableInModule", "FeatureFlag", "Dynamic", "DynamicEx"]:\r
@@ -1766,7 +1767,7 @@ class InfBuildData(ModuleBuildClassObject):
                     break\r
             else:\r
                 EdkLogger.error(\r
-                            'build', \r
+                            'build',\r
                             PARSER_ERROR,\r
                             "PCD [%s.%s] in [%s] is not found in dependent packages:" % (TokenSpaceGuid, PcdCName, self.DescFilePath),\r
                             ExtraData="\t%s" % '\n\t'.join([str(P) for P in self.Packages])\r
@@ -1812,7 +1813,7 @@ class InfBuildData(ModuleBuildClassObject):
 # This class defined the build databse\r
 # During the phase of initialization, the database will create all tables and\r
 # insert all records of table DataModel\r
-# \r
+#\r
 # @param object:      Inherited from object class\r
 # @param DbPath:      A string for the path of the ECC database\r
 #\r
@@ -1873,10 +1874,10 @@ class WorkspaceDatabase(object):
             # create temp table for current file\r
             Table = self.WorkspaceDb[FilePath]\r
             BuildObject = self._GENERATOR_[FileType](\r
-                                    FilePath, \r
-                                    Table, \r
-                                    self.WorkspaceDb, \r
-                                    Arch, \r
+                                    FilePath,\r
+                                    Table,\r
+                                    self.WorkspaceDb,\r
+                                    Arch,\r
                                     self.WorkspaceDb._GlobalMacros\r
                                     )\r
             self._CACHE_[Key] = BuildObject\r
@@ -1916,7 +1917,7 @@ class WorkspaceDatabase(object):
 \r
         self.BuildObject = WorkspaceDatabase.BuildObjectFactory(self)\r
         self.TransformObject = WorkspaceDatabase.TransformObjectFactory(self)\r
-    \r
+\r
     ## Initialize build database\r
     #\r
     # 1. Delete all old existing tables\r
@@ -1925,13 +1926,13 @@ class WorkspaceDatabase(object):
     #\r
     def InitDatabase(self):\r
         EdkLogger.verbose("\nInitialize ECC database started ...")\r
-        \r
+\r
         #\r
         # Create new tables\r
         #\r
         self.TblDataModel.Create(False)\r
         self.TblFile.Create(False)\r
-        \r
+\r
         #\r
         # Initialize table DataModel\r
         #\r
@@ -1944,10 +1945,10 @@ class WorkspaceDatabase(object):
     #\r
     def QueryTable(self, Table):\r
         Table.Query()\r
-    \r
+\r
     ## Close entire database\r
     #\r
-    # Commit all first \r
+    # Commit all first\r
     # Close the connection and cursor\r
     #\r
     def Close(self):\r
@@ -1976,7 +1977,7 @@ class WorkspaceDatabase(object):
     def GetTableName(self, FileType, FileId):\r
         return "_%s_%s" % (FileType, FileId)\r
 \r
-    ## TRICK: \r
+    ## TRICK:\r
     # Key = FilePath\r
     # Value = FileType\r
     def __setitem__(self, FilePath, FileType):\r
@@ -1999,7 +2000,7 @@ class WorkspaceDatabase(object):
         Parser.Start()\r
 \r
     ## Return a temp table containing all content of the given file\r
-    # \r
+    #\r
     def __getitem__(self, FileInfo):\r
         if type(FileInfo) == type(''):\r
             FileId = self.GetFileId(FileInfo)\r
@@ -2027,11 +2028,10 @@ class WorkspaceDatabase(object):
 if __name__ == '__main__':\r
     EdkLogger.Initialize()\r
     EdkLogger.SetLevel(EdkLogger.DEBUG_0)\r
-    \r
+\r
     Db = WorkspaceDatabase(DATABASE_PATH)\r
     Db.InitDatabase()\r
-    Db.QueryTable(Db.TblDataModel)   \r
+    Db.QueryTable(Db.TblDataModel)\r
     Db.QueryTable(Db.TblFile)\r
     Db.QueryTable(Db.TblDsc)\r
     Db.Close()\r
-    
\ No newline at end of file