Check In tool source code based on Build tool project revision r1655.
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@8964 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
364
BaseTools/Source/Python/Workspace/BuildClassObject.py
Normal file
364
BaseTools/Source/Python/Workspace/BuildClassObject.py
Normal file
@ -0,0 +1,364 @@
|
||||
## @file
|
||||
# This file is used to define each component of the build database
|
||||
#
|
||||
# Copyright (c) 2007 ~ 2008, Intel Corporation
|
||||
# All rights reserved. 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.
|
||||
#
|
||||
|
||||
import os
|
||||
|
||||
from Common.Misc import sdict
|
||||
from Common.Misc import RealPath2
|
||||
from Common.BuildToolError import *
|
||||
|
||||
## PcdClassObject
|
||||
#
|
||||
# This Class is used for PcdObject
|
||||
#
|
||||
# @param object: Inherited from object class
|
||||
# @param Name: Input value for Name of Pcd, default is None
|
||||
# @param Guid: Input value for Guid of Pcd, default is None
|
||||
# @param Type: Input value for Type of Pcd, default is None
|
||||
# @param DatumType: Input value for DatumType of Pcd, default is None
|
||||
# @param Value: Input value for Value of Pcd, default is None
|
||||
# @param Token: Input value for Token of Pcd, default is None
|
||||
# @param MaxDatumSize: Input value for MaxDatumSize of Pcd, default is None
|
||||
# @param SkuInfoList: Input value for SkuInfoList of Pcd, default is {}
|
||||
# @param IsOverrided: Input value for IsOverrided of Pcd, default is False
|
||||
#
|
||||
# @var TokenCName: To store value for TokenCName
|
||||
# @var TokenSpaceGuidCName: To store value for TokenSpaceGuidCName
|
||||
# @var Type: To store value for Type
|
||||
# @var DatumType: To store value for DatumType
|
||||
# @var TokenValue: To store value for TokenValue
|
||||
# @var MaxDatumSize: To store value for MaxDatumSize
|
||||
# @var SkuInfoList: To store value for SkuInfoList
|
||||
# @var IsOverrided: To store value for IsOverrided
|
||||
# @var Phase: To store value for Phase, default is "DXE"
|
||||
#
|
||||
class PcdClassObject(object):
|
||||
def __init__(self, Name = None, Guid = None, Type = None, DatumType = None, Value = None, Token = None, MaxDatumSize = None, SkuInfoList = {}, GuidValue = None):
|
||||
self.TokenCName = Name
|
||||
self.TokenSpaceGuidCName = Guid
|
||||
self.TokenSpaceGuidValue = GuidValue
|
||||
self.Type = Type
|
||||
self.DatumType = DatumType
|
||||
self.DefaultValue = Value
|
||||
self.TokenValue = Token
|
||||
self.MaxDatumSize = MaxDatumSize
|
||||
self.SkuInfoList = SkuInfoList
|
||||
self.Phase = "DXE"
|
||||
self.Pending = False
|
||||
|
||||
## Convert the class to a string
|
||||
#
|
||||
# Convert each member of the class to string
|
||||
# Organize to a signle line format string
|
||||
#
|
||||
# @retval Rtn Formatted String
|
||||
#
|
||||
def __str__(self):
|
||||
Rtn = '\tTokenCName=' + str(self.TokenCName) + ', ' + \
|
||||
'TokenSpaceGuidCName=' + str(self.TokenSpaceGuidCName) + ', ' + \
|
||||
'Type=' + str(self.Type) + ', ' + \
|
||||
'DatumType=' + str(self.DatumType) + ', ' + \
|
||||
'DefaultValue=' + str(self.DefaultValue) + ', ' + \
|
||||
'TokenValue=' + str(self.TokenValue) + ', ' + \
|
||||
'MaxDatumSize=' + str(self.MaxDatumSize) + ', '
|
||||
for Item in self.SkuInfoList.values():
|
||||
Rtn = Rtn + 'SkuId=' + Item.SkuId + ', ' + 'SkuIdName=' + Item.SkuIdName
|
||||
Rtn = Rtn + str(self.IsOverrided)
|
||||
|
||||
return Rtn
|
||||
|
||||
## Override __eq__ function
|
||||
#
|
||||
# Check whether pcds are the same
|
||||
#
|
||||
# @retval False The two pcds are different
|
||||
# @retval True The two pcds are the same
|
||||
#
|
||||
def __eq__(self, Other):
|
||||
return Other and self.TokenCName == Other.TokenCName and self.TokenSpaceGuidCName == Other.TokenSpaceGuidCName
|
||||
|
||||
## Override __hash__ function
|
||||
#
|
||||
# Use (TokenCName, TokenSpaceGuidCName) as key in hash table
|
||||
#
|
||||
# @retval truple() Key for hash table
|
||||
#
|
||||
def __hash__(self):
|
||||
return hash((self.TokenCName, self.TokenSpaceGuidCName))
|
||||
|
||||
## LibraryClassObject
|
||||
#
|
||||
# This Class defines LibraryClassObject used in BuildDatabase
|
||||
#
|
||||
# @param object: Inherited from object class
|
||||
# @param Name: Input value for LibraryClassName, default is None
|
||||
# @param SupModList: Input value for SupModList, default is []
|
||||
# @param Type: Input value for Type, default is None
|
||||
#
|
||||
# @var LibraryClass: To store value for LibraryClass
|
||||
# @var SupModList: To store value for SupModList
|
||||
# @var Type: To store value for Type
|
||||
#
|
||||
class LibraryClassObject(object):
|
||||
def __init__(self, Name = None, SupModList = [], Type = None):
|
||||
self.LibraryClass = Name
|
||||
self.SupModList = SupModList
|
||||
if Type != None:
|
||||
self.SupModList = CleanString(Type).split(DataType.TAB_SPACE_SPLIT)
|
||||
|
||||
## ModuleBuildClassObject
|
||||
#
|
||||
# This Class defines ModuleBuildClass
|
||||
#
|
||||
# @param object: Inherited from object class
|
||||
#
|
||||
# @var MetaFile: To store value for module meta file path
|
||||
# @var BaseName: To store value for BaseName
|
||||
# @var ModuleType: To store value for ModuleType
|
||||
# @var Guid: To store value for Guid
|
||||
# @var Version: To store value for Version
|
||||
# @var PcdIsDriver: To store value for PcdIsDriver
|
||||
# @var BinaryModule: To store value for BinaryModule
|
||||
# @var CustomMakefile: To store value for CustomMakefile
|
||||
# @var Specification: To store value for Specification
|
||||
# @var Shadow To store value for Shadow
|
||||
# @var LibraryClass: To store value for LibraryClass, it is a list structure as
|
||||
# [ LibraryClassObject, ...]
|
||||
# @var ModuleEntryPointList: To store value for ModuleEntryPointList
|
||||
# @var ModuleUnloadImageList: To store value for ModuleUnloadImageList
|
||||
# @var ConstructorList: To store value for ConstructorList
|
||||
# @var DestructorList: To store value for DestructorList
|
||||
# @var Binaries: To store value for Binaries, it is a list structure as
|
||||
# [ ModuleBinaryClassObject, ...]
|
||||
# @var Sources: To store value for Sources, it is a list structure as
|
||||
# [ ModuleSourceFilesClassObject, ... ]
|
||||
# @var LibraryClasses: To store value for LibraryClasses, it is a set structure as
|
||||
# { [LibraryClassName, ModuleType] : LibraryClassInfFile }
|
||||
# @var Protocols: To store value for Protocols, it is a list structure as
|
||||
# [ ProtocolName, ... ]
|
||||
# @var Ppis: To store value for Ppis, it is a list structure as
|
||||
# [ PpiName, ... ]
|
||||
# @var Guids: To store value for Guids, it is a list structure as
|
||||
# [ GuidName, ... ]
|
||||
# @var Includes: To store value for Includes, it is a list structure as
|
||||
# [ IncludePath, ... ]
|
||||
# @var Packages: To store value for Packages, it is a list structure as
|
||||
# [ DecFileName, ... ]
|
||||
# @var Pcds: To store value for Pcds, it is a set structure as
|
||||
# { [(PcdCName, PcdGuidCName)] : PcdClassObject}
|
||||
# @var BuildOptions: To store value for BuildOptions, it is a set structure as
|
||||
# { [BuildOptionKey] : BuildOptionValue}
|
||||
# @var Depex: To store value for Depex
|
||||
#
|
||||
class ModuleBuildClassObject(object):
|
||||
def __init__(self):
|
||||
self.AutoGenVersion = 0
|
||||
self.MetaFile = ''
|
||||
self.BaseName = ''
|
||||
self.ModuleType = ''
|
||||
self.Guid = ''
|
||||
self.Version = ''
|
||||
self.PcdIsDriver = ''
|
||||
self.BinaryModule = ''
|
||||
self.Shadow = ''
|
||||
self.SourceOverridePath = ''
|
||||
self.CustomMakefile = {}
|
||||
self.Specification = {}
|
||||
self.LibraryClass = []
|
||||
self.ModuleEntryPointList = []
|
||||
self.ModuleUnloadImageList = []
|
||||
self.ConstructorList = []
|
||||
self.DestructorList = []
|
||||
|
||||
self.Binaries = []
|
||||
self.Sources = []
|
||||
self.LibraryClasses = sdict()
|
||||
self.Libraries = []
|
||||
self.Protocols = []
|
||||
self.Ppis = []
|
||||
self.Guids = []
|
||||
self.Includes = []
|
||||
self.Packages = []
|
||||
self.Pcds = {}
|
||||
self.BuildOptions = {}
|
||||
self.Depex = {}
|
||||
|
||||
## Convert the class to a string
|
||||
#
|
||||
# Convert member MetaFile of the class to a string
|
||||
#
|
||||
# @retval string Formatted String
|
||||
#
|
||||
def __str__(self):
|
||||
return str(self.MetaFile)
|
||||
|
||||
## Override __eq__ function
|
||||
#
|
||||
# Check whether ModuleBuildClassObjects are the same
|
||||
#
|
||||
# @retval False The two ModuleBuildClassObjects are different
|
||||
# @retval True The two ModuleBuildClassObjects are the same
|
||||
#
|
||||
def __eq__(self, Other):
|
||||
return self.MetaFile == Other
|
||||
|
||||
## Override __hash__ function
|
||||
#
|
||||
# Use MetaFile as key in hash table
|
||||
#
|
||||
# @retval string Key for hash table
|
||||
#
|
||||
def __hash__(self):
|
||||
return hash(self.MetaFile)
|
||||
|
||||
## PackageBuildClassObject
|
||||
#
|
||||
# This Class defines PackageBuildClass
|
||||
#
|
||||
# @param object: Inherited from object class
|
||||
#
|
||||
# @var MetaFile: To store value for package meta file path
|
||||
# @var PackageName: To store value for PackageName
|
||||
# @var Guid: To store value for Guid
|
||||
# @var Version: To store value for Version
|
||||
# @var Protocols: To store value for Protocols, it is a set structure as
|
||||
# { [ProtocolName] : Protocol Guid, ... }
|
||||
# @var Ppis: To store value for Ppis, it is a set structure as
|
||||
# { [PpiName] : Ppi Guid, ... }
|
||||
# @var Guids: To store value for Guids, it is a set structure as
|
||||
# { [GuidName] : Guid, ... }
|
||||
# @var Includes: To store value for Includes, it is a list structure as
|
||||
# [ IncludePath, ... ]
|
||||
# @var LibraryClasses: To store value for LibraryClasses, it is a set structure as
|
||||
# { [LibraryClassName] : LibraryClassInfFile }
|
||||
# @var Pcds: To store value for Pcds, it is a set structure as
|
||||
# { [(PcdCName, PcdGuidCName)] : PcdClassObject}
|
||||
#
|
||||
class PackageBuildClassObject(object):
|
||||
def __init__(self):
|
||||
self.MetaFile = ''
|
||||
self.PackageName = ''
|
||||
self.Guid = ''
|
||||
self.Version = ''
|
||||
|
||||
self.Protocols = {}
|
||||
self.Ppis = {}
|
||||
self.Guids = {}
|
||||
self.Includes = []
|
||||
self.LibraryClasses = {}
|
||||
self.Pcds = {}
|
||||
|
||||
## Convert the class to a string
|
||||
#
|
||||
# Convert member MetaFile of the class to a string
|
||||
#
|
||||
# @retval string Formatted String
|
||||
#
|
||||
def __str__(self):
|
||||
return str(self.MetaFile)
|
||||
|
||||
## Override __eq__ function
|
||||
#
|
||||
# Check whether PackageBuildClassObjects are the same
|
||||
#
|
||||
# @retval False The two PackageBuildClassObjects are different
|
||||
# @retval True The two PackageBuildClassObjects are the same
|
||||
#
|
||||
def __eq__(self, Other):
|
||||
return self.MetaFile == Other
|
||||
|
||||
## Override __hash__ function
|
||||
#
|
||||
# Use MetaFile as key in hash table
|
||||
#
|
||||
# @retval string Key for hash table
|
||||
#
|
||||
def __hash__(self):
|
||||
return hash(self.MetaFile)
|
||||
|
||||
## PlatformBuildClassObject
|
||||
#
|
||||
# This Class defines PlatformBuildClass
|
||||
#
|
||||
# @param object: Inherited from object class
|
||||
#
|
||||
# @var MetaFile: To store value for platform meta-file path
|
||||
# @var PlatformName: To store value for PlatformName
|
||||
# @var Guid: To store value for Guid
|
||||
# @var Version: To store value for Version
|
||||
# @var DscSpecification: To store value for DscSpecification
|
||||
# @var OutputDirectory: To store value for OutputDirectory
|
||||
# @var FlashDefinition: To store value for FlashDefinition
|
||||
# @var BuildNumber: To store value for BuildNumber
|
||||
# @var MakefileName: To store value for MakefileName
|
||||
# @var SkuIds: To store value for SkuIds, it is a set structure as
|
||||
# { 'SkuName' : SkuId, '!include' : includefilename, ...}
|
||||
# @var Modules: To store value for Modules, it is a list structure as
|
||||
# [ InfFileName, ... ]
|
||||
# @var Libraries: To store value for Libraries, it is a list structure as
|
||||
# [ InfFileName, ... ]
|
||||
# @var LibraryClasses: To store value for LibraryClasses, it is a set structure as
|
||||
# { (LibraryClassName, ModuleType) : LibraryClassInfFile }
|
||||
# @var Pcds: To store value for Pcds, it is a set structure as
|
||||
# { [(PcdCName, PcdGuidCName)] : PcdClassObject }
|
||||
# @var BuildOptions: To store value for BuildOptions, it is a set structure as
|
||||
# { [BuildOptionKey] : BuildOptionValue }
|
||||
#
|
||||
class PlatformBuildClassObject(object):
|
||||
def __init__(self):
|
||||
self.MetaFile = ''
|
||||
self.PlatformName = ''
|
||||
self.Guid = ''
|
||||
self.Version = ''
|
||||
self.DscSpecification = ''
|
||||
self.OutputDirectory = ''
|
||||
self.FlashDefinition = ''
|
||||
self.BuildNumber = ''
|
||||
self.MakefileName = ''
|
||||
|
||||
self.SkuIds = {}
|
||||
self.Modules = []
|
||||
self.LibraryInstances = []
|
||||
self.LibraryClasses = {}
|
||||
self.Libraries = {}
|
||||
self.Pcds = {}
|
||||
self.BuildOptions = {}
|
||||
|
||||
## Convert the class to a string
|
||||
#
|
||||
# Convert member MetaFile of the class to a string
|
||||
#
|
||||
# @retval string Formatted String
|
||||
#
|
||||
def __str__(self):
|
||||
return str(self.MetaFile)
|
||||
|
||||
## Override __eq__ function
|
||||
#
|
||||
# Check whether PlatformBuildClassObjects are the same
|
||||
#
|
||||
# @retval False The two PlatformBuildClassObjects are different
|
||||
# @retval True The two PlatformBuildClassObjects are the same
|
||||
#
|
||||
def __eq__(self, Other):
|
||||
return self.MetaFile == Other
|
||||
|
||||
## Override __hash__ function
|
||||
#
|
||||
# Use MetaFile as key in hash table
|
||||
#
|
||||
# @retval string Key for hash table
|
||||
#
|
||||
def __hash__(self):
|
||||
return hash(self.MetaFile)
|
||||
|
335
BaseTools/Source/Python/Workspace/MetaDataTable.py
Normal file
335
BaseTools/Source/Python/Workspace/MetaDataTable.py
Normal file
@ -0,0 +1,335 @@
|
||||
## @file
|
||||
# This file is used to create/update/query/erase table for files
|
||||
#
|
||||
# Copyright (c) 2008, Intel Corporation
|
||||
# All rights reserved. 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.
|
||||
#
|
||||
|
||||
##
|
||||
# Import Modules
|
||||
#
|
||||
import os
|
||||
|
||||
import Common.EdkLogger as EdkLogger
|
||||
from CommonDataClass import DataClass
|
||||
from CommonDataClass.DataClass import FileClass
|
||||
|
||||
## Convert to SQL required string format
|
||||
def ConvertToSqlString(StringList):
|
||||
return map(lambda s: "'" + s.replace("'", "''") + "'", StringList)
|
||||
|
||||
## TableFile
|
||||
#
|
||||
# This class defined a common table
|
||||
#
|
||||
# @param object: Inherited from object class
|
||||
#
|
||||
# @param Cursor: Cursor of the database
|
||||
# @param TableName: Name of the table
|
||||
#
|
||||
class Table(object):
|
||||
_COLUMN_ = ''
|
||||
_ID_STEP_ = 1
|
||||
_ID_MAX_ = 0x80000000
|
||||
_DUMMY_ = 0
|
||||
|
||||
def __init__(self, Cursor, Name='', IdBase=0, Temporary=False):
|
||||
self.Cur = Cursor
|
||||
self.Table = Name
|
||||
self.IdBase = int(IdBase)
|
||||
self.ID = int(IdBase)
|
||||
self.Temporary = Temporary
|
||||
|
||||
def __str__(self):
|
||||
return self.Table
|
||||
|
||||
## Create table
|
||||
#
|
||||
# Create a table
|
||||
#
|
||||
def Create(self, NewTable=True):
|
||||
if NewTable:
|
||||
self.Drop()
|
||||
|
||||
if self.Temporary:
|
||||
SqlCommand = """create temp table IF NOT EXISTS %s (%s)""" % (self.Table, self._COLUMN_)
|
||||
else:
|
||||
SqlCommand = """create table IF NOT EXISTS %s (%s)""" % (self.Table, self._COLUMN_)
|
||||
EdkLogger.debug(EdkLogger.DEBUG_8, SqlCommand)
|
||||
self.Cur.execute(SqlCommand)
|
||||
self.ID = self.GetId()
|
||||
|
||||
## Insert table
|
||||
#
|
||||
# Insert a record into a table
|
||||
#
|
||||
def Insert(self, *Args):
|
||||
self.ID = self.ID + self._ID_STEP_
|
||||
if self.ID >= (self.IdBase + self._ID_MAX_):
|
||||
self.ID = self.IdBase + self._ID_STEP_
|
||||
Values = ", ".join([str(Arg) for Arg in Args])
|
||||
SqlCommand = "insert into %s values(%s, %s)" % (self.Table, self.ID, Values)
|
||||
EdkLogger.debug(EdkLogger.DEBUG_5, SqlCommand)
|
||||
self.Cur.execute(SqlCommand)
|
||||
return self.ID
|
||||
|
||||
## Query table
|
||||
#
|
||||
# Query all records of the table
|
||||
#
|
||||
def Query(self):
|
||||
SqlCommand = """select * from %s""" % self.Table
|
||||
self.Cur.execute(SqlCommand)
|
||||
for Rs in self.Cur:
|
||||
EdkLogger.verbose(str(Rs))
|
||||
TotalCount = self.GetId()
|
||||
|
||||
## Drop a table
|
||||
#
|
||||
# Drop the table
|
||||
#
|
||||
def Drop(self):
|
||||
SqlCommand = """drop table IF EXISTS %s""" % self.Table
|
||||
self.Cur.execute(SqlCommand)
|
||||
|
||||
## Get count
|
||||
#
|
||||
# Get a count of all records of the table
|
||||
#
|
||||
# @retval Count: Total count of all records
|
||||
#
|
||||
def GetCount(self):
|
||||
SqlCommand = """select count(ID) from %s""" % self.Table
|
||||
Record = self.Cur.execute(SqlCommand).fetchall()
|
||||
return Record[0][0]
|
||||
|
||||
def GetId(self):
|
||||
SqlCommand = """select max(ID) from %s""" % self.Table
|
||||
Record = self.Cur.execute(SqlCommand).fetchall()
|
||||
Id = Record[0][0]
|
||||
if Id == None:
|
||||
Id = self.IdBase
|
||||
return Id
|
||||
|
||||
## Init the ID of the table
|
||||
#
|
||||
# Init the ID of the table
|
||||
#
|
||||
def InitID(self):
|
||||
self.ID = self.GetId()
|
||||
|
||||
## Exec
|
||||
#
|
||||
# Exec Sql Command, return result
|
||||
#
|
||||
# @param SqlCommand: The SqlCommand to be executed
|
||||
#
|
||||
# @retval RecordSet: The result after executed
|
||||
#
|
||||
def Exec(self, SqlCommand):
|
||||
EdkLogger.debug(EdkLogger.DEBUG_5, SqlCommand)
|
||||
self.Cur.execute(SqlCommand)
|
||||
RecordSet = self.Cur.fetchall()
|
||||
return RecordSet
|
||||
|
||||
def SetEndFlag(self):
|
||||
self.Exec("insert into %s values(%s)" % (self.Table, self._DUMMY_))
|
||||
|
||||
def IsIntegral(self):
|
||||
Result = self.Exec("select min(ID) from %s" % (self.Table))
|
||||
if Result[0][0] != -1:
|
||||
return False
|
||||
return True
|
||||
|
||||
## TableFile
|
||||
#
|
||||
# This class defined a table used for file
|
||||
#
|
||||
# @param object: Inherited from object class
|
||||
#
|
||||
class TableFile(Table):
|
||||
_COLUMN_ = '''
|
||||
ID INTEGER PRIMARY KEY,
|
||||
Name VARCHAR NOT NULL,
|
||||
ExtName VARCHAR,
|
||||
Path VARCHAR,
|
||||
FullPath VARCHAR NOT NULL,
|
||||
Model INTEGER DEFAULT 0,
|
||||
TimeStamp SINGLE NOT NULL
|
||||
'''
|
||||
def __init__(self, Cursor):
|
||||
Table.__init__(self, Cursor, 'File')
|
||||
|
||||
## Insert table
|
||||
#
|
||||
# Insert a record into table File
|
||||
#
|
||||
# @param Name: Name of a File
|
||||
# @param ExtName: ExtName of a File
|
||||
# @param Path: Path of a File
|
||||
# @param FullPath: FullPath of a File
|
||||
# @param Model: Model of a File
|
||||
# @param TimeStamp: TimeStamp of a File
|
||||
#
|
||||
def Insert(self, Name, ExtName, Path, FullPath, Model, TimeStamp):
|
||||
(Name, ExtName, Path, FullPath) = ConvertToSqlString((Name, ExtName, Path, FullPath))
|
||||
return Table.Insert(
|
||||
self,
|
||||
Name,
|
||||
ExtName,
|
||||
Path,
|
||||
FullPath,
|
||||
Model,
|
||||
TimeStamp
|
||||
)
|
||||
|
||||
## InsertFile
|
||||
#
|
||||
# Insert one file to table
|
||||
#
|
||||
# @param FileFullPath: The full path of the file
|
||||
# @param Model: The model of the file
|
||||
#
|
||||
# @retval FileID: The ID after record is inserted
|
||||
#
|
||||
def InsertFile(self, FileFullPath, Model):
|
||||
(Filepath, Name) = os.path.split(FileFullPath)
|
||||
(Root, Ext) = os.path.splitext(FileFullPath)
|
||||
TimeStamp = os.stat(FileFullPath)[8]
|
||||
File = FileClass(-1, Name, Ext, Filepath, FileFullPath, Model, '', [], [], [])
|
||||
return self.Insert(
|
||||
Name,
|
||||
Ext,
|
||||
Filepath,
|
||||
FileFullPath,
|
||||
Model,
|
||||
TimeStamp
|
||||
)
|
||||
|
||||
## Get ID of a given file
|
||||
#
|
||||
# @param FilePath Path of file
|
||||
#
|
||||
# @retval ID ID value of given file in the table
|
||||
#
|
||||
def GetFileId(self, FilePath):
|
||||
QueryScript = "select ID from %s where FullPath = '%s'" % (self.Table, FilePath)
|
||||
RecordList = self.Exec(QueryScript)
|
||||
if len(RecordList) == 0:
|
||||
return None
|
||||
return RecordList[0][0]
|
||||
|
||||
## Get type of a given file
|
||||
#
|
||||
# @param FileId ID of a file
|
||||
#
|
||||
# @retval file_type Model value of given file in the table
|
||||
#
|
||||
def GetFileType(self, FileId):
|
||||
QueryScript = "select Model from %s where ID = '%s'" % (self.Table, FileId)
|
||||
RecordList = self.Exec(QueryScript)
|
||||
if len(RecordList) == 0:
|
||||
return None
|
||||
return RecordList[0][0]
|
||||
|
||||
## Get file timestamp of a given file
|
||||
#
|
||||
# @param FileId ID of file
|
||||
#
|
||||
# @retval timestamp TimeStamp value of given file in the table
|
||||
#
|
||||
def GetFileTimeStamp(self, FileId):
|
||||
QueryScript = "select TimeStamp from %s where ID = '%s'" % (self.Table, FileId)
|
||||
RecordList = self.Exec(QueryScript)
|
||||
if len(RecordList) == 0:
|
||||
return None
|
||||
return RecordList[0][0]
|
||||
|
||||
## Update the timestamp of a given file
|
||||
#
|
||||
# @param FileId ID of file
|
||||
# @param TimeStamp Time stamp of file
|
||||
#
|
||||
def SetFileTimeStamp(self, FileId, TimeStamp):
|
||||
self.Exec("update %s set TimeStamp=%s where ID='%s'" % (self.Table, TimeStamp, FileId))
|
||||
|
||||
## Get list of file with given type
|
||||
#
|
||||
# @param FileType Type value of file
|
||||
#
|
||||
# @retval file_list List of files with the given type
|
||||
#
|
||||
def GetFileList(self, FileType):
|
||||
RecordList = self.Exec("select FullPath from %s where Model=%s" % (self.Table, FileType))
|
||||
if len(RecordList) == 0:
|
||||
return []
|
||||
return [R[0] for R in RecordList]
|
||||
|
||||
## TableDataModel
|
||||
#
|
||||
# This class defined a table used for data model
|
||||
#
|
||||
# @param object: Inherited from object class
|
||||
#
|
||||
#
|
||||
class TableDataModel(Table):
|
||||
_COLUMN_ = """
|
||||
ID INTEGER PRIMARY KEY,
|
||||
CrossIndex INTEGER NOT NULL,
|
||||
Name VARCHAR NOT NULL,
|
||||
Description VARCHAR
|
||||
"""
|
||||
def __init__(self, Cursor):
|
||||
Table.__init__(self, Cursor, 'DataModel')
|
||||
|
||||
## Insert table
|
||||
#
|
||||
# Insert a record into table DataModel
|
||||
#
|
||||
# @param ID: ID of a ModelType
|
||||
# @param CrossIndex: CrossIndex of a ModelType
|
||||
# @param Name: Name of a ModelType
|
||||
# @param Description: Description of a ModelType
|
||||
#
|
||||
def Insert(self, CrossIndex, Name, Description):
|
||||
(Name, Description) = ConvertToSqlString((Name, Description))
|
||||
return Table.Insert(self, CrossIndex, Name, Description)
|
||||
|
||||
## Init table
|
||||
#
|
||||
# Create all default records of table DataModel
|
||||
#
|
||||
def InitTable(self):
|
||||
EdkLogger.verbose("\nInitialize table DataModel started ...")
|
||||
Count = self.GetCount()
|
||||
if Count != None and Count != 0:
|
||||
return
|
||||
for Item in DataClass.MODEL_LIST:
|
||||
CrossIndex = Item[1]
|
||||
Name = Item[0]
|
||||
Description = Item[0]
|
||||
self.Insert(CrossIndex, Name, Description)
|
||||
EdkLogger.verbose("Initialize table DataModel ... DONE!")
|
||||
|
||||
## Get CrossIndex
|
||||
#
|
||||
# Get a model's cross index from its name
|
||||
#
|
||||
# @param ModelName: Name of the model
|
||||
# @retval CrossIndex: CrossIndex of the model
|
||||
#
|
||||
def GetCrossIndex(self, ModelName):
|
||||
CrossIndex = -1
|
||||
SqlCommand = """select CrossIndex from DataModel where name = '""" + ModelName + """'"""
|
||||
self.Cur.execute(SqlCommand)
|
||||
for Item in self.Cur:
|
||||
CrossIndex = Item[0]
|
||||
|
||||
return CrossIndex
|
||||
|
1131
BaseTools/Source/Python/Workspace/MetaFileParser.py
Normal file
1131
BaseTools/Source/Python/Workspace/MetaFileParser.py
Normal file
File diff suppressed because it is too large
Load Diff
275
BaseTools/Source/Python/Workspace/MetaFileTable.py
Normal file
275
BaseTools/Source/Python/Workspace/MetaFileTable.py
Normal file
@ -0,0 +1,275 @@
|
||||
## @file
|
||||
# This file is used to create/update/query/erase a meta file table
|
||||
#
|
||||
# Copyright (c) 2008, Intel Corporation
|
||||
# All rights reserved. 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.
|
||||
#
|
||||
|
||||
##
|
||||
# Import Modules
|
||||
#
|
||||
import Common.EdkLogger as EdkLogger
|
||||
from MetaDataTable import Table
|
||||
from MetaDataTable import ConvertToSqlString
|
||||
|
||||
## Python class representation of table storing module data
|
||||
class ModuleTable(Table):
|
||||
# TRICK: use file ID as the part before '.'
|
||||
_ID_STEP_ = 0.00000001
|
||||
_ID_MAX_ = 0.99999999
|
||||
_COLUMN_ = '''
|
||||
ID REAL PRIMARY KEY,
|
||||
Model INTEGER NOT NULL,
|
||||
Value1 TEXT NOT NULL,
|
||||
Value2 TEXT,
|
||||
Value3 TEXT,
|
||||
Scope1 TEXT,
|
||||
Scope2 TEXT,
|
||||
BelongsToItem REAL NOT NULL,
|
||||
StartLine INTEGER NOT NULL,
|
||||
StartColumn INTEGER NOT NULL,
|
||||
EndLine INTEGER NOT NULL,
|
||||
EndColumn INTEGER NOT NULL,
|
||||
Enabled INTEGER DEFAULT 0
|
||||
'''
|
||||
# used as table end flag, in case the changes to database is not committed to db file
|
||||
_DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1"
|
||||
|
||||
## Constructor
|
||||
def __init__(self, Cursor, Name='Inf', IdBase=0, Temporary=False):
|
||||
Table.__init__(self, Cursor, Name, IdBase, Temporary)
|
||||
|
||||
## Insert a record into table Inf
|
||||
#
|
||||
# @param Model: Model of a Inf item
|
||||
# @param Value1: Value1 of a Inf item
|
||||
# @param Value2: Value2 of a Inf item
|
||||
# @param Value3: Value3 of a Inf item
|
||||
# @param Scope1: Arch of a Inf item
|
||||
# @param Scope2 Platform os a Inf item
|
||||
# @param BelongsToItem: The item belongs to which another item
|
||||
# @param StartLine: StartLine of a Inf item
|
||||
# @param StartColumn: StartColumn of a Inf item
|
||||
# @param EndLine: EndLine of a Inf item
|
||||
# @param EndColumn: EndColumn of a Inf item
|
||||
# @param Enabled: If this item enabled
|
||||
#
|
||||
def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON',
|
||||
BelongsToItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0):
|
||||
(Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))
|
||||
return Table.Insert(
|
||||
self,
|
||||
Model,
|
||||
Value1,
|
||||
Value2,
|
||||
Value3,
|
||||
Scope1,
|
||||
Scope2,
|
||||
BelongsToItem,
|
||||
StartLine,
|
||||
StartColumn,
|
||||
EndLine,
|
||||
EndColumn,
|
||||
Enabled
|
||||
)
|
||||
|
||||
## Query table
|
||||
#
|
||||
# @param Model: The Model of Record
|
||||
# @param Arch: The Arch attribute of Record
|
||||
# @param Platform The Platform attribute of Record
|
||||
#
|
||||
# @retval: A recordSet of all found records
|
||||
#
|
||||
def Query(self, Model, Arch=None, Platform=None):
|
||||
ConditionString = "Model=%s AND Enabled>=0" % Model
|
||||
ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"
|
||||
|
||||
if Arch != None and Arch != 'COMMON':
|
||||
ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch
|
||||
if Platform != None and Platform != 'COMMON':
|
||||
ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Platform
|
||||
|
||||
SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)
|
||||
return self.Exec(SqlCommand)
|
||||
|
||||
## Python class representation of table storing package data
|
||||
class PackageTable(Table):
|
||||
_ID_STEP_ = 0.00000001
|
||||
_ID_MAX_ = 0.99999999
|
||||
_COLUMN_ = '''
|
||||
ID REAL PRIMARY KEY,
|
||||
Model INTEGER NOT NULL,
|
||||
Value1 TEXT NOT NULL,
|
||||
Value2 TEXT,
|
||||
Value3 TEXT,
|
||||
Scope1 TEXT,
|
||||
Scope2 TEXT,
|
||||
BelongsToItem REAL NOT NULL,
|
||||
StartLine INTEGER NOT NULL,
|
||||
StartColumn INTEGER NOT NULL,
|
||||
EndLine INTEGER NOT NULL,
|
||||
EndColumn INTEGER NOT NULL,
|
||||
Enabled INTEGER DEFAULT 0
|
||||
'''
|
||||
# used as table end flag, in case the changes to database is not committed to db file
|
||||
_DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1"
|
||||
|
||||
## Constructor
|
||||
def __init__(self, Cursor, Name='Dec', IdBase=0, Temporary=False):
|
||||
Table.__init__(self, Cursor, Name, IdBase, Temporary)
|
||||
|
||||
## Insert table
|
||||
#
|
||||
# Insert a record into table Dec
|
||||
#
|
||||
# @param Model: Model of a Dec item
|
||||
# @param Value1: Value1 of a Dec item
|
||||
# @param Value2: Value2 of a Dec item
|
||||
# @param Value3: Value3 of a Dec item
|
||||
# @param Scope1: Arch of a Dec item
|
||||
# @param Scope2: Module type of a Dec item
|
||||
# @param BelongsToItem: The item belongs to which another item
|
||||
# @param StartLine: StartLine of a Dec item
|
||||
# @param StartColumn: StartColumn of a Dec item
|
||||
# @param EndLine: EndLine of a Dec item
|
||||
# @param EndColumn: EndColumn of a Dec item
|
||||
# @param Enabled: If this item enabled
|
||||
#
|
||||
def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON',
|
||||
BelongsToItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=0):
|
||||
(Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))
|
||||
return Table.Insert(
|
||||
self,
|
||||
Model,
|
||||
Value1,
|
||||
Value2,
|
||||
Value3,
|
||||
Scope1,
|
||||
Scope2,
|
||||
BelongsToItem,
|
||||
StartLine,
|
||||
StartColumn,
|
||||
EndLine,
|
||||
EndColumn,
|
||||
Enabled
|
||||
)
|
||||
|
||||
## Query table
|
||||
#
|
||||
# @param Model: The Model of Record
|
||||
# @param Arch: The Arch attribute of Record
|
||||
#
|
||||
# @retval: A recordSet of all found records
|
||||
#
|
||||
def Query(self, Model, Arch=None):
|
||||
ConditionString = "Model=%s AND Enabled>=0" % Model
|
||||
ValueString = "Value1,Value2,Value3,Scope1,ID,StartLine"
|
||||
|
||||
if Arch != None and Arch != 'COMMON':
|
||||
ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Arch
|
||||
|
||||
SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)
|
||||
return self.Exec(SqlCommand)
|
||||
|
||||
## Python class representation of table storing platform data
|
||||
class PlatformTable(Table):
|
||||
_ID_STEP_ = 0.00000001
|
||||
_ID_MAX_ = 0.99999999
|
||||
_COLUMN_ = '''
|
||||
ID REAL PRIMARY KEY,
|
||||
Model INTEGER NOT NULL,
|
||||
Value1 TEXT NOT NULL,
|
||||
Value2 TEXT,
|
||||
Value3 TEXT,
|
||||
Scope1 TEXT,
|
||||
Scope2 TEXT,
|
||||
BelongsToItem REAL NOT NULL,
|
||||
FromItem REAL NOT NULL,
|
||||
StartLine INTEGER NOT NULL,
|
||||
StartColumn INTEGER NOT NULL,
|
||||
EndLine INTEGER NOT NULL,
|
||||
EndColumn INTEGER NOT NULL,
|
||||
Enabled INTEGER DEFAULT 0
|
||||
'''
|
||||
# used as table end flag, in case the changes to database is not committed to db file
|
||||
_DUMMY_ = "-1, -1, '====', '====', '====', '====', '====', -1, -1, -1, -1, -1, -1, -1"
|
||||
|
||||
## Constructor
|
||||
def __init__(self, Cursor, Name='Dsc', IdBase=0, Temporary=False):
|
||||
Table.__init__(self, Cursor, Name, IdBase, Temporary)
|
||||
|
||||
## Insert table
|
||||
#
|
||||
# Insert a record into table Dsc
|
||||
#
|
||||
# @param Model: Model of a Dsc item
|
||||
# @param Value1: Value1 of a Dsc item
|
||||
# @param Value2: Value2 of a Dsc item
|
||||
# @param Value3: Value3 of a Dsc item
|
||||
# @param Scope1: Arch of a Dsc item
|
||||
# @param Scope2: Module type of a Dsc item
|
||||
# @param BelongsToItem: The item belongs to which another item
|
||||
# @param FromItem: The item belongs to which dsc file
|
||||
# @param StartLine: StartLine of a Dsc item
|
||||
# @param StartColumn: StartColumn of a Dsc item
|
||||
# @param EndLine: EndLine of a Dsc item
|
||||
# @param EndColumn: EndColumn of a Dsc item
|
||||
# @param Enabled: If this item enabled
|
||||
#
|
||||
def Insert(self, Model, Value1, Value2, Value3, Scope1='COMMON', Scope2='COMMON', BelongsToItem=-1,
|
||||
FromItem=-1, StartLine=-1, StartColumn=-1, EndLine=-1, EndColumn=-1, Enabled=1):
|
||||
(Value1, Value2, Value3, Scope1, Scope2) = ConvertToSqlString((Value1, Value2, Value3, Scope1, Scope2))
|
||||
return Table.Insert(
|
||||
self,
|
||||
Model,
|
||||
Value1,
|
||||
Value2,
|
||||
Value3,
|
||||
Scope1,
|
||||
Scope2,
|
||||
BelongsToItem,
|
||||
FromItem,
|
||||
StartLine,
|
||||
StartColumn,
|
||||
EndLine,
|
||||
EndColumn,
|
||||
Enabled
|
||||
)
|
||||
|
||||
## Query table
|
||||
#
|
||||
# @param Model: The Model of Record
|
||||
# @param Scope1: Arch of a Dsc item
|
||||
# @param Scope2: Module type of a Dsc item
|
||||
# @param BelongsToItem: The item belongs to which another item
|
||||
# @param FromItem: The item belongs to which dsc file
|
||||
#
|
||||
# @retval: A recordSet of all found records
|
||||
#
|
||||
def Query(self, Model, Scope1=None, Scope2=None, BelongsToItem=None, FromItem=None):
|
||||
ConditionString = "Model=%s AND Enabled>=0" % Model
|
||||
ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"
|
||||
|
||||
if Scope1 != None and Scope1 != 'COMMON':
|
||||
ConditionString += " AND (Scope1='%s' OR Scope1='COMMON')" % Scope1
|
||||
if Scope2 != None and Scope2 != 'COMMON':
|
||||
ConditionString += " AND (Scope2='%s' OR Scope2='COMMON' OR Scope2='DEFAULT')" % Scope2
|
||||
|
||||
if BelongsToItem != None:
|
||||
ConditionString += " AND BelongsToItem=%s" % BelongsToItem
|
||||
else:
|
||||
ConditionString += " AND BelongsToItem<0"
|
||||
|
||||
if FromItem != None:
|
||||
ConditionString += " AND FromItem=%s" % FromItem
|
||||
|
||||
SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)
|
||||
return self.Exec(SqlCommand)
|
||||
|
2274
BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
Normal file
2274
BaseTools/Source/Python/Workspace/WorkspaceDatabase.py
Normal file
File diff suppressed because it is too large
Load Diff
0
BaseTools/Source/Python/Workspace/__init__.py
Normal file
0
BaseTools/Source/Python/Workspace/__init__.py
Normal file
Reference in New Issue
Block a user