## @file\r
# This file is used to create a database used by build tool\r
#\r
-# Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>\r
# (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
# This program and the accompanying materials\r
# are licensed and made available under the terms and conditions of the BSD License\r
##\r
# Import Modules\r
#\r
-import sqlite3\r
-from Common.String import *\r
+from __future__ import absolute_import\r
+from Common.StringUtils import *\r
from Common.DataType import *\r
from Common.Misc import *\r
from types import *\r
\r
-from MetaDataTable import *\r
-from MetaFileTable import *\r
-from MetaFileParser import *\r
+from .MetaDataTable import *\r
+from .MetaFileTable import *\r
+from .MetaFileParser import *\r
\r
from Workspace.DecBuildData import DecBuildData\r
from Workspace.DscBuildData import DscBuildData\r
#\r
# @param DbPath Path of database file\r
# @param GlobalMacros Global macros used for replacement during file parsing\r
-# @prarm RenewDb=False Create new database file if it's already there\r
+# @param RenewDb=False Create new database file if it's already there\r
#\r
class WorkspaceDatabase(object):\r
\r
Arch = None\r
return (FilePath, Arch) in self._CACHE_\r
\r
- # key = (FilePath, Arch=None, Target=None, Toochain=None)\r
+ # key = (FilePath, Arch=None, Target=None, Toolchain=None)\r
def __getitem__(self, Key):\r
FilePath = Key[0]\r
KeyLength = len(Key)\r
return self._CACHE_[Key]\r
\r
# check file type\r
+ BuildObject = self.CreateBuildObject(FilePath, Arch, Target, Toolchain)\r
+ self._CACHE_[Key] = BuildObject\r
+ return BuildObject\r
+ def CreateBuildObject(self,FilePath, Arch, Target, Toolchain):\r
Ext = FilePath.Type\r
if Ext not in self._FILE_TYPE_:\r
return None\r
\r
# get the parser ready for this file\r
MetaFile = self._FILE_PARSER_[FileType](\r
- FilePath, \r
- FileType, \r
+ FilePath,\r
+ FileType,\r
Arch,\r
- MetaFileStorage(self.WorkspaceDb.Cur, FilePath, FileType)\r
+ MetaFileStorage(self.WorkspaceDb, FilePath, FileType)\r
)\r
- # alwasy do post-process, in case of macros change\r
+ # always do post-process, in case of macros change\r
MetaFile.DoPostProcess()\r
# object the build is based on\r
BuildObject = self._GENERATOR_[FileType](\r
Target,\r
Toolchain\r
)\r
- self._CACHE_[Key] = BuildObject\r
return BuildObject\r
\r
# placeholder for file format conversion\r
#\r
# @param DbPath Path of database file\r
# @param GlobalMacros Global macros used for replacement during file parsing\r
- # @prarm RenewDb=False Create new database file if it's already there\r
+ # @param RenewDb=False Create new database file if it's already there\r
#\r
- def __init__(self, DbPath, RenewDb=False):\r
- self._DbClosedFlag = False\r
- if not DbPath:\r
- DbPath = os.path.normpath(mws.join(GlobalData.gWorkspace, 'Conf', GlobalData.gDatabasePath))\r
-\r
- # don't create necessary path for db in memory\r
- if DbPath != ':memory:':\r
- DbDir = os.path.split(DbPath)[0]\r
- if not os.path.exists(DbDir):\r
- os.makedirs(DbDir)\r
-\r
- # remove db file in case inconsistency between db and file in file system\r
- if self._CheckWhetherDbNeedRenew(RenewDb, DbPath):\r
- os.remove(DbPath)\r
- \r
- # create db with optimized parameters\r
- self.Conn = sqlite3.connect(DbPath, isolation_level='DEFERRED')\r
- self.Conn.execute("PRAGMA synchronous=OFF")\r
- self.Conn.execute("PRAGMA temp_store=MEMORY")\r
- self.Conn.execute("PRAGMA count_changes=OFF")\r
- self.Conn.execute("PRAGMA cache_size=8192")\r
- #self.Conn.execute("PRAGMA page_size=8192")\r
-\r
- # to avoid non-ascii character conversion issue\r
- self.Conn.text_factory = str\r
- self.Cur = self.Conn.cursor()\r
-\r
+ def __init__(self):\r
+ self.DB = dict()\r
# create table for internal uses\r
- self.TblDataModel = TableDataModel(self.Cur)\r
- self.TblFile = TableFile(self.Cur)\r
+ self.TblDataModel = DataClass.MODEL_LIST\r
+ self.TblFile = []\r
self.Platform = None\r
\r
# conversion object for build or file format conversion purpose\r
self.BuildObject = WorkspaceDatabase.BuildObjectFactory(self)\r
self.TransformObject = WorkspaceDatabase.TransformObjectFactory(self)\r
\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 is 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
- \r
- ## Initialize build database\r
- def InitDatabase(self):\r
- EdkLogger.verbose("\nInitialize build database started ...")\r
+ def SetFileTimeStamp(self,FileId,TimeStamp):\r
+ self.TblFile[FileId-1][6] = TimeStamp\r
\r
- #\r
- # Create new tables\r
- #\r
- self.TblDataModel.Create(False)\r
- self.TblFile.Create(False)\r
-\r
- #\r
- # Initialize table DataModel\r
- #\r
- self.TblDataModel.InitTable()\r
- EdkLogger.verbose("Initialize build database ... DONE!")\r
+ def GetFileTimeStamp(self,FileId):\r
+ return self.TblFile[FileId-1][6]\r
\r
- ## Query a table\r
- #\r
- # @param Table: The instance of the table to be queried\r
- #\r
- def QueryTable(self, Table):\r
- Table.Query()\r
-\r
- def __del__(self):\r
- self.Close()\r
-\r
- ## Close entire database\r
- #\r
- # Commit all first\r
- # Close the connection and cursor\r
- #\r
- def Close(self):\r
- if not self._DbClosedFlag:\r
- self.Conn.commit()\r
- self.Cur.close()\r
- self.Conn.close()\r
- self._DbClosedFlag = True\r
\r
## Summarize all packages in the database\r
def GetPackageList(self, Platform, Arch, TargetName, ToolChainTag):\r
self.Platform = Platform\r
PackageList = []\r
- Pa = self.BuildObject[self.Platform, Arch]\r
+ Pa = self.BuildObject[self.Platform, Arch, TargetName, ToolChainTag]\r
#\r
# Get Package related to Modules\r
#\r
return PackageList\r
\r
## Summarize all platforms in the database\r
- def _GetPlatformList(self):\r
- PlatformList = []\r
- for PlatformFile in self.TblFile.GetFileList(MODEL_FILE_DSC):\r
+ def PlatformList(self):\r
+ RetVal = []\r
+ for PlatformFile in [item[3] for item in self.TblFile if item[5] == MODEL_FILE_DSC]:\r
try:\r
- Platform = self.BuildObject[PathClass(PlatformFile), 'COMMON']\r
+ RetVal.append(self.BuildObject[PathClass(PlatformFile), TAB_COMMON])\r
except:\r
- Platform = None\r
- if Platform is not None:\r
- PlatformList.append(Platform)\r
- return PlatformList\r
+ pass\r
+ return RetVal\r
\r
- def _MapPlatform(self, Dscfile):\r
- Platform = self.BuildObject[PathClass(Dscfile), 'COMMON']\r
+ def MapPlatform(self, Dscfile):\r
+ Platform = self.BuildObject[PathClass(Dscfile), TAB_COMMON]\r
if Platform is None:\r
EdkLogger.error('build', PARSER_ERROR, "Failed to parser DSC file: %s" % Dscfile)\r
return Platform\r
\r
- PlatformList = property(_GetPlatformList)\r
-\r
##\r
#\r
# This acts like the main() function for the script, unless it is 'import'ed into another\r