X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FWorkspace%2FWorkspaceDatabase.py;h=8dbf3ae97cb9d32403335f52a59807597250cfb7;hb=2f818ed0fb57d98985d151781a2ce9b8683129ee;hp=a40ab8fc8c882c49aa0c32041870655f337ac834;hpb=f7496d717357b9af78414d19679b073403812340;p=mirror_edk2.git diff --git a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py b/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py index a40ab8fc8c..8dbf3ae97c 100644 --- a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py +++ b/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py @@ -15,15 +15,15 @@ ## # Import Modules # -import sqlite3 +from __future__ import absolute_import from Common.StringUtils import * from Common.DataType import * from Common.Misc import * from types import * -from MetaDataTable import * -from MetaFileTable import * -from MetaFileParser import * +from .MetaDataTable import * +from .MetaFileTable import * +from .MetaFileParser import * from Workspace.DecBuildData import DecBuildData from Workspace.DscBuildData import DscBuildData @@ -105,6 +105,10 @@ class WorkspaceDatabase(object): return self._CACHE_[Key] # check file type + BuildObject = self.CreateBuildObject(FilePath, Arch, Target, Toolchain) + self._CACHE_[Key] = BuildObject + return BuildObject + def CreateBuildObject(self,FilePath, Arch, Target, Toolchain): Ext = FilePath.Type if Ext not in self._FILE_TYPE_: return None @@ -117,7 +121,7 @@ class WorkspaceDatabase(object): FilePath, FileType, Arch, - MetaFileStorage(self.WorkspaceDb.Cur, FilePath, FileType) + MetaFileStorage(self.WorkspaceDb, FilePath, FileType) ) # alwasy do post-process, in case of macros change MetaFile.DoPostProcess() @@ -130,7 +134,6 @@ class WorkspaceDatabase(object): Target, Toolchain ) - self._CACHE_[Key] = BuildObject return BuildObject # placeholder for file format conversion @@ -148,133 +151,23 @@ class WorkspaceDatabase(object): # @param GlobalMacros Global macros used for replacement during file parsing # @prarm RenewDb=False Create new database file if it's already there # - def __init__(self, DbPath, RenewDb=False): - self._DbClosedFlag = False - if not DbPath: - DbPath = os.path.normpath(mws.join(GlobalData.gWorkspace, 'Conf', GlobalData.gDatabasePath)) - - # don't create necessary path for db in memory - if DbPath != ':memory:': - DbDir = os.path.split(DbPath)[0] - if not os.path.exists(DbDir): - 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') - self.Conn.execute("PRAGMA synchronous=OFF") - self.Conn.execute("PRAGMA temp_store=MEMORY") - self.Conn.execute("PRAGMA count_changes=OFF") - self.Conn.execute("PRAGMA cache_size=8192") - #self.Conn.execute("PRAGMA page_size=8192") - - # to avoid non-ascii character conversion issue - self.Conn.text_factory = str - self.Cur = self.Conn.cursor() - + def __init__(self): + self.DB = dict() # create table for internal uses - self.TblDataModel = TableDataModel(self.Cur) - self.TblFile = TableFile(self.Cur) + self.TblDataModel = DataClass.MODEL_LIST + self.TblFile = [] self.Platform = None # conversion object for build or file format conversion purpose self.BuildObject = WorkspaceDatabase.BuildObjectFactory(self) self.TransformObject = WorkspaceDatabase.TransformObjectFactory(self) - ## 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): - # 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 is 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. + def SetFileTimeStamp(self,FileId,TimeStamp): + self.TblFile[FileId][6] = TimeStamp - 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) + def GetFileTimeStamp(self,FileId): + return self.TblFile[FileId][6] - 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): - EdkLogger.verbose("\nInitialize build database started ...") - - # - # Create new tables - # - self.TblDataModel.Create(False) - self.TblFile.Create(False) - - # - # Initialize table DataModel - # - self.TblDataModel.InitTable() - EdkLogger.verbose("Initialize build database ... DONE!") - - ## Query a table - # - # @param Table: The instance of the table to be queried - # - def QueryTable(self, Table): - Table.Query() - - def __del__(self): - self.Close() - - ## Close entire database - # - # Commit all first - # Close the connection and cursor - # - def Close(self): - if not self._DbClosedFlag: - self.Conn.commit() - self.Cur.close() - self.Conn.close() - self._DbClosedFlag = True ## Summarize all packages in the database def GetPackageList(self, Platform, Arch, TargetName, ToolChainTag): @@ -301,25 +194,21 @@ determine whether database file is out of date!\n") return PackageList ## Summarize all platforms in the database - def _GetPlatformList(self): - PlatformList = [] - for PlatformFile in self.TblFile.GetFileList(MODEL_FILE_DSC): + def PlatformList(self): + RetVal = [] + for PlatformFile in [item[3] for item in self.TblFile if item[5] == MODEL_FILE_DSC]: try: - Platform = self.BuildObject[PathClass(PlatformFile), TAB_COMMON] + RetVal.append(self.BuildObject[PathClass(PlatformFile), TAB_COMMON]) except: - Platform = None - if Platform is not None: - PlatformList.append(Platform) - return PlatformList + pass + return RetVal - def _MapPlatform(self, Dscfile): + def MapPlatform(self, Dscfile): Platform = self.BuildObject[PathClass(Dscfile), TAB_COMMON] if Platform is None: EdkLogger.error('build', PARSER_ERROR, "Failed to parser DSC file: %s" % Dscfile) return Platform - PlatformList = property(_GetPlatformList) - ## # # This acts like the main() function for the script, unless it is 'import'ed into another