]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
Sync basetools' source and binary files with r1707 of the basetools project.
[mirror_edk2.git] / BaseTools / Source / Python / Workspace / WorkspaceDatabase.py
index df0fa81ebb7d3bf72260afd63da64afa461f08bf..348d219aa9efd30907bbf6ef9c74a0e238d3049b 100644 (file)
@@ -17,6 +17,7 @@
 import sqlite3
 import os
 import os.path
+import pickle
 
 import Common.EdkLogger as EdkLogger
 import Common.GlobalData as GlobalData
@@ -24,6 +25,7 @@ import Common.GlobalData as GlobalData
 from Common.String import *
 from Common.DataType import *
 from Common.Misc import *
+from types import *
 
 from CommonDataClass.CommonClass import SkuInfoClass
 
@@ -1109,6 +1111,7 @@ class InfBuildData(ModuleBuildClassObject):
         "BS_DRIVER"             :   "DXE_DRIVER",
         "RT_DRIVER"             :   "DXE_RUNTIME_DRIVER",
         "SAL_RT_DRIVER"         :   "DXE_SAL_DRIVER",
+        "SMM_DRIVER"            :   "SMM_DRIVER",
     #    "BS_DRIVER"             :   "DXE_SMM_DRIVER",
     #    "BS_DRIVER"             :   "UEFI_DRIVER",
         "APPLICATION"           :   "UEFI_APPLICATION",
@@ -2059,11 +2062,11 @@ class WorkspaceDatabase(object):
         if DbPath != ':memory:':
             DbDir = os.path.split(DbPath)[0]
             if not os.path.exists(DbDir):
-                os.makedirs(DbDir)\r
-                
-        # remove db file in case inconsistency between db and file in file system
-        if self._CheckWhetherDbNeedRenew(RenewDb, DbPath):\r
-            os.remove(DbPath)\r
+                os.makedirs(DbDir)
+
+            # remove db file in case inconsistency between db and file in file system
+            if self._CheckWhetherDbNeedRenew(RenewDb, DbPath):
+                os.remove(DbPath)
         
         # create db with optimized parameters
         self.Conn = sqlite3.connect(DbPath, isolation_level='DEFERRED')
@@ -2084,60 +2087,95 @@ class WorkspaceDatabase(object):
         # conversion object for build or file format conversion purpose
         self.BuildObject = WorkspaceDatabase.BuildObjectFactory(self)
         self.TransformObject = WorkspaceDatabase.TransformObjectFactory(self)
-\r
-    ## Check whether workspace database need to be renew.\r
-    #  The renew reason maybe:\r
-    #  1) If user force to renew;\r
-    #  2) If user do not force renew, and\r
-    #     a) If the time of last modified python source is newer than database file;\r
-    #     b) If the time of last modified frozen executable file is newer than database file;\r
-    #\r
-    #  @param force     User force renew database\r
-    #  @param DbPath    The absolute path of workspace database file\r
-    #\r
-    #  @return Bool value for whether need renew workspace databse\r
-    #\r
-    def _CheckWhetherDbNeedRenew (self, force, DbPath):\r
-        # if database does not exist, we need do nothing\r
-        if not os.path.exists(DbPath): return False\r
-            \r
-        # if user force to renew database, then not check whether database is out of date\r
-        if force: return True\r
-        \r
-        #    \r
-        # Check the time of last modified source file or build.exe\r
-        # if is newer than time of database, then database need to be re-created.\r
-        #\r
-        timeOfToolModified = 0\r
-        if hasattr(sys, "frozen"):\r
-            exePath             = os.path.abspath(sys.executable)\r
-            timeOfToolModified  = os.stat(exePath).st_mtime\r
-        else:\r
-            curPath  = os.path.dirname(__file__) # curPath is the path of WorkspaceDatabase.py\r
-            rootPath = os.path.split(curPath)[0] # rootPath is root path of python source, such as /BaseTools/Source/Python\r
-            if rootPath == "" or rootPath == None:\r
-                EdkLogger.verbose("\nFail to find the root path of build.exe or python sources, so can not \\r
-determine whether database file is out of date!\n")\r
-        \r
-            # walk the root path of source or build's binary to get the time last modified.\r
-        \r
-            for root, dirs, files in os.walk (rootPath):\r
-                for dir in dirs:\r
-                    # bypass source control folder \r
-                    if dir.lower() in [".svn", "_svn", "cvs"]:\r
-                        dirs.remove(dir)\r
-                        \r
-                for file in files:\r
-                    ext = os.path.splitext(file)[1]\r
-                    if ext.lower() == ".py":            # only check .py files\r
-                        fd = os.stat(os.path.join(root, file))\r
-                        if timeOfToolModified < fd.st_mtime:\r
-                            timeOfToolModified = fd.st_mtime\r
-        if timeOfToolModified > os.stat(DbPath).st_mtime:\r
-            EdkLogger.verbose("\nWorkspace database is out of data!")\r
-            return True\r
-            \r
-        return False\r
+
+    ## Check whether workspace database need to be renew.
+    #  The renew reason maybe:
+    #  1) If user force to renew;
+    #  2) If user do not force renew, and
+    #     a) If the time of last modified python source is newer than database file;
+    #     b) If the time of last modified frozen executable file is newer than database file;
+    #
+    #  @param force     User force renew database
+    #  @param DbPath    The absolute path of workspace database file
+    #
+    #  @return Bool value for whether need renew workspace databse
+    #
+    def _CheckWhetherDbNeedRenew (self, force, DbPath):
+        DbDir = os.path.split(DbPath)[0]
+        MacroFilePath = os.path.normpath(os.path.join(DbDir, "build.mac"))
+        MacroMatch = False
+        if os.path.exists(MacroFilePath) and os.path.isfile(MacroFilePath):
+            LastMacros = None
+            try:
+                f = open(MacroFilePath,'r')
+                LastMacros = pickle.load(f)
+                f.close()
+            except IOError:
+                pass
+            except:
+                f.close()
+
+            if LastMacros != None and type(LastMacros) is DictType:
+                if LastMacros == self._GlobalMacros:
+                    MacroMatch = True
+                    for Macro in LastMacros.keys():
+                        if not (Macro in self._GlobalMacros and LastMacros[Macro] == self._GlobalMacros[Macro]):
+                            MacroMatch = False;
+                            break;
+
+        if not MacroMatch:
+            # save command line macros to file
+            try:
+                f = open(MacroFilePath,'w')
+                pickle.dump(self._GlobalMacros, f, 2)
+                f.close()
+            except IOError:
+                pass
+            except:
+                f.close()
+
+            force = True
+
+        # if database does not exist, we need do nothing
+        if not os.path.exists(DbPath): return False
+            
+        # if user force to renew database, then not check whether database is out of date
+        if force: return True
+        
+        #    
+        # Check the time of last modified source file or build.exe
+        # if is newer than time of database, then database need to be re-created.
+        #
+        timeOfToolModified = 0
+        if hasattr(sys, "frozen"):
+            exePath             = os.path.abspath(sys.executable)
+            timeOfToolModified  = os.stat(exePath).st_mtime
+        else:
+            curPath  = os.path.dirname(__file__) # curPath is the path of WorkspaceDatabase.py
+            rootPath = os.path.split(curPath)[0] # rootPath is root path of python source, such as /BaseTools/Source/Python
+            if rootPath == "" or rootPath == None:
+                EdkLogger.verbose("\nFail to find the root path of build.exe or python sources, so can not \
+determine whether database file is out of date!\n")
+        
+            # walk the root path of source or build's binary to get the time last modified.
+        
+            for root, dirs, files in os.walk (rootPath):
+                for dir in dirs:
+                    # bypass source control folder 
+                    if dir.lower() in [".svn", "_svn", "cvs"]:
+                        dirs.remove(dir)
+                        
+                for file in files:
+                    ext = os.path.splitext(file)[1]
+                    if ext.lower() == ".py":            # only check .py files
+                        fd = os.stat(os.path.join(root, file))
+                        if timeOfToolModified < fd.st_mtime:
+                            timeOfToolModified = fd.st_mtime
+        if timeOfToolModified > os.stat(DbPath).st_mtime:
+            EdkLogger.verbose("\nWorkspace database is out of data!")
+            return True
+            
+        return False
             
     ## Initialize build database
     def InitDatabase(self):