X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FWorkspace%2FWorkspaceDatabase.py;h=28a975f54e51cb0597266024ad5b2c4a495c4e23;hb=2e351cbe8e190271b3716284fc1076551d005472;hp=e554d843262e9f48d27b4199bf609cbdc3c85418;hpb=b9a6d9d7ca59563b769fbf0218f204913bddf45d;p=mirror_edk2.git
diff --git a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py b/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
index e554d84326..28a975f54e 100644
--- a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
+++ b/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
@@ -3,27 +3,21 @@
#
# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP
-# This program and the accompanying materials
-# are licensed and made available under the terms and conditions of the BSD License
-# which accompanies this distribution. The full text of the license may be found at
-# http://opensource.org/licenses/bsd-license.php
-#
-# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
# Import Modules
#
-import sqlite3
-from Common.String import *
+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
@@ -37,7 +31,7 @@ from Workspace.InfBuildData import InfBuildData
#
# @param DbPath Path of database file
# @param GlobalMacros Global macros used for replacement during file parsing
-# @prarm RenewDb=False Create new database file if it's already there
+# @param RenewDb=False Create new database file if it's already there
#
class WorkspaceDatabase(object):
@@ -82,7 +76,7 @@ class WorkspaceDatabase(object):
Arch = None
return (FilePath, Arch) in self._CACHE_
- # key = (FilePath, Arch=None, Target=None, Toochain=None)
+ # key = (FilePath, Arch=None, Target=None, Toolchain=None)
def __getitem__(self, Key):
FilePath = Key[0]
KeyLength = len(Key)
@@ -105,6 +99,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
@@ -114,12 +112,12 @@ class WorkspaceDatabase(object):
# get the parser ready for this file
MetaFile = self._FILE_PARSER_[FileType](
- FilePath,
- FileType,
+ FilePath,
+ FileType,
Arch,
- MetaFileStorage(self.WorkspaceDb.Cur, FilePath, FileType)
+ MetaFileStorage(self.WorkspaceDb, FilePath, FileType)
)
- # alwasy do post-process, in case of macros change
+ # always do post-process, in case of macros change
MetaFile.DoPostProcess()
# object the build is based on
BuildObject = self._GENERATOR_[FileType](
@@ -130,7 +128,6 @@ class WorkspaceDatabase(object):
Target,
Toolchain
)
- self._CACHE_[Key] = BuildObject
return BuildObject
# placeholder for file format conversion
@@ -146,135 +143,25 @@ class WorkspaceDatabase(object):
#
# @param DbPath Path of database file
# @param GlobalMacros Global macros used for replacement during file parsing
- # @prarm RenewDb=False Create new database file if it's already there
+ # @param 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.
-
- 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):
- 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 SetFileTimeStamp(self,FileId,TimeStamp):
+ self.TblFile[FileId-1][6] = TimeStamp
- def __del__(self):
- self.Close()
+ def GetFileTimeStamp(self,FileId):
+ return self.TblFile[FileId-1][6]
- ## 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 +188,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), '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):
- Platform = self.BuildObject[PathClass(Dscfile), 'COMMON']
+ 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