diff options
author | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-10-29 06:59:30 +0000 |
---|---|---|
committer | lgao4 <lgao4@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-10-29 06:59:30 +0000 |
commit | 0d2711a69397d2971079121df4326d84736c181e (patch) | |
tree | 0d3c93b9db1df5a30a0d15ec9d70c75768c1f67c /BaseTools/Source/Python/Workspace | |
parent | 421fb3b504cfe18033c49a40fcd46bab45a0fb50 (diff) | |
download | edk2-0d2711a69397d2971079121df4326d84736c181e.tar.gz edk2-0d2711a69397d2971079121df4326d84736c181e.tar.bz2 edk2-0d2711a69397d2971079121df4326d84736c181e.zip |
Sync BaseTools Trunk (version r2387) to EDKII main trunk.
Signed-off-by: lgao4
Reviewed-by: gikidy
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12602 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'BaseTools/Source/Python/Workspace')
-rw-r--r-- | BaseTools/Source/Python/Workspace/MetaDataTable.py | 31 | ||||
-rw-r--r-- | BaseTools/Source/Python/Workspace/MetaFileParser.py | 1126 | ||||
-rw-r--r-- | BaseTools/Source/Python/Workspace/MetaFileTable.py | 106 | ||||
-rw-r--r-- | BaseTools/Source/Python/Workspace/WorkspaceDatabase.py | 509 |
4 files changed, 1060 insertions, 712 deletions
diff --git a/BaseTools/Source/Python/Workspace/MetaDataTable.py b/BaseTools/Source/Python/Workspace/MetaDataTable.py index 64f0480c37..34ef4903df 100644 --- a/BaseTools/Source/Python/Workspace/MetaDataTable.py +++ b/BaseTools/Source/Python/Workspace/MetaDataTable.py @@ -140,6 +140,10 @@ class Table(object): def SetEndFlag(self):
self.Exec("insert into %s values(%s)" % (self.Table, self._DUMMY_))
+ #
+ # Need to execution commit for table data changed.
+ #
+ self.Cur.connection.commit()
def IsIntegral(self):
Result = self.Exec("select min(ID) from %s" % (self.Table))
@@ -147,6 +151,9 @@ class Table(object): return False
return True
+ def GetAll(self):
+ return self.Exec("select * from %s where ID > 0 order by ID" % (self.Table))
+
## TableFile
#
# This class defined a table used for file
@@ -198,19 +205,15 @@ class TableFile(Table): #
# @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, '', [], [], [])
+ def InsertFile(self, File, Model):
return self.Insert(
- Name,
- Ext,
- Filepath,
- FileFullPath,
- Model,
- TimeStamp
- )
+ File.Name,
+ File.Ext,
+ File.Dir,
+ File.Path,
+ Model,
+ File.TimeStamp
+ )
## Get ID of a given file
#
@@ -218,8 +221,8 @@ class TableFile(Table): #
# @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)
+ def GetFileId(self, File):
+ QueryScript = "select ID from %s where FullPath = '%s'" % (self.Table, str(File))
RecordList = self.Exec(QueryScript)
if len(RecordList) == 0:
return None
diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py index 4bad21298a..bfa7054396 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -15,14 +15,75 @@ # Import Modules # import os +import re import time import copy import Common.EdkLogger as EdkLogger +import Common.GlobalData as GlobalData + from CommonDataClass.DataClass import * from Common.DataType import * from Common.String import * -from Common.Misc import Blist, GuidStructureStringToGuidString, CheckPcdDatum +from Common.Misc import GuidStructureStringToGuidString, CheckPcdDatum, PathClass, AnalyzePcdData +from Common.Expression import * +from CommonDataClass.Exceptions import * + +from MetaFileTable import MetaFileStorage + +## A decorator used to parse macro definition +def ParseMacro(Parser): + def MacroParser(self): + Match = gMacroDefPattern.match(self._CurrentLine) + if not Match: + # Not 'DEFINE/EDK_GLOBAL' statement, call decorated method + Parser(self) + return + + TokenList = GetSplitValueList(self._CurrentLine[Match.end(1):], TAB_EQUAL_SPLIT, 1) + # Syntax check + if not TokenList[0]: + EdkLogger.error('Parser', FORMAT_INVALID, "No macro name given", + ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) + if len(TokenList) < 2: + TokenList.append('') + + Type = Match.group(1) + Name, Value = TokenList + # Global macros can be only defined via environment variable + if Name in GlobalData.gGlobalDefines: + EdkLogger.error('Parser', FORMAT_INVALID, "%s can only be defined via environment variable" % Name, + ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) + # Only upper case letters, digit and '_' are allowed + if not gMacroNamePattern.match(Name): + EdkLogger.error('Parser', FORMAT_INVALID, "The macro name must be in the pattern [A-Z][A-Z0-9_]*", + ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) + + self._ItemType = self.DataType[Type] + # DEFINE defined macros + if self._ItemType == MODEL_META_DATA_DEFINE: + if self._SectionType == MODEL_META_DATA_HEADER: + self._FileLocalMacros[Name] = Value + else: + SectionDictKey = self._SectionType, self._Scope[0][0], self._Scope[0][1] + if SectionDictKey not in self._SectionsMacroDict: + self._SectionsMacroDict[SectionDictKey] = {} + SectionLocalMacros = self._SectionsMacroDict[SectionDictKey] + SectionLocalMacros[Name] = Value + # EDK_GLOBAL defined macros + elif type(self) != DscParser: + EdkLogger.error('Parser', FORMAT_INVALID, "EDK_GLOBAL can only be used in .dsc file", + ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) + elif self._SectionType != MODEL_META_DATA_HEADER: + EdkLogger.error('Parser', FORMAT_INVALID, "EDK_GLOBAL can only be used under [Defines] section", + ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) + elif (Name in self._FileLocalMacros) and (self._FileLocalMacros[Name] != Value): + EdkLogger.error('Parser', FORMAT_INVALID, "EDK_GLOBAL defined a macro with the same name and different value as one defined by 'DEFINE'", + ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) + + self._ValueList = [Type, Name, Value] + + return MacroParser ## Base class of parser # @@ -73,23 +134,21 @@ class MetaFileParser(object): # @param Owner Owner ID (for sub-section parsing) # @param From ID from which the data comes (for !INCLUDE directive) # - def __init__(self, FilePath, FileType, Table, Macros=None, Owner=-1, From=-1): - # prevent re-initialization - if hasattr(self, "_Table"): - return + def __init__(self, FilePath, FileType, Table, Owner=-1, From=-1): self._Table = Table + self._RawTable = Table self._FileType = FileType self.MetaFile = FilePath - self._FileDir = os.path.dirname(self.MetaFile) - self._Macros = copy.copy(Macros) - self._Macros["WORKSPACE"] = os.environ["WORKSPACE"] + self._FileDir = self.MetaFile.Dir + self._Defines = {} + self._FileLocalMacros = {} + self._SectionsMacroDict = {} # for recursive parsing - self._Owner = Owner + self._Owner = [Owner] self._From = From # parsr status for parsing - self._Content = None self._ValueList = ['', '', '', '', ''] self._Scope = [] self._LineIndex = 0 @@ -99,9 +158,13 @@ class MetaFileParser(object): self._InSubsection = False self._SubsectionType = MODEL_UNKNOWN self._SubsectionName = '' + self._ItemType = MODEL_UNKNOWN self._LastItem = -1 self._Enabled = 0 self._Finished = False + self._PostProcessed = False + # Different version of meta-file has different way to parse. + self._Version = 0 ## Store the parsed data in table def _Store(self, *Args): @@ -111,6 +174,10 @@ class MetaFileParser(object): def Start(self): raise NotImplementedError + ## Notify a post-process is needed + def DoPostProcess(self): + self._PostProcessed = False + ## Set parsing complete flag in both class and table def _Done(self): self._Finished = True @@ -118,15 +185,8 @@ class MetaFileParser(object): if self._From == -1: self._Table.SetEndFlag() - ## Return the table containg parsed data - # - # If the parse complete flag is not set, this method will try to parse the - # file before return the table - # - def _GetTable(self): - if not self._Finished: - self.Start() - return self._Table + def _PostProcess(self): + self._PostProcessed = True ## Get the parse complete flag def _GetFinished(self): @@ -138,12 +198,30 @@ class MetaFileParser(object): ## Use [] style to query data in table, just for readability # - # DataInfo = [data_type, scope1(arch), scope2(platform,moduletype)] + # DataInfo = [data_type, scope1(arch), scope2(platform/moduletype)] # def __getitem__(self, DataInfo): if type(DataInfo) != type(()): DataInfo = (DataInfo,) - return self.Table.Query(*DataInfo) + + # Parse the file first, if necessary + if not self._Finished: + if self._RawTable.IsIntegrity(): + self._Finished = True + else: + self._Table = self._RawTable + self._PostProcessed = False + self.Start() + + # No specific ARCH or Platform given, use raw data + if self._RawTable and (len(DataInfo) == 1 or DataInfo[1] == None): + return self._RawTable.Query(*DataInfo) + + # Do post-process if necessary + if not self._PostProcessed: + self._PostProcess() + + return self._Table.Query(*DataInfo) ## Data parser for the common format in different type of file # @@ -151,6 +229,7 @@ class MetaFileParser(object): # # xxx1 | xxx2 | xxx3 # + @ParseMacro def _CommonParser(self): TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT) self._ValueList[0:len(TokenList)] = TokenList @@ -159,15 +238,14 @@ class MetaFileParser(object): # # Only path can have macro used. So we need to replace them before use. # + @ParseMacro def _PathParser(self): TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT) self._ValueList[0:len(TokenList)] = TokenList - if len(self._Macros) > 0: - for Index in range(0, len(self._ValueList)): - Value = self._ValueList[Index] - if Value == None or Value == '': - continue - self._ValueList[Index] = NormPath(Value, self._Macros) + # Don't do macro replacement for dsc file at this point + if type(self) != DscParser: + Macros = self._Macros + self._ValueList = [ReplaceMacro(Value, Macros) for Value in self._ValueList] ## Skip unsupported data def _Skip(self): @@ -217,47 +295,47 @@ class MetaFileParser(object): if 'COMMON' in ArchList and len(ArchList) > 1: EdkLogger.error('Parser', FORMAT_INVALID, "'common' ARCH must not be used with specific ARCHs", File=self.MetaFile, Line=self._LineIndex+1, ExtraData=self._CurrentLine) + # If the section information is needed later, it should be stored in database + self._ValueList[0] = self._SectionName ## [defines] section parser + @ParseMacro def _DefineParser(self): TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1) - self._ValueList[0:len(TokenList)] = TokenList - if self._ValueList[1] == '': - EdkLogger.error('Parser', FORMAT_INVALID, "No value specified", + self._ValueList[1:len(TokenList)] = TokenList + if not self._ValueList[1]: + EdkLogger.error('Parser', FORMAT_INVALID, "No name specified", ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) - - ## DEFINE name=value parser - def _MacroParser(self): - TokenList = GetSplitValueList(self._CurrentLine, ' ', 1) - MacroType = TokenList[0] - if len(TokenList) < 2 or TokenList[1] == '': - EdkLogger.error('Parser', FORMAT_INVALID, "No macro name/value given", - ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) - TokenList = GetSplitValueList(TokenList[1], TAB_EQUAL_SPLIT, 1) - if TokenList[0] == '': - EdkLogger.error('Parser', FORMAT_INVALID, "No macro name given", + if not self._ValueList[2]: + EdkLogger.error('Parser', FORMAT_INVALID, "No value specified", ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) - # Macros defined in the command line override ones defined in the meta-data file - if not TokenList[0] in self._Macros: - if len(TokenList) == 1: - self._Macros[TokenList[0]] = '' - else: - # keep the macro definition for later use - self._Macros[TokenList[0]] = ReplaceMacro(TokenList[1], self._Macros, False) + Name, Value = self._ValueList[1], self._ValueList[2] + # Sometimes, we need to make differences between EDK and EDK2 modules + if Name == 'INF_VERSION': + try: + self._Version = int(Value, 0) + except: + EdkLogger.error('Parser', FORMAT_INVALID, "Invalid version number", + ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) - return TokenList[0], self._Macros[TokenList[0]] + Value = ReplaceMacro(Value, self._Macros) + if type(self) == InfParser and self._Version < 0x00010005: + # EDK module allows using defines as macros + self._FileLocalMacros[Name] = Value + self._Defines[Name] = Value ## [BuildOptions] section parser + @ParseMacro def _BuildOptionParser(self): TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1) TokenList2 = GetSplitValueList(TokenList[0], ':', 1) if len(TokenList2) == 2: - self._ValueList[0] = TokenList2[0] # toolchain family - self._ValueList[1] = TokenList2[1] # keys + self._ValueList[0] = TokenList2[0] # toolchain family + self._ValueList[1] = TokenList2[1] # keys else: self._ValueList[1] = TokenList[0] - if len(TokenList) == 2: # value + if len(TokenList) == 2 and type(self) != DscParser: # value self._ValueList[2] = ReplaceMacro(TokenList[1], self._Macros) if self._ValueList[1].count('_') != 4: @@ -270,9 +348,27 @@ class MetaFileParser(object): Line=self._LineIndex+1 ) + def _GetMacros(self): + Macros = {} + Macros.update(self._FileLocalMacros) + Macros.update(self._GetApplicableSectionMacro()) + return Macros + + + ## Get section Macros that are applicable to current line, which may come from other sections + ## that share the same name while scope is wider + def _GetApplicableSectionMacro(self): + Macros = {} + + for SectionType, Scope1, Scope2 in self._SectionsMacroDict: + if (SectionType == self._SectionType) and (Scope1 == self._Scope[0][0] or Scope1 == "COMMON") and (Scope2 == self._Scope[0][1] or Scope2 == "COMMON"): + Macros.update(self._SectionsMacroDict[(SectionType, Scope1, Scope2)]) + + return Macros + _SectionParser = {} - Table = property(_GetTable) Finished = property(_GetFinished, _SetFinished) + _Macros = property(_GetMacros) ## INF file parser class @@ -287,6 +383,7 @@ class InfParser(MetaFileParser): DataType = { TAB_UNKNOWN.upper() : MODEL_UNKNOWN, TAB_INF_DEFINES.upper() : MODEL_META_DATA_HEADER, + TAB_DSC_DEFINES_DEFINE : MODEL_META_DATA_DEFINE, TAB_BUILD_OPTIONS.upper() : MODEL_META_DATA_BUILD_OPTION, TAB_INCLUDES.upper() : MODEL_EFI_INCLUDE, TAB_LIBRARIES.upper() : MODEL_EFI_LIBRARY_INSTANCE, @@ -316,26 +413,30 @@ class InfParser(MetaFileParser): # @param Table Database used to retrieve module/package information # @param Macros Macros used for replacement in file # - def __init__(self, FilePath, FileType, Table, Macros=None): - MetaFileParser.__init__(self, FilePath, FileType, Table, Macros) + def __init__(self, FilePath, FileType, Table): + # prevent re-initialization + if hasattr(self, "_Table"): + return + MetaFileParser.__init__(self, FilePath, FileType, Table) ## Parser starter def Start(self): NmakeLine = '' + Content = '' try: - self._Content = open(self.MetaFile, 'r').readlines() + Content = open(str(self.MetaFile), 'r').readlines() except: EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile) # parse the file line by line IsFindBlockComment = False - for Index in range(0, len(self._Content)): + for Index in range(0, len(Content)): # skip empty, commented, block commented lines - Line = CleanString(self._Content[Index], AllowCppStyleComment=True) + Line = CleanString(Content[Index], AllowCppStyleComment=True) NextLine = '' - if Index + 1 < len(self._Content): - NextLine = CleanString(self._Content[Index + 1]) + if Index + 1 < len(Content): + NextLine = CleanString(Content[Index + 1]) if Line == '': continue if Line.find(DataType.TAB_COMMENT_EDK_START) > -1: @@ -353,6 +454,29 @@ class InfParser(MetaFileParser): # section header if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END: self._SectionHeaderParser() + # Check invalid sections + if self._Version < 0x00010005: + if self._SectionType in [MODEL_META_DATA_BUILD_OPTION, + MODEL_EFI_LIBRARY_CLASS, + MODEL_META_DATA_PACKAGE, + MODEL_PCD_FIXED_AT_BUILD, + MODEL_PCD_PATCHABLE_IN_MODULE, + MODEL_PCD_FEATURE_FLAG, + MODEL_PCD_DYNAMIC_EX, + MODEL_PCD_DYNAMIC, + MODEL_EFI_GUID, + MODEL_EFI_PROTOCOL, + MODEL_EFI_PPI, + MODEL_META_DATA_USER_EXTENSION]: + EdkLogger.error('Parser', FORMAT_INVALID, + "Section [%s] is not allowed in inf file without version" % (self._SectionName), + ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) + elif self._SectionType in [MODEL_EFI_INCLUDE, + MODEL_EFI_LIBRARY_INSTANCE, + MODEL_META_DATA_NMAKE]: + EdkLogger.error('Parser', FORMAT_INVALID, + "Section [%s] is not allowed in inf file with version 0x%08x" % (self._SectionName, self._Version), + ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) continue # merge two lines specified by '\' in section NMAKE elif self._SectionType == MODEL_META_DATA_NMAKE: @@ -370,10 +494,6 @@ class InfParser(MetaFileParser): else: self._CurrentLine = NmakeLine + Line NmakeLine = '' - elif Line.upper().startswith('DEFINE '): - # file private macros - self._MacroParser() - continue # section content self._ValueList = ['','',''] @@ -392,7 +512,7 @@ class InfParser(MetaFileParser): self._ValueList[2], Arch, Platform, - self._Owner, + self._Owner[-1], self._LineIndex+1, -1, self._LineIndex+1, @@ -411,9 +531,13 @@ class InfParser(MetaFileParser): def _IncludeParser(self): TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT) self._ValueList[0:len(TokenList)] = TokenList - if len(self._Macros) > 0: + Macros = self._Macros + if Macros: for Index in range(0, len(self._ValueList)): Value = self._ValueList[Index] + if not Value: + continue + if Value.upper().find('$(EFI_SOURCE)\Edk'.upper()) > -1 or Value.upper().find('$(EFI_SOURCE)/Edk'.upper()) > -1: Value = '$(EDK_SOURCE)' + Value[17:] if Value.find('$(EFI_SOURCE)') > -1 or Value.find('$(EDK_SOURCE)') > -1: @@ -425,34 +549,30 @@ class InfParser(MetaFileParser): else: Value = '$(EFI_SOURCE)/' + Value - if Value == None or Value == '': - continue - self._ValueList[Index] = NormPath(Value, self._Macros) + self._ValueList[Index] = ReplaceMacro(Value, Macros) ## Parse [Sources] section # # Only path can have macro used. So we need to replace them before use. # + @ParseMacro def _SourceFileParser(self): TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT) self._ValueList[0:len(TokenList)] = TokenList + Macros = self._Macros # For Acpi tables, remove macro like ' TABLE_NAME=Sata1' - if 'COMPONENT_TYPE' in self._Macros: - if self._Macros['COMPONENT_TYPE'].upper() == 'ACPITABLE': + if 'COMPONENT_TYPE' in Macros: + if self._Defines['COMPONENT_TYPE'].upper() == 'ACPITABLE': self._ValueList[0] = GetSplitValueList(self._ValueList[0], ' ', 1)[0] - if self._Macros['BASE_NAME'] == 'Microcode': + if self._Defines['BASE_NAME'] == 'Microcode': pass - if len(self._Macros) > 0: - for Index in range(0, len(self._ValueList)): - Value = self._ValueList[Index] - if Value == None or Value == '': - continue - self._ValueList[Index] = NormPath(Value, self._Macros) + self._ValueList = [ReplaceMacro(Value, Macros) for Value in self._ValueList] ## Parse [Binaries] section # # Only path can have macro used. So we need to replace them before use. # + @ParseMacro def _BinaryFileParser(self): TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 2) if len(TokenList) < 2: @@ -468,27 +588,19 @@ class InfParser(MetaFileParser): ExtraData=self._CurrentLine + " (<FileType> | <FilePath> [| <Target>])", File=self.MetaFile, Line=self._LineIndex+1) self._ValueList[0:len(TokenList)] = TokenList - self._ValueList[1] = NormPath(self._ValueList[1], self._Macros) + self._ValueList[1] = ReplaceMacro(self._ValueList[1], self._Macros) - ## [defines] section parser - def _DefineParser(self): - TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1) - self._ValueList[0:len(TokenList)] = TokenList - if self._ValueList[1] == '': - EdkLogger.error('Parser', FORMAT_INVALID, "No value specified", - ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) - self._Macros[TokenList[0]] = ReplaceMacro(TokenList[1], self._Macros, False) - - ## [nmake] section parser (EDK.x style only) + ## [nmake] section parser (Edk.x style only) def _NmakeParser(self): TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1) self._ValueList[0:len(TokenList)] = TokenList # remove macros - self._ValueList[1] = ReplaceMacro(self._ValueList[1], self._Macros, False) + self._ValueList[1] = ReplaceMacro(self._ValueList[1], self._Macros) # remove self-reference in macro setting #self._ValueList[1] = ReplaceMacro(self._ValueList[1], {self._ValueList[0]:''}) ## [FixedPcd], [FeaturePcd], [PatchPcd], [Pcd] and [PcdEx] sections parser + @ParseMacro def _PcdParser(self): TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1) ValueList = GetSplitValueList(TokenList[0], TAB_SPLIT) @@ -503,6 +615,7 @@ class InfParser(MetaFileParser): EdkLogger.error('Parser', FORMAT_INVALID, "No token space GUID or PCD name specified", ExtraData=self._CurrentLine + " (<TokenSpaceGuidCName>.<PcdCName>)", File=self.MetaFile, Line=self._LineIndex+1) + # if value are 'True', 'true', 'TRUE' or 'False', 'false', 'FALSE', replace with integer 1 or 0. if self._ValueList[2] != '': InfPcdValueList = GetSplitValueList(TokenList[1], TAB_VALUE_SPLIT, 1) @@ -512,18 +625,19 @@ class InfParser(MetaFileParser): self._ValueList[2] = TokenList[1].replace(InfPcdValueList[0], '0', 1); ## [depex] section parser + @ParseMacro def _DepexParser(self): self._ValueList[0:1] = [self._CurrentLine] _SectionParser = { MODEL_UNKNOWN : MetaFileParser._Skip, - MODEL_META_DATA_HEADER : _DefineParser, + MODEL_META_DATA_HEADER : MetaFileParser._DefineParser, MODEL_META_DATA_BUILD_OPTION : MetaFileParser._BuildOptionParser, - MODEL_EFI_INCLUDE : _IncludeParser, # for EDK.x modules - MODEL_EFI_LIBRARY_INSTANCE : MetaFileParser._CommonParser, # for EDK.x modules + MODEL_EFI_INCLUDE : _IncludeParser, # for Edk.x modules + MODEL_EFI_LIBRARY_INSTANCE : MetaFileParser._CommonParser, # for Edk.x modules MODEL_EFI_LIBRARY_CLASS : MetaFileParser._PathParser, MODEL_META_DATA_PACKAGE : MetaFileParser._PathParser, - MODEL_META_DATA_NMAKE : _NmakeParser, # for EDK.x modules + MODEL_META_DATA_NMAKE : _NmakeParser, # for Edk.x modules MODEL_PCD_FIXED_AT_BUILD : _PcdParser, MODEL_PCD_PATCHABLE_IN_MODULE : _PcdParser, MODEL_PCD_FEATURE_FLAG : _PcdParser, @@ -566,6 +680,8 @@ class DscParser(MetaFileParser): TAB_COMPONENTS.upper() : MODEL_META_DATA_COMPONENT, TAB_COMPONENTS_SOURCE_OVERRIDE_PATH.upper() : MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH, TAB_DSC_DEFINES.upper() : MODEL_META_DATA_HEADER, + TAB_DSC_DEFINES_DEFINE : MODEL_META_DATA_DEFINE, + TAB_DSC_DEFINES_EDKGLOBAL : MODEL_META_DATA_GLOBAL_DEFINE, TAB_INCLUDE.upper() : MODEL_META_DATA_INCLUDE, TAB_IF.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_IF, TAB_IF_DEF.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF, @@ -575,37 +691,26 @@ class DscParser(MetaFileParser): TAB_END_IF.upper() : MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF, } - # sections which allow "!include" directive - _IncludeAllowedSection = [ - TAB_COMMON_DEFINES.upper(), - TAB_LIBRARIES.upper(), - TAB_LIBRARY_CLASSES.upper(), - TAB_SKUIDS.upper(), - TAB_COMPONENTS.upper(), - TAB_BUILD_OPTIONS.upper(), - TAB_PCDS_FIXED_AT_BUILD_NULL.upper(), - TAB_PCDS_PATCHABLE_IN_MODULE_NULL.upper(), - TAB_PCDS_FEATURE_FLAG_NULL.upper(), - TAB_PCDS_DYNAMIC_DEFAULT_NULL.upper(), - TAB_PCDS_DYNAMIC_HII_NULL.upper(), - TAB_PCDS_DYNAMIC_VPD_NULL.upper(), - TAB_PCDS_DYNAMIC_EX_DEFAULT_NULL.upper(), - TAB_PCDS_DYNAMIC_EX_HII_NULL.upper(), - TAB_PCDS_DYNAMIC_EX_VPD_NULL.upper(), - ] - - # operators which can be used in "!if/!ifdef/!ifndef" directives - _OP_ = { - "!" : lambda a: not a, - "!=" : lambda a,b: a!=b, - "==" : lambda a,b: a==b, - ">" : lambda a,b: a>b, - "<" : lambda a,b: a<b, - "=>" : lambda a,b: a>=b, - ">=" : lambda a,b: a>=b, - "<=" : lambda a,b: a<=b, - "=<" : lambda a,b: a<=b, - } + # Valid names in define section + DefineKeywords = [ + "DSC_SPECIFICATION", + "PLATFORM_NAME", + "PLATFORM_GUID", + "PLATFORM_VERSION", + "SKUID_IDENTIFIER", + "SUPPORTED_ARCHITECTURES", + "BUILD_TARGETS", + "OUTPUT_DIRECTORY", + "FLASH_DEFINITION", + "BUILD_NUMBER", + "RFC_LANGUAGES", + "ISO_LANGUAGES", + "TIME_STAMP_FILE", + "VPD_TOOL_GUID", + "FIX_LOAD_TOP_MEMORY_ADDRESS" + ] + + SymbolPattern = ValueExpression.SymbolPattern ## Constructor of DscParser # @@ -618,162 +723,99 @@ class DscParser(MetaFileParser): # @param Owner Owner ID (for sub-section parsing) # @param From ID from which the data comes (for !INCLUDE directive) # - def __init__(self, FilePath, FileType, Table, Macros=None, Owner=-1, From=-1): - MetaFileParser.__init__(self, FilePath, FileType, Table, Macros, Owner, From) + def __init__(self, FilePath, FileType, Table, Owner=-1, From=-1): + # prevent re-initialization + if hasattr(self, "_Table"): + return + MetaFileParser.__init__(self, FilePath, FileType, Table, Owner, From) + self._Version = 0x00010005 # Only EDK2 dsc file is supported # to store conditional directive evaluation result - self._Eval = Blist() + self._DirectiveStack = [] + self._DirectiveEvalStack = [] + self._Enabled = 1 + + # Final valid replacable symbols + self._Symbols = {} + # + # Map the ID between the original table and new table to track + # the owner item + # + self._IdMapping = {-1:-1} ## Parser starter def Start(self): + Content = '' try: - if self._Content == None: - self._Content = open(self.MetaFile, 'r').readlines() + Content = open(str(self.MetaFile), 'r').readlines() except: EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile) - for Index in range(0, len(self._Content)): - Line = CleanString(self._Content[Index]) + for Index in range(0, len(Content)): + Line = CleanString(Content[Index]) # skip empty line if Line == '': continue + self._CurrentLine = Line self._LineIndex = Index - if self._InSubsection and self._Owner == -1: - self._Owner = self._LastItem + if self._InSubsection and self._Owner[-1] == -1: + self._Owner.append(self._LastItem) # section header if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END: - self._SectionHeaderParser() - continue + self._SectionType = MODEL_META_DATA_SECTION_HEADER # subsection ending - elif Line[0] == '}': + elif Line[0] == '}' and self._InSubsection: self._InSubsection = False self._SubsectionType = MODEL_UNKNOWN self._SubsectionName = '' - self._Owner = -1 + self._Owner.pop() continue # subsection header elif Line[0] == TAB_OPTION_START and Line[-1] == TAB_OPTION_END: - self._SubsectionHeaderParser() - continue + self._SubsectionType = MODEL_META_DATA_SUBSECTION_HEADER # directive line elif Line[0] == '!': self._DirectiveParser() continue - # file private macros - elif Line.upper().startswith('DEFINE '): - if self._Enabled < 0: - # Do not parse the macro and add it to self._Macros dictionary if directives - # statement is evaluated to false. - continue - - (Name, Value) = self._MacroParser() - # Make the defined macro in DSC [Defines] section also - # available for FDF file. - if self._SectionName == TAB_COMMON_DEFINES.upper(): - self._LastItem = self._Store( - MODEL_META_DATA_GLOBAL_DEFINE, - Name, - Value, - '', - 'COMMON', - 'COMMON', - self._Owner, - self._From, - self._LineIndex+1, - -1, - self._LineIndex+1, - -1, - self._Enabled - ) - continue - elif Line.upper().startswith('EDK_GLOBAL '): - if self._Enabled < 0: - # Do not parse the macro and add it to self._Macros dictionary - # if previous directives statement is evaluated to false. - continue - - (Name, Value) = self._MacroParser() - for Arch, ModuleType in self._Scope: - self._LastItem = self._Store( - MODEL_META_DATA_DEFINE, - Name, - Value, - '', - Arch, - 'COMMON', - self._Owner, - self._From, - self._LineIndex+1, - -1, - self._LineIndex+1, - -1, - self._Enabled - ) - continue - # section content if self._InSubsection: SectionType = self._SubsectionType - SectionName = self._SubsectionName else: SectionType = self._SectionType - SectionName = self._SectionName + self._ItemType = SectionType self._ValueList = ['', '', ''] self._SectionParser[SectionType](self) if self._ValueList == None: continue - # # Model, Value1, Value2, Value3, Arch, ModuleType, BelongsToItem=-1, BelongsToFile=-1, # LineBegin=-1, ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, Enabled=-1 # for Arch, ModuleType in self._Scope: self._LastItem = self._Store( - SectionType, - self._ValueList[0], - self._ValueList[1], - self._ValueList[2], - Arch, - ModuleType, - self._Owner, - self._From, - self._LineIndex+1, - -1, - self._LineIndex+1, - -1, - self._Enabled - ) + self._ItemType, + self._ValueList[0], + self._ValueList[1], + self._ValueList[2], + Arch, + ModuleType, + self._Owner[-1], + self._From, + self._LineIndex+1, + -1, + self._LineIndex+1, + -1, + self._Enabled + ) + + if self._DirectiveStack: + Type, Line, Text = self._DirectiveStack[-1] + EdkLogger.error('Parser', FORMAT_INVALID, "No matching '!endif' found", + ExtraData=Text, File=self.MetaFile, Line=Line) self._Done() - ## [defines] section parser - def _DefineParser(self): - TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1) - if len(TokenList) < 2: - EdkLogger.error('Parser', FORMAT_INVALID, "No value specified", - ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) - # 'FLASH_DEFINITION', 'OUTPUT_DIRECTORY' need special processing - if TokenList[0] in ['FLASH_DEFINITION', 'OUTPUT_DIRECTORY']: - TokenList[1] = NormPath(TokenList[1], self._Macros) - self._ValueList[0:len(TokenList)] = TokenList - # Treat elements in the [defines] section as global macros for FDF file. - self._LastItem = self._Store( - MODEL_META_DATA_GLOBAL_DEFINE, - TokenList[0], - TokenList[1], - '', - 'COMMON', - 'COMMON', - self._Owner, - self._From, - self._LineIndex+1, - -1, - self._LineIndex+1, - -1, - self._Enabled - ) - ## <subsection_header> parser def _SubsectionHeaderParser(self): self._SubsectionName = self._CurrentLine[1:-1].upper() @@ -782,13 +824,16 @@ class DscParser(MetaFileParser): else: self._SubsectionType = MODEL_UNKNOWN EdkLogger.warn("Parser", "Unrecognized sub-section", File=self.MetaFile, - Line=self._LineIndex+1, ExtraData=self._CurrentLine) + Line=self._LineIndex+1, ExtraData=self._CurrentLine) + self._ValueList[0] = self._SubsectionName ## Directive statement parser def _DirectiveParser(self): self._ValueList = ['','',''] TokenList = GetSplitValueList(self._CurrentLine, ' ', 1) self._ValueList[0:len(TokenList)] = TokenList + + # Syntax check DirectiveName = self._ValueList[0].upper() if DirectiveName not in self.DataType: EdkLogger.error("Parser", FORMAT_INVALID, "Unknown directive [%s]" % DirectiveName, @@ -797,134 +842,89 @@ class DscParser(MetaFileParser): EdkLogger.error("Parser", FORMAT_INVALID, "Missing expression", File=self.MetaFile, Line=self._LineIndex+1, ExtraData=self._CurrentLine) - # keep the directive in database first - self._LastItem = self._Store( - self.DataType[DirectiveName], - self._ValueList[0], - self._ValueList[1], - self._ValueList[2], - 'COMMON', - 'COMMON', - self._Owner, - self._From, - self._LineIndex + 1, - -1, - self._LineIndex + 1, - -1, - 0 - ) - - # process the directive - if DirectiveName == "!INCLUDE": - if not self._SectionName in self._IncludeAllowedSection: - EdkLogger.error("Parser", FORMAT_INVALID, File=self.MetaFile, Line=self._LineIndex+1, - ExtraData="'!include' is not allowed under section [%s]" % self._SectionName) - # the included file must be relative to workspace - IncludedFile = os.path.join(os.environ["WORKSPACE"], NormPath(self._ValueList[1], self._Macros)) - Parser = DscParser(IncludedFile, self._FileType, self._Table, self._Macros, From=self._LastItem) - # set the parser status with current status - Parser._SectionName = self._SectionName - Parser._SectionType = self._SectionType - Parser._Scope = self._Scope - Parser._Enabled = self._Enabled - try: - Parser.Start() - except: - EdkLogger.error("Parser", PARSER_ERROR, File=self.MetaFile, Line=self._LineIndex+1, - ExtraData="Failed to parse content in file %s" % IncludedFile) - # insert an imaginary token in the DSC table to indicate its external dependency on another file - self._Store(MODEL_EXTERNAL_DEPENDENCY, IncludedFile, str(os.stat(IncludedFile)[8]), "") - # update current status with sub-parser's status - self._SectionName = Parser._SectionName - self._SectionType = Parser._SectionType - self._Scope = Parser._Scope - self._Enabled = Parser._Enabled - self._Macros.update(Parser._Macros) - else: - if DirectiveName in ["!IF", "!IFDEF", "!IFNDEF"]: - # evaluate the expression - Result = self._Evaluate(self._ValueList[1]) - if DirectiveName == "!IFNDEF": - Result = not Result - self._Eval.append(Result) - elif DirectiveName in ["!ELSEIF"]: - # evaluate the expression - self._Eval[-1] = (not self._Eval[-1]) & self._Evaluate(self._ValueList[1]) - elif DirectiveName in ["!ELSE"]: - self._Eval[-1] = not self._Eval[-1] - elif DirectiveName in ["!ENDIF"]: - if len(self._Eval) > 0: - self._Eval.pop() - else: - EdkLogger.error("Parser", FORMAT_INVALID, "!IF..[!ELSE]..!ENDIF doesn't match", - File=self.MetaFile, Line=self._LineIndex+1) - if self._Eval.Result == False: - self._Enabled = 0 - len(self._Eval) - else: - self._Enabled = len(self._Eval) - ## Evaluate the Token for its value; for now only macros are supported. - def _EvaluateToken(self, TokenName, Expression): - if TokenName.startswith("$(") and TokenName.endswith(")"): - Name = TokenName[2:-1] - return self._Macros.get(Name) - else: - EdkLogger.error('Parser', FORMAT_INVALID, "Unknown operand '%(Token)s', " - "please use '$(%(Token)s)' if '%(Token)s' is a macro" % {"Token" : TokenName}, - File=self.MetaFile, Line=self._LineIndex+1, ExtraData=Expression) - - ## Evaluate the value of expression in "if/ifdef/ifndef" directives - def _Evaluate(self, Expression): - TokenList = Expression.split() - TokenNumber = len(TokenList) - # one operand, guess it's just a macro name - if TokenNumber == 1: - TokenValue = self._EvaluateToken(TokenList[0], Expression) - return TokenValue != None - # two operands, suppose it's "!xxx" format - elif TokenNumber == 2: - Op = TokenList[0] - if Op not in self._OP_: - EdkLogger.error('Parser', FORMAT_INVALID, "Unsupported operator [%s]" % Op, File=self.MetaFile, - Line=self._LineIndex+1, ExtraData=Expression) - if TokenList[1].upper() == 'TRUE': - Value = True + ItemType = self.DataType[DirectiveName] + if ItemType == MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF: + # Remove all directives between !if and !endif, including themselves + while self._DirectiveStack: + # Remove any !else or !elseif + DirectiveInfo = self._DirectiveStack.pop() + if DirectiveInfo[0] in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF, + MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF, + MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF]: + break else: - Value = False - return self._OP_[Op](Value) - # three operands - elif TokenNumber == 3: - TokenValue = TokenList[0] - if TokenValue != "": - if TokenValue[0] in ["'", '"'] and TokenValue[-1] in ["'", '"']: - TokenValue = TokenValue[1:-1] - if TokenValue.startswith("$(") and TokenValue.endswith(")"): - TokenValue = self._EvaluateToken(TokenValue, Expression) - if TokenValue == None: - return False - if TokenValue != "": - if TokenValue[0] in ["'", '"'] and TokenValue[-1] in ["'", '"']: - TokenValue = TokenValue[1:-1] - - Value = TokenList[2] - if Value != "": - if Value[0] in ["'", '"'] and Value[-1] in ["'", '"']: - Value = Value[1:-1] - if Value.startswith("$(") and Value.endswith(")"): - Value = self._EvaluateToken(Value, Expression) - if Value == None: - return False - if Value != "": - if Value[0] in ["'", '"'] and Value[-1] in ["'", '"']: - Value = Value[1:-1] - Op = TokenList[1] - if Op not in self._OP_: - EdkLogger.error('Parser', FORMAT_INVALID, "Unsupported operator [%s]" % Op, File=self.MetaFile, - Line=self._LineIndex+1, ExtraData=Expression) - return self._OP_[Op](TokenValue, Value) - else: - EdkLogger.error('Parser', FORMAT_INVALID, File=self.MetaFile, Line=self._LineIndex+1, - ExtraData=Expression) + EdkLogger.error("Parser", FORMAT_INVALID, "Redundant '!endif'", + File=self.MetaFile, Line=self._LineIndex+1, + ExtraData=self._CurrentLine) + elif ItemType != MODEL_META_DATA_INCLUDE: + # Break if there's a !else is followed by a !elseif + if ItemType == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF and \ + self._DirectiveStack and \ + self._DirectiveStack[-1][0] == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE: + EdkLogger.error("Parser", FORMAT_INVALID, "'!elseif' after '!else'", + File=self.MetaFile, Line=self._LineIndex+1, + ExtraData=self._CurrentLine) + self._DirectiveStack.append((ItemType, self._LineIndex+1, self._CurrentLine)) + elif self._From > 0: + EdkLogger.error('Parser', FORMAT_INVALID, + "No '!include' allowed in included file", + ExtraData=self._CurrentLine, File=self.MetaFile, + Line=self._LineIndex+1) + + # + # Model, Value1, Value2, Value3, Arch, ModuleType, BelongsToItem=-1, BelongsToFile=-1, + # LineBegin=-1, ColumnBegin=-1, LineEnd=-1, ColumnEnd=-1, Enabled=-1 + # + self._LastItem = self._Store( + ItemType, + self._ValueList[0], + self._ValueList[1], + self._ValueList[2], + 'COMMON', + 'COMMON', + self._Owner[-1], + self._From, + self._LineIndex+1, + -1, + self._LineIndex+1, + -1, + 0 + ) + + ## [defines] section parser + @ParseMacro + def _DefineParser(self): + TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1) + self._ValueList[1:len(TokenList)] = TokenList + + # Syntax check + if not self._ValueList[1]: + EdkLogger.error('Parser', FORMAT_INVALID, "No name specified", + ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) + if not self._ValueList[2]: + EdkLogger.error('Parser', FORMAT_INVALID, "No value specified", + ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) + if not self._ValueList[1] in self.DefineKeywords: + EdkLogger.error('Parser', FORMAT_INVALID, + "Unknown keyword found: %s. " + "If this is a macro you must " + "add it as a DEFINE in the DSC" % self._ValueList[1], + ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) + self._Defines[self._ValueList[1]] = self._ValueList[2] + self._ItemType = self.DataType[TAB_DSC_DEFINES.upper()] + + @ParseMacro + def _SkuIdParser(self): + TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT) + if len(TokenList) != 2: + EdkLogger.error('Parser', FORMAT_INVALID, "Correct format is '<Integer>|<UiName>'", + ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) + self._ValueList[0:len(TokenList)] = TokenList + + ## Parse Edk style of library modules + def _LibraryInstanceParser(self): + self._ValueList[0] = self._CurrentLine ## PCD sections parser # @@ -940,8 +940,9 @@ class DscParser(MetaFileParser): # [PcdsDynamicVpd] # [PcdsDynamicHii] # + @ParseMacro def _PcdParser(self): - TokenList = GetSplitValueList(ReplaceMacro(self._CurrentLine, self._Macros), TAB_VALUE_SPLIT, 1) + TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1) self._ValueList[0:1] = GetSplitValueList(TokenList[0], TAB_SPLIT) if len(TokenList) == 2: self._ValueList[2] = TokenList[1] @@ -959,17 +960,18 @@ class DscParser(MetaFileParser): self._ValueList[2] = TokenList[1].replace(DscPcdValueList[0], '1', 1); elif DscPcdValueList[0] in ['False', 'false', 'FALSE']: self._ValueList[2] = TokenList[1].replace(DscPcdValueList[0], '0', 1); - + ## [components] section parser + @ParseMacro def _ComponentParser(self): if self._CurrentLine[-1] == '{': self._ValueList[0] = self._CurrentLine[0:-1].strip() self._InSubsection = True else: self._ValueList[0] = self._CurrentLine - if len(self._Macros) > 0: - self._ValueList[0] = NormPath(self._ValueList[0], self._Macros) + ## [LibraryClasses] section + @ParseMacro def _LibraryClassParser(self): TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT) if len(TokenList) < 2: @@ -984,35 +986,357 @@ class DscParser(MetaFileParser): EdkLogger.error('Parser', FORMAT_INVALID, "No library instance specified", ExtraData=self._CurrentLine + " (<LibraryClassName>|<LibraryInstancePath>)", File=self.MetaFile, Line=self._LineIndex+1) + self._ValueList[0:len(TokenList)] = TokenList - if len(self._Macros) > 0: - self._ValueList[1] = NormPath(self._ValueList[1], self._Macros) def _CompponentSourceOverridePathParser(self): - if len(self._Macros) > 0: - self._ValueList[0] = NormPath(self._CurrentLine, self._Macros) + self._ValueList[0] = self._CurrentLine + + ## [BuildOptions] section parser + @ParseMacro + def _BuildOptionParser(self): + TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1) + TokenList2 = GetSplitValueList(TokenList[0], ':', 1) + if len(TokenList2) == 2: + self._ValueList[0] = TokenList2[0] # toolchain family + self._ValueList[1] = TokenList2[1] # keys + else: + self._ValueList[1] = TokenList[0] + if len(TokenList) == 2: # value + self._ValueList[2] = TokenList[1] + + if self._ValueList[1].count('_') != 4: + EdkLogger.error( + 'Parser', + FORMAT_INVALID, + "'%s' must be in format of <TARGET>_<TOOLCHAIN>_<ARCH>_<TOOL>_FLAGS" % self._ValueList[1], + ExtraData=self._CurrentLine, + File=self.MetaFile, + Line=self._LineIndex+1 + ) + + ## Override parent's method since we'll do all macro replacements in parser + def _GetMacros(self): + Macros = {} + Macros.update(self._FileLocalMacros) + Macros.update(self._GetApplicableSectionMacro()) + Macros.update(GlobalData.gEdkGlobal) + Macros.update(GlobalData.gPlatformDefines) + Macros.update(GlobalData.gCommandLineDefines) + # PCD cannot be referenced in macro definition + if self._ItemType not in [MODEL_META_DATA_DEFINE, MODEL_META_DATA_GLOBAL_DEFINE]: + Macros.update(self._Symbols) + return Macros + + def _PostProcess(self): + Processer = { + MODEL_META_DATA_SECTION_HEADER : self.__ProcessSectionHeader, + MODEL_META_DATA_SUBSECTION_HEADER : self.__ProcessSubsectionHeader, + MODEL_META_DATA_HEADER : self.__ProcessDefine, + MODEL_META_DATA_DEFINE : self.__ProcessDefine, + MODEL_META_DATA_GLOBAL_DEFINE : self.__ProcessDefine, + MODEL_META_DATA_INCLUDE : self.__ProcessDirective, + MODEL_META_DATA_CONDITIONAL_STATEMENT_IF : self.__ProcessDirective, + MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE : self.__ProcessDirective, + MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF : self.__ProcessDirective, + MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF : self.__ProcessDirective, + MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF : self.__ProcessDirective, + MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF : self.__ProcessDirective, + MODEL_EFI_SKU_ID : self.__ProcessSkuId, + MODEL_EFI_LIBRARY_INSTANCE : self.__ProcessLibraryInstance, + MODEL_EFI_LIBRARY_CLASS : self.__ProcessLibraryClass, + MODEL_PCD_FIXED_AT_BUILD : self.__ProcessPcd, + MODEL_PCD_PATCHABLE_IN_MODULE : self.__ProcessPcd, + MODEL_PCD_FEATURE_FLAG : self.__ProcessPcd, + MODEL_PCD_DYNAMIC_DEFAULT : self.__ProcessPcd, + MODEL_PCD_DYNAMIC_HII : self.__ProcessPcd, + MODEL_PCD_DYNAMIC_VPD : self.__ProcessPcd, + MODEL_PCD_DYNAMIC_EX_DEFAULT : self.__ProcessPcd, + MODEL_PCD_DYNAMIC_EX_HII : self.__ProcessPcd, + MODEL_PCD_DYNAMIC_EX_VPD : self.__ProcessPcd, + MODEL_META_DATA_COMPONENT : self.__ProcessComponent, + MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH : self.__ProcessSourceOverridePath, + MODEL_META_DATA_BUILD_OPTION : self.__ProcessBuildOption, + MODEL_UNKNOWN : self._Skip, + MODEL_META_DATA_USER_EXTENSION : self._Skip, + } + + self._Table = MetaFileStorage(self._RawTable.Cur, self.MetaFile, MODEL_FILE_DSC, True) + self._Table.Create() + self._DirectiveStack = [] + self._DirectiveEvalStack = [] + self._FileWithError = self.MetaFile + self._FileLocalMacros = {} + self._SectionsMacroDict = {} + GlobalData.gPlatformDefines = {} + + # Get all macro and PCD which has straitforward value + self.__RetrievePcdValue() + self._Content = self._RawTable.GetAll() + self._ContentIndex = 0 + while self._ContentIndex < len(self._Content) : + Id, self._ItemType, V1, V2, V3, S1, S2, Owner, self._From, \ + LineStart, ColStart, LineEnd, ColEnd, Enabled = self._Content[self._ContentIndex] + + if self._From < 0: + self._FileWithError = self.MetaFile + + self._ContentIndex += 1 + + self._Scope = [[S1, S2]] + self._LineIndex = LineStart - 1 + self._ValueList = [V1, V2, V3] + + try: + Processer[self._ItemType]() + except EvaluationException, Excpt: + # + # Only catch expression evaluation error here. We need to report + # the precise number of line on which the error occurred + # + EdkLogger.error('Parser', FORMAT_INVALID, "Invalid expression: %s" % str(Excpt), + File=self._FileWithError, ExtraData=' '.join(self._ValueList), + Line=self._LineIndex+1) + except MacroException, Excpt: + EdkLogger.error('Parser', FORMAT_INVALID, str(Excpt), + File=self._FileWithError, ExtraData=' '.join(self._ValueList), + Line=self._LineIndex+1) + + if self._ValueList == None: + continue + + NewOwner = self._IdMapping.get(Owner, -1) + self._Enabled = int((not self._DirectiveEvalStack) or (False not in self._DirectiveEvalStack)) + self._LastItem = self._Store( + self._ItemType, + self._ValueList[0], + self._ValueList[1], + self._ValueList[2], + S1, + S2, + NewOwner, + self._From, + self._LineIndex+1, + -1, + self._LineIndex+1, + -1, + self._Enabled + ) + self._IdMapping[Id] = self._LastItem + + GlobalData.gPlatformDefines.update(self._FileLocalMacros) + self._PostProcessed = True + self._Content = None + + def __ProcessSectionHeader(self): + self._SectionName = self._ValueList[0] + if self._SectionName in self.DataType: + self._SectionType = self.DataType[self._SectionName] + else: + self._SectionType = MODEL_UNKNOWN + + def __ProcessSubsectionHeader(self): + self._SubsectionName = self._ValueList[0] + if self._SubsectionName in self.DataType: + self._SubsectionType = self.DataType[self._SubsectionName] + else: + self._SubsectionType = MODEL_UNKNOWN + + def __RetrievePcdValue(self): + Records = self._RawTable.Query(MODEL_PCD_FEATURE_FLAG, BelongsToItem=-1.0) + for TokenSpaceGuid,PcdName,Value,Dummy2,Dummy3,ID,Line in Records: + Value, DatumType, MaxDatumSize = AnalyzePcdData(Value) + # Only use PCD whose value is straitforward (no macro and PCD) + if self.SymbolPattern.findall(Value): + continue + Name = TokenSpaceGuid + '.' + PcdName + # Don't use PCD with different values. + if Name in self._Symbols and self._Symbols[Name] != Value: + self._Symbols.pop(Name) + continue + self._Symbols[Name] = Value + + Records = self._RawTable.Query(MODEL_PCD_FIXED_AT_BUILD, BelongsToItem=-1.0) + for TokenSpaceGuid,PcdName,Value,Dummy2,Dummy3,ID,Line in Records: + Value, DatumType, MaxDatumSize = AnalyzePcdData(Value) + # Only use PCD whose value is straitforward (no macro and PCD) + if self.SymbolPattern.findall(Value): + continue + Name = TokenSpaceGuid+'.'+PcdName + # Don't use PCD with different values. + if Name in self._Symbols and self._Symbols[Name] != Value: + self._Symbols.pop(Name) + continue + self._Symbols[Name] = Value + + def __ProcessDefine(self): + if not self._Enabled: + return + + Type, Name, Value = self._ValueList + Value = ReplaceMacro(Value, self._Macros, False) + if self._ItemType == MODEL_META_DATA_DEFINE: + if self._SectionType == MODEL_META_DATA_HEADER: + self._FileLocalMacros[Name] = Value + else: + SectionDictKey = self._SectionType, self._Scope[0][0], self._Scope[0][1] + if SectionDictKey not in self._SectionsMacroDict: + self._SectionsMacroDict[SectionDictKey] = {} + SectionLocalMacros = self._SectionsMacroDict[SectionDictKey] + SectionLocalMacros[Name] = Value + elif self._ItemType == MODEL_META_DATA_GLOBAL_DEFINE: + GlobalData.gEdkGlobal[Name] = Value + + # + # Keyword in [Defines] section can be used as Macros + # + if (self._ItemType == MODEL_META_DATA_HEADER) and (self._SectionType == MODEL_META_DATA_HEADER): + self._FileLocalMacros[Name] = Value + + self._ValueList = [Type, Name, Value] + + def __ProcessDirective(self): + Result = None + if self._ItemType in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF, + MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF]: + Macros = self._Macros + Macros.update(GlobalData.gGlobalDefines) + try: + Result = ValueExpression(self._ValueList[1], Macros)() + except SymbolNotFound, Exc: + EdkLogger.debug(EdkLogger.DEBUG_5, str(Exc), self._ValueList[1]) + Result = False + except WrnExpression, Excpt: + # + # Catch expression evaluation warning here. We need to report + # the precise number of line and return the evaluation result + # + EdkLogger.warn('Parser', "Suspicious expression: %s" % str(Excpt), + File=self._FileWithError, ExtraData=' '.join(self._ValueList), + Line=self._LineIndex+1) + Result = Excpt.result + + if self._ItemType in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF, + MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF, + MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF]: + self._DirectiveStack.append(self._ItemType) + if self._ItemType == MODEL_META_DATA_CONDITIONAL_STATEMENT_IF: + Result = bool(Result) + else: + Macro = self._ValueList[1] + Macro = Macro[2:-1] if (Macro.startswith("$(") and Macro.endswith(")")) else Macro + Result = Macro in self._Macros + if self._ItemType == MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF: + Result = not Result + self._DirectiveEvalStack.append(Result) + elif self._ItemType == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSEIF: + self._DirectiveStack.append(self._ItemType) + self._DirectiveEvalStack[-1] = not self._DirectiveEvalStack[-1] + self._DirectiveEvalStack.append(bool(Result)) + elif self._ItemType == MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE: + self._DirectiveStack[-1] = self._ItemType + self._DirectiveEvalStack[-1] = not self._DirectiveEvalStack[-1] + elif self._ItemType == MODEL_META_DATA_CONDITIONAL_STATEMENT_ENDIF: + # Back to the nearest !if/!ifdef/!ifndef + while self._DirectiveStack: + self._DirectiveEvalStack.pop() + Directive = self._DirectiveStack.pop() + if Directive in [MODEL_META_DATA_CONDITIONAL_STATEMENT_IF, + MODEL_META_DATA_CONDITIONAL_STATEMENT_IFDEF, + MODEL_META_DATA_CONDITIONAL_STATEMENT_ELSE, + MODEL_META_DATA_CONDITIONAL_STATEMENT_IFNDEF]: + break + elif self._ItemType == MODEL_META_DATA_INCLUDE: + # The included file must be relative to workspace + IncludedFile = NormPath(ReplaceMacro(self._ValueList[1], self._Macros, RaiseError=True)) + IncludedFile = PathClass(IncludedFile, GlobalData.gWorkspace) + ErrorCode, ErrorInfo = IncludedFile.Validate() + if ErrorCode != 0: + EdkLogger.error('parser', ErrorCode, File=self._FileWithError, + Line=self._LineIndex+1, ExtraData=ErrorInfo) + + self._FileWithError = IncludedFile + + IncludedFileTable = MetaFileStorage(self._Table.Cur, IncludedFile, MODEL_FILE_DSC, False) + Owner = self._Content[self._ContentIndex-1][0] + Parser = DscParser(IncludedFile, self._FileType, IncludedFileTable, + Owner=Owner, From=Owner) + + # set the parser status with current status + Parser._SectionName = self._SectionName + Parser._SectionType = self._SectionType + Parser._Scope = self._Scope + Parser._Enabled = self._Enabled + # Parse the included file + Parser.Start() + + # update current status with sub-parser's status + self._SectionName = Parser._SectionName + self._SectionType = Parser._SectionType + self._Scope = Parser._Scope + self._Enabled = Parser._Enabled + + # Insert all records in the table for the included file into dsc file table + Records = IncludedFileTable.GetAll() + if Records: + self._Content[self._ContentIndex:self._ContentIndex] = Records + + def __ProcessSkuId(self): + self._ValueList = [ReplaceMacro(Value, self._Macros, RaiseError=True) + for Value in self._ValueList] + + def __ProcessLibraryInstance(self): + self._ValueList = [ReplaceMacro(Value, self._Macros) for Value in self._ValueList] + + def __ProcessLibraryClass(self): + self._ValueList[1] = ReplaceMacro(self._ValueList[1], self._Macros, RaiseError=True) + + def __ProcessPcd(self): + ValueList = GetSplitValueList(self._ValueList[2]) + if len(ValueList) > 1 and ValueList[1] == 'VOID*': + PcdValue = ValueList[0] + ValueList[0] = ReplaceMacro(PcdValue, self._Macros) + else: + PcdValue = ValueList[-1] + ValueList[-1] = ReplaceMacro(PcdValue, self._Macros) + + self._ValueList[2] = '|'.join(ValueList) + + def __ProcessComponent(self): + self._ValueList[0] = ReplaceMacro(self._ValueList[0], self._Macros) + + def __ProcessSourceOverridePath(self): + self._ValueList[0] = ReplaceMacro(self._ValueList[0], self._Macros) + + def __ProcessBuildOption(self): + self._ValueList = [ReplaceMacro(Value, self._Macros, RaiseError=False) + for Value in self._ValueList] _SectionParser = { - MODEL_META_DATA_HEADER : _DefineParser, - MODEL_EFI_SKU_ID : MetaFileParser._CommonParser, - MODEL_EFI_LIBRARY_INSTANCE : MetaFileParser._PathParser, - MODEL_EFI_LIBRARY_CLASS : _LibraryClassParser, - MODEL_PCD_FIXED_AT_BUILD : _PcdParser, - MODEL_PCD_PATCHABLE_IN_MODULE : _PcdParser, - MODEL_PCD_FEATURE_FLAG : _PcdParser, - MODEL_PCD_DYNAMIC_DEFAULT : _PcdParser, - MODEL_PCD_DYNAMIC_HII : _PcdParser, - MODEL_PCD_DYNAMIC_VPD : _PcdParser, - MODEL_PCD_DYNAMIC_EX_DEFAULT : _PcdParser, - MODEL_PCD_DYNAMIC_EX_HII : _PcdParser, - MODEL_PCD_DYNAMIC_EX_VPD : _PcdParser, - MODEL_META_DATA_COMPONENT : _ComponentParser, - MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH : _CompponentSourceOverridePathParser, - MODEL_META_DATA_BUILD_OPTION : MetaFileParser._BuildOptionParser, - MODEL_UNKNOWN : MetaFileParser._Skip, - MODEL_META_DATA_USER_EXTENSION : MetaFileParser._Skip, + MODEL_META_DATA_HEADER : _DefineParser, + MODEL_EFI_SKU_ID : _SkuIdParser, + MODEL_EFI_LIBRARY_INSTANCE : _LibraryInstanceParser, + MODEL_EFI_LIBRARY_CLASS : _LibraryClassParser, + MODEL_PCD_FIXED_AT_BUILD : _PcdParser, + MODEL_PCD_PATCHABLE_IN_MODULE : _PcdParser, + MODEL_PCD_FEATURE_FLAG : _PcdParser, + MODEL_PCD_DYNAMIC_DEFAULT : _PcdParser, + MODEL_PCD_DYNAMIC_HII : _PcdParser, + MODEL_PCD_DYNAMIC_VPD : _PcdParser, + MODEL_PCD_DYNAMIC_EX_DEFAULT : _PcdParser, + MODEL_PCD_DYNAMIC_EX_HII : _PcdParser, + MODEL_PCD_DYNAMIC_EX_VPD : _PcdParser, + MODEL_META_DATA_COMPONENT : _ComponentParser, + MODEL_META_DATA_COMPONENT_SOURCE_OVERRIDE_PATH : _CompponentSourceOverridePathParser, + MODEL_META_DATA_BUILD_OPTION : _BuildOptionParser, + MODEL_UNKNOWN : MetaFileParser._Skip, + MODEL_META_DATA_USER_EXTENSION : MetaFileParser._Skip, + MODEL_META_DATA_SECTION_HEADER : MetaFileParser._SectionHeaderParser, + MODEL_META_DATA_SUBSECTION_HEADER : _SubsectionHeaderParser, } + _Macros = property(_GetMacros) + ## DEC file parser class # # @param FilePath The path of platform description file @@ -1045,20 +1369,24 @@ class DecParser(MetaFileParser): # @param Table Database used to retrieve module/package information # @param Macros Macros used for replacement in file # - def __init__(self, FilePath, FileType, Table, Macro=None): - MetaFileParser.__init__(self, FilePath, FileType, Table, Macro, -1) + def __init__(self, FilePath, FileType, Table): + # prevent re-initialization + if hasattr(self, "_Table"): + return + MetaFileParser.__init__(self, FilePath, FileType, Table, -1) self._Comments = [] + self._Version = 0x00010005 # Only EDK2 dec file is supported ## Parser starter def Start(self): + Content = '' try: - if self._Content == None: - self._Content = open(self.MetaFile, 'r').readlines() + Content = open(str(self.MetaFile), 'r').readlines() except: EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile) - for Index in range(0, len(self._Content)): - Line, Comment = CleanString2(self._Content[Index]) + for Index in range(0, len(Content)): + Line, Comment = CleanString2(Content[Index]) self._CurrentLine = Line self._LineIndex = Index @@ -1074,9 +1402,6 @@ class DecParser(MetaFileParser): self._SectionHeaderParser() self._Comments = [] continue - elif Line.startswith('DEFINE '): - self._MacroParser() - continue elif len(self._SectionType) == 0: self._Comments = [] continue @@ -1100,7 +1425,7 @@ class DecParser(MetaFileParser): self._ValueList[2], Arch, ModuleType, - self._Owner, + self._Owner[-1], self._LineIndex+1, -1, self._LineIndex+1, @@ -1180,6 +1505,7 @@ class DecParser(MetaFileParser): File=self.MetaFile, Line=self._LineIndex+1, ExtraData=self._CurrentLine) ## [guids], [ppis] and [protocols] section parser + @ParseMacro def _GuidParser(self): TokenList = GetSplitValueList(self._CurrentLine, TAB_EQUAL_SPLIT, 1) if len(TokenList) < 2: @@ -1210,6 +1536,7 @@ class DecParser(MetaFileParser): # [PcdsDynamicEx # [PcdsDynamic] # + @ParseMacro def _PcdParser(self): TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1) self._ValueList[0:1] = GetSplitValueList(TokenList[0], TAB_SPLIT) @@ -1268,6 +1595,7 @@ class DecParser(MetaFileParser): if not IsValid: EdkLogger.error('Parser', FORMAT_INVALID, Cause, ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex+1) + if ValueList[0] in ['True', 'true', 'TRUE']: ValueList[0] = '1' elif ValueList[0] in ['False', 'false', 'FALSE']: diff --git a/BaseTools/Source/Python/Workspace/MetaFileTable.py b/BaseTools/Source/Python/Workspace/MetaFileTable.py index d8dacacd64..f20eab9688 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileTable.py +++ b/BaseTools/Source/Python/Workspace/MetaFileTable.py @@ -14,14 +14,59 @@ ##
# Import Modules
#
+import uuid
+
import Common.EdkLogger as EdkLogger
-from MetaDataTable import Table
+
+from MetaDataTable import Table, TableFile
from MetaDataTable import ConvertToSqlString
+from CommonDataClass.DataClass import MODEL_FILE_DSC, MODEL_FILE_DEC, MODEL_FILE_INF, \
+ MODEL_FILE_OTHERS
-## Python class representation of table storing module data
-class ModuleTable(Table):
+class MetaFileTable(Table):
# TRICK: use file ID as the part before '.'
_ID_STEP_ = 0.00000001
+ _ID_MAX_ = 0.99999999
+
+ ## Constructor
+ def __init__(self, Cursor, MetaFile, FileType, Temporary):
+ self.MetaFile = MetaFile
+
+ self._FileIndexTable = TableFile(Cursor)
+ self._FileIndexTable.Create(False)
+
+ FileId = self._FileIndexTable.GetFileId(MetaFile)
+ if not FileId:
+ FileId = self._FileIndexTable.InsertFile(MetaFile, FileType)
+
+ if Temporary:
+ TableName = "_%s_%s_%s" % (FileType, FileId, uuid.uuid4().hex)
+ else:
+ TableName = "_%s_%s" % (FileType, FileId)
+
+ #Table.__init__(self, Cursor, TableName, FileId, False)
+ Table.__init__(self, Cursor, TableName, FileId, Temporary)
+ self.Create(not self.IsIntegrity())
+
+ def IsIntegrity(self):
+ try:
+ Result = self.Cur.execute("select ID from %s where ID<0" % (self.Table)).fetchall()
+ if not Result:
+ return False
+
+ TimeStamp = self.MetaFile.TimeStamp
+ if TimeStamp != self._FileIndexTable.GetFileTimeStamp(self.IdBase):
+ # update the timestamp in database
+ self._FileIndexTable.SetFileTimeStamp(self.IdBase, TimeStamp)
+ return False
+ except Exception, Exc:
+ EdkLogger.debug(EdkLogger.DEBUG_5, str(Exc))
+ return False
+ return True
+
+## Python class representation of table storing module data
+class ModuleTable(MetaFileTable):
+ _ID_STEP_ = 0.00000001
_ID_MAX_ = 0.99999999
_COLUMN_ = '''
ID REAL PRIMARY KEY,
@@ -42,8 +87,8 @@ class ModuleTable(Table): _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)
+ def __init__(self, Cursor, MetaFile, Temporary):
+ MetaFileTable.__init__(self, Cursor, MetaFile, MODEL_FILE_INF, Temporary)
## Insert a record into table Inf
#
@@ -100,9 +145,7 @@ class ModuleTable(Table): return self.Exec(SqlCommand)
## Python class representation of table storing package data
-class PackageTable(Table):
- _ID_STEP_ = 0.00000001
- _ID_MAX_ = 0.99999999
+class PackageTable(MetaFileTable):
_COLUMN_ = '''
ID REAL PRIMARY KEY,
Model INTEGER NOT NULL,
@@ -122,8 +165,8 @@ class PackageTable(Table): _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)
+ def __init__(self, Cursor, MetaFile, Temporary):
+ MetaFileTable.__init__(self, Cursor, MetaFile, MODEL_FILE_DEC, Temporary)
## Insert table
#
@@ -179,9 +222,7 @@ class PackageTable(Table): return self.Exec(SqlCommand)
## Python class representation of table storing platform data
-class PlatformTable(Table):
- _ID_STEP_ = 0.00000001
- _ID_MAX_ = 0.99999999
+class PlatformTable(MetaFileTable):
_COLUMN_ = '''
ID REAL PRIMARY KEY,
Model INTEGER NOT NULL,
@@ -202,8 +243,8 @@ class PlatformTable(Table): _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)
+ def __init__(self, Cursor, MetaFile, Temporary):
+ MetaFileTable.__init__(self, Cursor, MetaFile, MODEL_FILE_DSC, Temporary)
## Insert table
#
@@ -254,7 +295,7 @@ class PlatformTable(Table): # @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
+ ConditionString = "Model=%s AND Enabled>0" % Model
ValueString = "Value1,Value2,Value3,Scope1,Scope2,ID,StartLine"
if Scope1 != None and Scope1 != 'COMMON':
@@ -273,3 +314,36 @@ class PlatformTable(Table): SqlCommand = "SELECT %s FROM %s WHERE %s" % (ValueString, self.Table, ConditionString)
return self.Exec(SqlCommand)
+## Factory class to produce different storage for different type of meta-file
+class MetaFileStorage(object):
+ _FILE_TABLE_ = {
+ MODEL_FILE_INF : ModuleTable,
+ MODEL_FILE_DEC : PackageTable,
+ MODEL_FILE_DSC : PlatformTable,
+ MODEL_FILE_OTHERS : MetaFileTable,
+ }
+
+ _FILE_TYPE_ = {
+ ".inf" : MODEL_FILE_INF,
+ ".dec" : MODEL_FILE_DEC,
+ ".dsc" : MODEL_FILE_DSC,
+ }
+
+ ## Constructor
+ def __new__(Class, Cursor, MetaFile, FileType=None, Temporary=False):
+ # no type given, try to find one
+ if not FileType:
+ if MetaFile.Type in self._FILE_TYPE_:
+ FileType = Class._FILE_TYPE_[MetaFile.Type]
+ else:
+ FileType = MODEL_FILE_OTHERS
+
+ # don't pass the type around if it's well known
+ if FileType == MODEL_FILE_OTHERS:
+ Args = (Cursor, MetaFile, FileType, Temporary)
+ else:
+ Args = (Cursor, MetaFile, Temporary)
+
+ # create the storage object and return it to caller
+ return Class._FILE_TABLE_[FileType](*Args)
+
diff --git a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py b/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py index ac2ca057cc..71e98a94be 100644 --- a/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py +++ b/BaseTools/Source/Python/Workspace/WorkspaceDatabase.py @@ -92,20 +92,14 @@ class DscBuildData(PlatformBuildClassObject): # @param Platform (not used for DscBuildData)
# @param Macros Macros used for replacement in DSC file
#
- def __init__(self, FilePath, RawData, BuildDataBase, Arch='COMMON', Platform='DUMMY', Macros={}):
+ def __init__(self, FilePath, RawData, BuildDataBase, Arch='COMMON', Target=None, Toolchain=None):
self.MetaFile = FilePath
self._RawData = RawData
self._Bdb = BuildDataBase
self._Arch = Arch
- self._Macros = Macros
+ self._Target = Target
+ self._Toolchain = Toolchain
self._Clear()
- RecordList = self._RawData[MODEL_META_DATA_DEFINE, self._Arch]
- for Record in RecordList:
- GlobalData.gEdkGlobal[Record[0]] = Record[1]
-
- RecordList = self._RawData[MODEL_META_DATA_GLOBAL_DEFINE, self._Arch]
- for Record in RecordList:
- GlobalData.gGlobalDefines[Record[0]] = Record[1]
## XXX[key] = value
def __setitem__(self, key, value):
@@ -145,6 +139,16 @@ class DscBuildData(PlatformBuildClassObject): self._RFCLanguages = None
self._ISOLanguages = None
self._VpdToolGuid = None
+ self.__Macros = None
+
+ ## Get current effective macros
+ def _GetMacros(self):
+ if self.__Macros == None:
+ self.__Macros = {}
+ self.__Macros.update(GlobalData.gPlatformDefines)
+ self.__Macros.update(GlobalData.gGlobalDefines)
+ self.__Macros.update(GlobalData.gCommandLineDefines)
+ return self.__Macros
## Get architecture
def _GetArch(self):
@@ -172,37 +176,40 @@ class DscBuildData(PlatformBuildClassObject): def _GetHeaderInfo(self):
RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch]
for Record in RecordList:
- Name = Record[0]
+ Name = Record[1]
# items defined _PROPERTY_ don't need additional processing
if Name in self:
- self[Name] = Record[1]
+ self[Name] = Record[2]
# some special items in [Defines] section need special treatment
elif Name == TAB_DSC_DEFINES_OUTPUT_DIRECTORY:
- self._OutputDirectory = NormPath(Record[1], self._Macros)
+ self._OutputDirectory = NormPath(Record[2], self._Macros)
if ' ' in self._OutputDirectory:
EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "No space is allowed in OUTPUT_DIRECTORY",
File=self.MetaFile, Line=Record[-1],
ExtraData=self._OutputDirectory)
elif Name == TAB_DSC_DEFINES_FLASH_DEFINITION:
- self._FlashDefinition = PathClass(NormPath(Record[1], self._Macros), GlobalData.gWorkspace)
+ self._FlashDefinition = PathClass(NormPath(Record[2], self._Macros), GlobalData.gWorkspace)
ErrorCode, ErrorInfo = self._FlashDefinition.Validate('.fdf')
if ErrorCode != 0:
EdkLogger.error('build', ErrorCode, File=self.MetaFile, Line=Record[-1],
ExtraData=ErrorInfo)
elif Name == TAB_DSC_DEFINES_SUPPORTED_ARCHITECTURES:
- self._SupArchList = GetSplitValueList(Record[1], TAB_VALUE_SPLIT)
+ self._SupArchList = GetSplitValueList(Record[2], TAB_VALUE_SPLIT)
elif Name == TAB_DSC_DEFINES_BUILD_TARGETS:
- self._BuildTargets = GetSplitValueList(Record[1])
+ self._BuildTargets = GetSplitValueList(Record[2])
elif Name == TAB_DSC_DEFINES_SKUID_IDENTIFIER:
if self._SkuName == None:
- self._SkuName = Record[1]
+ self._SkuName = Record[2]
elif Name == TAB_FIX_LOAD_TOP_MEMORY_ADDRESS:
- self._LoadFixAddress = Record[1]
+ try:
+ self._LoadFixAddress = int (Record[2], 0)
+ except:
+ EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (Record[2]))
elif Name == TAB_DSC_DEFINES_RFC_LANGUAGES:
- if not Record[1] or Record[1][0] != '"' or Record[1][-1] != '"' or len(Record[1]) == 1:
+ if not Record[2] or Record[2][0] != '"' or Record[2][-1] != '"' or len(Record[2]) == 1:
EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'language code for RFC_LANGUAGES must have double quotes around it, for example: RFC_LANGUAGES = "en-us;zh-hans"',
File=self.MetaFile, Line=Record[-1])
- LanguageCodes = Record[1][1:-1]
+ LanguageCodes = Record[2][1:-1]
if not LanguageCodes:
EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'one or more RFC4646 format language code must be provided for RFC_LANGUAGES statement',
File=self.MetaFile, Line=Record[-1])
@@ -213,10 +220,10 @@ class DscBuildData(PlatformBuildClassObject): File=self.MetaFile, Line=Record[-1])
self._RFCLanguages = LanguageList
elif Name == TAB_DSC_DEFINES_ISO_LANGUAGES:
- if not Record[1] or Record[1][0] != '"' or Record[1][-1] != '"' or len(Record[1]) == 1:
+ if not Record[2] or Record[2][0] != '"' or Record[2][-1] != '"' or len(Record[2]) == 1:
EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'language code for ISO_LANGUAGES must have double quotes around it, for example: ISO_LANGUAGES = "engchn"',
File=self.MetaFile, Line=Record[-1])
- LanguageCodes = Record[1][1:-1]
+ LanguageCodes = Record[2][1:-1]
if not LanguageCodes:
EdkLogger.error('build', FORMAT_NOT_SUPPORTED, 'one or more ISO639-2 format language code must be provided for ISO_LANGUAGES statement',
File=self.MetaFile, Line=Record[-1])
@@ -233,10 +240,10 @@ class DscBuildData(PlatformBuildClassObject): # for VPD_TOOL_GUID is correct.
#
try:
- uuid.UUID(Record[1])
+ uuid.UUID(Record[2])
except:
EdkLogger.error("build", FORMAT_INVALID, "Invalid GUID format for VPD_TOOL_GUID", File=self.MetaFile)
- self._VpdToolGuid = Record[1]
+ self._VpdToolGuid = Record[2]
# set _Header to non-None in order to avoid database re-querying
self._Header = 'DUMMY'
@@ -368,8 +375,18 @@ class DscBuildData(PlatformBuildClassObject): if self._LoadFixAddress == None:
if self._Header == None:
self._GetHeaderInfo()
+
if self._LoadFixAddress == None:
- self._LoadFixAddress = ''
+ self._LoadFixAddress = self._Macros.get(TAB_FIX_LOAD_TOP_MEMORY_ADDRESS, '0')
+
+ try:
+ self._LoadFixAddress = int (self._LoadFixAddress, 0)
+ except:
+ EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS %s is not valid dec or hex string" % (self._LoadFixAddress))
+ if self._LoadFixAddress < 0:
+ EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid negative value %s" % (self._LoadFixAddress))
+ if self._LoadFixAddress != 0xFFFFFFFFFFFFFFFF and self._LoadFixAddress % 0x1000 != 0:
+ EdkLogger.error("build", PARAMETER_INVALID, "FIX_LOAD_TOP_MEMORY_ADDRESS is set to the invalid unaligned 4K value %s" % (self._LoadFixAddress))
return self._LoadFixAddress
## Retrieve RFCLanguage filter
@@ -389,7 +406,6 @@ class DscBuildData(PlatformBuildClassObject): if self._ISOLanguages == None:
self._ISOLanguages = []
return self._ISOLanguages
-
## Retrieve the GUID string for VPD tool
def _GetVpdToolGuid(self):
if self._VpdToolGuid == None:
@@ -402,8 +418,8 @@ class DscBuildData(PlatformBuildClassObject): ## Retrieve [SkuIds] section information
def _GetSkuIds(self):
if self._SkuIds == None:
- self._SkuIds = {}
- RecordList = self._RawData[MODEL_EFI_SKU_ID]
+ self._SkuIds = sdict()
+ RecordList = self._RawData[MODEL_EFI_SKU_ID, self._Arch]
for Record in RecordList:
if Record[0] in [None, '']:
EdkLogger.error('build', FORMAT_INVALID, 'No Sku ID number',
@@ -423,8 +439,8 @@ class DscBuildData(PlatformBuildClassObject): self._Modules = sdict()
RecordList = self._RawData[MODEL_META_DATA_COMPONENT, self._Arch]
- Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource}
- Macros.update(self._Macros)
+ Macros = self._Macros
+ Macros["EDK_SOURCE"] = GlobalData.gEcpSource
for Record in RecordList:
ModuleFile = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)
ModuleId = Record[5]
@@ -530,9 +546,8 @@ class DscBuildData(PlatformBuildClassObject): LibraryClassDict = tdict(True, 3)
# track all library class names
LibraryClassSet = set()
- RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch]
- Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource}
- Macros.update(self._Macros)
+ RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, None, -1]
+ Macros = self._Macros
for Record in RecordList:
LibraryClass, LibraryInstance, Dummy, Arch, ModuleType, Dummy, LineNo = Record
if LibraryClass == '' or LibraryClass == 'NULL':
@@ -564,7 +579,8 @@ class DscBuildData(PlatformBuildClassObject): continue
self._LibraryClasses[LibraryClass, ModuleType] = LibraryInstance
- # for EDK style library instances, which are listed in different section
+ # for Edk style library instances, which are listed in different section
+ Macros["EDK_SOURCE"] = GlobalData.gEcpSource
RecordList = self._RawData[MODEL_EFI_LIBRARY_INSTANCE, self._Arch]
for Record in RecordList:
File = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)
@@ -581,14 +597,14 @@ class DscBuildData(PlatformBuildClassObject): # to parse it here. (self._Bdb[] will trigger a file parse if it
# hasn't been parsed)
#
- Library = self._Bdb[File, self._Arch]
+ Library = self._Bdb[File, self._Arch, self._Target, self._Toolchain]
self._LibraryClasses[Library.BaseName, ':dummy:'] = Library
return self._LibraryClasses
## Retrieve all PCD settings in platform
def _GetPcds(self):
if self._Pcds == None:
- self._Pcds = {}
+ self._Pcds = sdict()
self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))
self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))
self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))
@@ -603,17 +619,17 @@ class DscBuildData(PlatformBuildClassObject): ## Retrieve [BuildOptions]
def _GetBuildOptions(self):
if self._BuildOptions == None:
- self._BuildOptions = {}
+ self._BuildOptions = sdict()
#
# Retrieve build option for EDKII style module
#
- RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, 'COMMON', EDKII_NAME]
+ RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, EDKII_NAME]
for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:
self._BuildOptions[ToolChainFamily, ToolChain, EDKII_NAME] = Option
#
# Retrieve build option for EDK style module
#
- RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, 'COMMON', EDK_NAME]
+ RecordList = self._RawData[MODEL_META_DATA_BUILD_OPTION, self._Arch, EDK_NAME]
for ToolChainFamily, ToolChain, Option, Dummy1, Dummy2, Dummy3, Dummy4 in RecordList:
self._BuildOptions[ToolChainFamily, ToolChain, EDK_NAME] = Option
return self._BuildOptions
@@ -625,7 +641,7 @@ class DscBuildData(PlatformBuildClassObject): # @retval a dict object contains settings of given PCD type
#
def _GetPcd(self, Type):
- Pcds = {}
+ Pcds = sdict()
#
# tdict is a special dict kind of type, used for selecting correct
# PCD settings for certain ARCH
@@ -664,7 +680,7 @@ class DscBuildData(PlatformBuildClassObject): # @retval a dict object contains settings of given PCD type
#
def _GetDynamicPcd(self, Type):
- Pcds = {}
+ Pcds = sdict()
#
# tdict is a special dict kind of type, used for selecting correct
# PCD settings for certain ARCH and SKU
@@ -706,7 +722,7 @@ class DscBuildData(PlatformBuildClassObject): # @retval a dict object contains settings of given PCD type
#
def _GetDynamicHiiPcd(self, Type):
- Pcds = {}
+ Pcds = sdict()
#
# tdict is a special dict kind of type, used for selecting correct
# PCD settings for certain ARCH and SKU
@@ -746,7 +762,7 @@ class DscBuildData(PlatformBuildClassObject): # @retval a dict object contains settings of given PCD type
#
def _GetDynamicVpdPcd(self, Type):
- Pcds = {}
+ Pcds = sdict()
#
# tdict is a special dict kind of type, used for selecting correct
# PCD settings for certain ARCH and SKU
@@ -814,6 +830,7 @@ class DscBuildData(PlatformBuildClassObject): self.Pcds[Name, Guid] = PcdClassObject(Name, Guid, '', '', '', '', '', {}, False, None)
self.Pcds[Name, Guid].DefaultValue = Value
+ _Macros = property(_GetMacros)
Arch = property(_GetArch, _SetArch)
Platform = property(_GetPlatformName)
PlatformName = property(_GetPlatformName)
@@ -884,13 +901,14 @@ class DecBuildData(PackageBuildClassObject): # @param Platform (not used for DecBuildData)
# @param Macros Macros used for replacement in DSC file
#
- def __init__(self, File, RawData, BuildDataBase, Arch='COMMON', Platform='DUMMY', Macros={}):
+ def __init__(self, File, RawData, BuildDataBase, Arch='COMMON', Target=None, Toolchain=None):
self.MetaFile = File
self._PackageDir = File.Dir
self._RawData = RawData
self._Bdb = BuildDataBase
self._Arch = Arch
- self._Macros = Macros
+ self._Target = Target
+ self._Toolchain = Toolchain
self._Clear()
## XXX[key] = value
@@ -918,6 +936,14 @@ class DecBuildData(PackageBuildClassObject): self._Includes = None
self._LibraryClasses = None
self._Pcds = None
+ self.__Macros = None
+
+ ## Get current effective macros
+ def _GetMacros(self):
+ if self.__Macros == None:
+ self.__Macros = {}
+ self.__Macros.update(GlobalData.gGlobalDefines)
+ return self.__Macros
## Get architecture
def _GetArch(self):
@@ -943,11 +969,11 @@ class DecBuildData(PackageBuildClassObject): # (Retriving all [Defines] information in one-shot is just to save time.)
#
def _GetHeaderInfo(self):
- RecordList = self._RawData[MODEL_META_DATA_HEADER]
+ RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch]
for Record in RecordList:
- Name = Record[0]
+ Name = Record[1]
if Name in self:
- self[Name] = Record[1]
+ self[Name] = Record[2]
self._Header = 'DUMMY'
## Retrieve package name
@@ -1057,8 +1083,8 @@ class DecBuildData(PackageBuildClassObject): if self._Includes == None:
self._Includes = []
RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch]
- Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource}
- Macros.update(self._Macros)
+ Macros = self._Macros
+ Macros["EDK_SOURCE"] = GlobalData.gEcpSource
for Record in RecordList:
File = PathClass(NormPath(Record[0], Macros), self._PackageDir, Arch=self._Arch)
LineNo = Record[-1]
@@ -1082,8 +1108,7 @@ class DecBuildData(PackageBuildClassObject): LibraryClassDict = tdict(True)
LibraryClassSet = set()
RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch]
- Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource}
- Macros.update(self._Macros)
+ Macros = self._Macros
for LibraryClass, File, Dummy, Arch, ID, LineNo in RecordList:
File = PathClass(NormPath(File, Macros), self._PackageDir, Arch=self._Arch)
# check the file validation
@@ -1100,7 +1125,7 @@ class DecBuildData(PackageBuildClassObject): ## Retrieve PCD declarations
def _GetPcds(self):
if self._Pcds == None:
- self._Pcds = {}
+ self._Pcds = sdict()
self._Pcds.update(self._GetPcd(MODEL_PCD_FIXED_AT_BUILD))
self._Pcds.update(self._GetPcd(MODEL_PCD_PATCHABLE_IN_MODULE))
self._Pcds.update(self._GetPcd(MODEL_PCD_FEATURE_FLAG))
@@ -1110,7 +1135,7 @@ class DecBuildData(PackageBuildClassObject): ## Retrieve PCD declarations for given type
def _GetPcd(self, Type):
- Pcds = {}
+ Pcds = sdict()
#
# tdict is a special kind of dict, used for selecting correct
# PCD declaration for given ARCH
@@ -1150,6 +1175,7 @@ class DecBuildData(PackageBuildClassObject): return Pcds
+ _Macros = property(_GetMacros)
Arch = property(_GetArch, _SetArch)
PackageName = property(_GetPackageName)
Guid = property(_GetFileGuid)
@@ -1194,7 +1220,7 @@ class InfBuildData(ModuleBuildClassObject): #
# Optional Fields
#
- TAB_INF_DEFINES_INF_VERSION : "_AutoGenVersion",
+ #TAB_INF_DEFINES_INF_VERSION : "_AutoGenVersion",
TAB_INF_DEFINES_COMPONENT_TYPE : "_ComponentType",
TAB_INF_DEFINES_MAKEFILE_NAME : "_MakefileName",
#TAB_INF_DEFINES_CUSTOM_MAKEFILE : "_CustomMakefile",
@@ -1249,14 +1275,15 @@ class InfBuildData(ModuleBuildClassObject): # @param Platform The name of platform employing this module
# @param Macros Macros used for replacement in DSC file
#
- def __init__(self, FilePath, RawData, BuildDatabase, Arch='COMMON', Platform='COMMON', Macros={}):
+ def __init__(self, FilePath, RawData, BuildDatabase, Arch='COMMON', Target=None, Toolchain=None):
self.MetaFile = FilePath
self._ModuleDir = FilePath.Dir
self._RawData = RawData
self._Bdb = BuildDatabase
self._Arch = Arch
+ self._Target = Target
+ self._Toolchain = Toolchain
self._Platform = 'COMMON'
- self._Macros = Macros
self._SourceOverridePath = None
if FilePath.Key in GlobalData.gOverrideDir:
self._SourceOverridePath = GlobalData.gOverrideDir[FilePath.Key]
@@ -1310,7 +1337,17 @@ class InfBuildData(ModuleBuildClassObject): self._BuildOptions = None
self._Depex = None
self._DepexExpression = None
- #self._SourceOverridePath = None
+ self.__Macros = None
+
+ ## Get current effective macros
+ def _GetMacros(self):
+ if self.__Macros == None:
+ self.__Macros = {}
+ # EDK_GLOBAL defined macros can be applied to EDK modoule
+ if self.AutoGenVersion < 0x00010005:
+ self.__Macros.update(GlobalData.gEdkGlobal)
+ self.__Macros.update(GlobalData.gGlobalDefines)
+ return self.__Macros
## Get architecture
def _GetArch(self):
@@ -1354,26 +1391,25 @@ class InfBuildData(ModuleBuildClassObject): def _GetHeaderInfo(self):
RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]
for Record in RecordList:
- Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
- Name = Record[0]
+ Name, Value = Record[1], ReplaceMacro(Record[2], self._Macros, False)
# items defined _PROPERTY_ don't need additional processing
if Name in self:
- self[Name] = Record[1]
+ self[Name] = Value
# some special items in [Defines] section need special treatment
elif Name in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION', 'EDK_RELEASE_VERSION', 'PI_SPECIFICATION_VERSION'):
if Name in ('EFI_SPECIFICATION_VERSION', 'UEFI_SPECIFICATION_VERSION'):
Name = 'UEFI_SPECIFICATION_VERSION'
if self._Specification == None:
self._Specification = sdict()
- self._Specification[Name] = GetHexVerValue(Record[1])
+ self._Specification[Name] = GetHexVerValue(Value)
if self._Specification[Name] == None:
EdkLogger.error("build", FORMAT_NOT_SUPPORTED,
- "'%s' format is not supported for %s" % (Record[1], Name),
+ "'%s' format is not supported for %s" % (Value, Name),
File=self.MetaFile, Line=Record[-1])
elif Name == 'LIBRARY_CLASS':
if self._LibraryClass == None:
self._LibraryClass = []
- ValueList = GetSplitValueList(Record[1])
+ ValueList = GetSplitValueList(Value)
LibraryClass = ValueList[0]
if len(ValueList) > 1:
SupModuleList = GetSplitValueList(ValueList[1], ' ')
@@ -1383,27 +1419,27 @@ class InfBuildData(ModuleBuildClassObject): elif Name == 'ENTRY_POINT':
if self._ModuleEntryPointList == None:
self._ModuleEntryPointList = []
- self._ModuleEntryPointList.append(Record[1])
+ self._ModuleEntryPointList.append(Value)
elif Name == 'UNLOAD_IMAGE':
if self._ModuleUnloadImageList == None:
self._ModuleUnloadImageList = []
- if Record[1] == '':
+ if not Value:
continue
- self._ModuleUnloadImageList.append(Record[1])
+ self._ModuleUnloadImageList.append(Value)
elif Name == 'CONSTRUCTOR':
if self._ConstructorList == None:
self._ConstructorList = []
- if Record[1] == '':
+ if not Value:
continue
- self._ConstructorList.append(Record[1])
+ self._ConstructorList.append(Value)
elif Name == 'DESTRUCTOR':
if self._DestructorList == None:
self._DestructorList = []
- if Record[1] == '':
+ if not Value:
continue
- self._DestructorList.append(Record[1])
+ self._DestructorList.append(Value)
elif Name == TAB_INF_DEFINES_CUSTOM_MAKEFILE:
- TokenList = GetSplitValueList(Record[1])
+ TokenList = GetSplitValueList(Value)
if self._CustomMakefile == None:
self._CustomMakefile = {}
if len(TokenList) < 2:
@@ -1418,25 +1454,25 @@ class InfBuildData(ModuleBuildClassObject): else:
if self._Defs == None:
self._Defs = sdict()
- self._Defs[Name] = Record[1]
+ self._Defs[Name] = Value
#
- # Retrieve information in sections specific to EDK.x modules
+ # Retrieve information in sections specific to Edk.x modules
#
- if self._AutoGenVersion >= 0x00010005: # _AutoGenVersion may be None, which is less than anything
+ if self.AutoGenVersion >= 0x00010005:
if not self._ModuleType:
EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE,
"MODULE_TYPE is not given", File=self.MetaFile)
if self._ModuleType not in SUP_MODULE_LIST:
RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]
for Record in RecordList:
- Name = Record[0]
+ Name = Record[1]
if Name == "MODULE_TYPE":
LineNo = Record[6]
break
EdkLogger.error("build", FORMAT_NOT_SUPPORTED,
"MODULE_TYPE %s is not supported for EDK II, valid values are:\n %s" % (self._ModuleType,' '.join(l for l in SUP_MODULE_LIST)),
- File=self.MetaFile, Line=LineNo)
+ File=self.MetaFile, Line=LineNo)
if (self._Specification == None) or (not 'PI_SPECIFICATION_VERSION' in self._Specification) or (int(self._Specification['PI_SPECIFICATION_VERSION'], 16) < 0x0001000A):
if self._ModuleType == SUP_MODULE_SMM_CORE:
EdkLogger.error("build", FORMAT_NOT_SUPPORTED, "SMM_CORE module type can't be used in the module with PI_SPECIFICATION_VERSION less than 0x0001000A", File=self.MetaFile)
@@ -1459,29 +1495,28 @@ class InfBuildData(ModuleBuildClassObject): if self.Sources == None:
self._Sources = []
self._Sources.append(File)
- else:
- self._BuildType = self._ComponentType.upper()
+ else:
if not self._ComponentType:
EdkLogger.error("build", ATTRIBUTE_NOT_AVAILABLE,
"COMPONENT_TYPE is not given", File=self.MetaFile)
+ self._BuildType = self._ComponentType.upper()
if self._ComponentType in self._MODULE_TYPE_:
self._ModuleType = self._MODULE_TYPE_[self._ComponentType]
if self._ComponentType == 'LIBRARY':
self._LibraryClass = [LibraryClassObject(self._BaseName, SUP_MODULE_LIST)]
# make use some [nmake] section macros
+ Macros = self._Macros
+ Macros["EDK_SOURCE"] = GlobalData.gEcpSource
+ Macros['PROCESSOR'] = self._Arch
RecordList = self._RawData[MODEL_META_DATA_NMAKE, self._Arch, self._Platform]
for Name,Value,Dummy,Arch,Platform,ID,LineNo in RecordList:
- Value = Value.replace('$(PROCESSOR)', self._Arch)
- Name = Name.replace('$(PROCESSOR)', self._Arch)
- Name, Value = ReplaceMacros((Name, Value), GlobalData.gEdkGlobal, True)
+ Value = ReplaceMacro(Value, Macros, True)
if Name == "IMAGE_ENTRY_POINT":
if self._ModuleEntryPointList == None:
self._ModuleEntryPointList = []
self._ModuleEntryPointList.append(Value)
elif Name == "DPX_SOURCE":
- Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource}
- Macros.update(self._Macros)
- File = PathClass(NormPath(Value, Macros), self._ModuleDir, Arch=self._Arch)
+ File = PathClass(NormPath(Value), self._ModuleDir, Arch=self._Arch)
# check the file validation
ErrorCode, ErrorInfo = File.Validate(".dxs", CaseSensitive=False)
if ErrorCode != 0:
@@ -1505,9 +1540,9 @@ class InfBuildData(ModuleBuildClassObject): else:
Tool = ToolList[0]
ToolChain = "*_*_*_%s_FLAGS" % Tool
- ToolChainFamily = 'MSFT' # EDK.x only support MSFT tool chain
+ ToolChainFamily = 'MSFT' # Edk.x only support MSFT tool chain
#ignore not replaced macros in value
- ValueList = GetSplitValueList(' ' + Value, '/D')
+ ValueList = GetSplitList(' ' + Value, '/D')
Dummy = ValueList[0]
for Index in range(1, len(ValueList)):
if ValueList[Index][-1] == '=' or ValueList[Index] == '':
@@ -1525,8 +1560,11 @@ class InfBuildData(ModuleBuildClassObject): ## Retrieve file version
def _GetInfVersion(self):
if self._AutoGenVersion == None:
- if self._Header_ == None:
- self._GetHeaderInfo()
+ RecordList = self._RawData[MODEL_META_DATA_HEADER, self._Arch, self._Platform]
+ for Record in RecordList:
+ if Record[1] == TAB_INF_DEFINES_INF_VERSION:
+ self._AutoGenVersion = int(Record[2], 0)
+ break
if self._AutoGenVersion == None:
self._AutoGenVersion = 0x00010000
return self._AutoGenVersion
@@ -1693,10 +1731,10 @@ class InfBuildData(ModuleBuildClassObject): if self._Binaries == None:
self._Binaries = []
RecordList = self._RawData[MODEL_EFI_BINARY_FILE, self._Arch, self._Platform]
- Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource, 'PROCESSOR':self._Arch}
- Macros.update(self._Macros)
+ Macros = self._Macros
+ Macros["EDK_SOURCE"] = GlobalData.gEcpSource
+ Macros['PROCESSOR'] = self._Arch
for Record in RecordList:
- Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
FileType = Record[0]
LineNo = Record[-1]
Target = 'COMMON'
@@ -1721,17 +1759,17 @@ class InfBuildData(ModuleBuildClassObject): if self._Sources == None:
self._Sources = []
RecordList = self._RawData[MODEL_EFI_SOURCE_FILE, self._Arch, self._Platform]
- Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource, 'PROCESSOR':self._Arch}
- Macros.update(self._Macros)
+ Macros = self._Macros
+ Macros["EDK_SOURCE"] = GlobalData.gEcpSource
+ Macros['PROCESSOR'] = self._Arch
for Record in RecordList:
- Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
LineNo = Record[-1]
ToolChainFamily = Record[1]
TagName = Record[2]
ToolCode = Record[3]
FeatureFlag = Record[4]
- if self._AutoGenVersion < 0x00010005:
- # old module source files (EDK)
+ if self.AutoGenVersion < 0x00010005:
+ # old module source files (Edk)
File = PathClass(NormPath(Record[0], Macros), self._ModuleDir, self._SourceOverridePath,
'', False, self._Arch, ToolChainFamily, '', TagName, ToolCode)
# check the file validation
@@ -1760,23 +1798,22 @@ class InfBuildData(ModuleBuildClassObject): self._LibraryClasses = sdict()
RecordList = self._RawData[MODEL_EFI_LIBRARY_CLASS, self._Arch, self._Platform]
for Record in RecordList:
- Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
Lib = Record[0]
Instance = Record[1]
- if Instance != None and Instance != '':
+ if Instance:
Instance = NormPath(Instance, self._Macros)
self._LibraryClasses[Lib] = Instance
return self._LibraryClasses
- ## Retrieve library names (for EDK.x style of modules)
+ ## Retrieve library names (for Edk.x style of modules)
def _GetLibraryNames(self):
if self._Libraries == None:
self._Libraries = []
RecordList = self._RawData[MODEL_EFI_LIBRARY_INSTANCE, self._Arch, self._Platform]
for Record in RecordList:
- # in case of name with '.lib' extension, which is unusual in EDK.x inf
- Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
- LibraryName = os.path.splitext(Record[0])[0]
+ LibraryName = ReplaceMacro(Record[0], self._Macros, False)
+ # in case of name with '.lib' extension, which is unusual in Edk.x inf
+ LibraryName = os.path.splitext(LibraryName)[0]
if LibraryName not in self._Libraries:
self._Libraries.append(LibraryName)
return self._Libraries
@@ -1829,23 +1866,23 @@ class InfBuildData(ModuleBuildClassObject): self._Guids[CName] = Value
return self._Guids
- ## Retrieve include paths necessary for this module (for EDK.x style of modules)
+ ## Retrieve include paths necessary for this module (for Edk.x style of modules)
def _GetIncludes(self):
if self._Includes == None:
self._Includes = []
if self._SourceOverridePath:
self._Includes.append(self._SourceOverridePath)
+
+ Macros = self._Macros
+ if 'PROCESSOR' in GlobalData.gEdkGlobal.keys():
+ Macros['PROCESSOR'] = GlobalData.gEdkGlobal['PROCESSOR']
+ else:
+ Macros['PROCESSOR'] = self._Arch
RecordList = self._RawData[MODEL_EFI_INCLUDE, self._Arch, self._Platform]
- # [includes] section must be used only in old (EDK.x) inf file
- if self.AutoGenVersion >= 0x00010005 and len(RecordList) > 0:
- EdkLogger.error('build', FORMAT_NOT_SUPPORTED, "No [include] section allowed",
- File=self.MetaFile, Line=RecordList[0][-1]-1)
for Record in RecordList:
- Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
- Record[0] = Record[0].replace('$(PROCESSOR)', self._Arch)
- Record[0] = ReplaceMacro(Record[0], {'EFI_SOURCE' : GlobalData.gEfiSource}, False)
if Record[0].find('EDK_SOURCE') > -1:
- File = NormPath(ReplaceMacro(Record[0], {'EDK_SOURCE' : GlobalData.gEcpSource}, False), self._Macros)
+ Macros['EDK_SOURCE'] = GlobalData.gEcpSource
+ File = NormPath(Record[0], self._Macros)
if File[0] == '.':
File = os.path.join(self._ModuleDir, File)
else:
@@ -1855,7 +1892,8 @@ class InfBuildData(ModuleBuildClassObject): self._Includes.append(File)
#TRICK: let compiler to choose correct header file
- File = NormPath(ReplaceMacro(Record[0], {'EDK_SOURCE' : GlobalData.gEdkSource}, False), self._Macros)
+ Macros['EDK_SOURCE'] = GlobalData.gEdkSource
+ File = NormPath(Record[0], self._Macros)
if File[0] == '.':
File = os.path.join(self._ModuleDir, File)
else:
@@ -1864,7 +1902,7 @@ class InfBuildData(ModuleBuildClassObject): if File:
self._Includes.append(File)
else:
- File = NormPath(Record[0], self._Macros)
+ File = NormPath(Record[0], Macros)
if File[0] == '.':
File = os.path.join(self._ModuleDir, File)
else:
@@ -1879,8 +1917,8 @@ class InfBuildData(ModuleBuildClassObject): if self._Packages == None:
self._Packages = []
RecordList = self._RawData[MODEL_META_DATA_PACKAGE, self._Arch, self._Platform]
- Macros = {"EDK_SOURCE":GlobalData.gEcpSource, "EFI_SOURCE":GlobalData.gEfiSource}
- Macros.update(self._Macros)
+ Macros = self._Macros
+ Macros['EDK_SOURCE'] = GlobalData.gEcpSource
for Record in RecordList:
File = PathClass(NormPath(Record[0], Macros), GlobalData.gWorkspace, Arch=self._Arch)
LineNo = Record[-1]
@@ -1889,7 +1927,7 @@ class InfBuildData(ModuleBuildClassObject): if ErrorCode != 0:
EdkLogger.error('build', ErrorCode, ExtraData=ErrorInfo, File=self.MetaFile, Line=LineNo)
# parse this package now. we need it to get protocol/ppi/guid value
- Package = self._Bdb[File, self._Arch]
+ Package = self._Bdb[File, self._Arch, self._Target, self._Toolchain]
self._Packages.append(Package)
return self._Packages
@@ -1921,7 +1959,7 @@ class InfBuildData(ModuleBuildClassObject): self._BuildOptions[ToolChainFamily, ToolChain] = OptionString + " " + Option
return self._BuildOptions
- ## Retrieve depedency expression
+ ## Retrieve dependency expression
def _GetDepex(self):
if self._Depex == None:
self._Depex = tdict(False, 2)
@@ -1929,8 +1967,8 @@ class InfBuildData(ModuleBuildClassObject): # If the module has only Binaries and no Sources, then ignore [Depex]
if self.Sources == None or self.Sources == []:
- if self.Binaries <> None and self.Binaries <> []:
- return self._Depex
+ if self.Binaries != None and self.Binaries != []:
+ return self._Depex
# PEIM and DXE drivers must have a valid [Depex] section
if len(self.LibraryClass) == 0 and len(RecordList) == 0:
@@ -1939,12 +1977,12 @@ class InfBuildData(ModuleBuildClassObject): EdkLogger.error('build', RESOURCE_NOT_AVAILABLE, "No [Depex] section or no valid expression in [Depex] section for [%s] module" \
% self.ModuleType, File=self.MetaFile)
- Depex = {}
+ Depex = sdict()
for Record in RecordList:
- Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
+ DepexStr = ReplaceMacro(Record[0], self._Macros, False)
Arch = Record[3]
ModuleType = Record[4]
- TokenList = Record[0].split()
+ TokenList = DepexStr.split()
if (Arch, ModuleType) not in Depex:
Depex[Arch, ModuleType] = []
DepexList = Depex[Arch, ModuleType]
@@ -1980,12 +2018,12 @@ class InfBuildData(ModuleBuildClassObject): if self._DepexExpression == None:
self._DepexExpression = tdict(False, 2)
RecordList = self._RawData[MODEL_EFI_DEPEX, self._Arch]
- DepexExpression = {}
+ DepexExpression = sdict()
for Record in RecordList:
- Record = ReplaceMacros(Record, GlobalData.gEdkGlobal, False)
+ DepexStr = ReplaceMacro(Record[0], self._Macros, False)
Arch = Record[3]
ModuleType = Record[4]
- TokenList = Record[0].split()
+ TokenList = DepexStr.split()
if (Arch, ModuleType) not in DepexExpression:
DepexExpression[Arch, ModuleType] = ''
for Token in TokenList:
@@ -2123,6 +2161,7 @@ class InfBuildData(ModuleBuildClassObject): return Pcds
+ _Macros = property(_GetMacros)
Arch = property(_GetArch, _SetArch)
Platform = property(_GetPlatform, _SetPlatform)
@@ -2170,21 +2209,6 @@ class InfBuildData(ModuleBuildClassObject): # @prarm RenewDb=False Create new database file if it's already there
#
class WorkspaceDatabase(object):
- # file parser
- _FILE_PARSER_ = {
- MODEL_FILE_INF : InfParser,
- MODEL_FILE_DEC : DecParser,
- MODEL_FILE_DSC : DscParser,
- MODEL_FILE_FDF : None, #FdfParser,
- MODEL_FILE_CIF : None
- }
-
- # file table
- _FILE_TABLE_ = {
- MODEL_FILE_INF : ModuleTable,
- MODEL_FILE_DEC : PackageTable,
- MODEL_FILE_DSC : PlatformTable,
- }
# default database file path
_DB_PATH_ = "Conf/.cache/build.db"
@@ -2194,11 +2218,18 @@ class WorkspaceDatabase(object): # to avoid unnecessary re-parsing
#
class BuildObjectFactory(object):
+
_FILE_TYPE_ = {
".inf" : MODEL_FILE_INF,
".dec" : MODEL_FILE_DEC,
".dsc" : MODEL_FILE_DSC,
- ".fdf" : MODEL_FILE_FDF,
+ }
+
+ # file parser
+ _FILE_PARSER_ = {
+ MODEL_FILE_INF : InfParser,
+ MODEL_FILE_DEC : DecParser,
+ MODEL_FILE_DSC : DscParser,
}
# convert to xxxBuildData object
@@ -2206,7 +2237,6 @@ class WorkspaceDatabase(object): MODEL_FILE_INF : InfBuildData,
MODEL_FILE_DEC : DecBuildData,
MODEL_FILE_DSC : DscBuildData,
- MODEL_FILE_FDF : None #FlashDefTable,
}
_CACHE_ = {} # (FilePath, Arch) : <object>
@@ -2215,46 +2245,61 @@ class WorkspaceDatabase(object): def __init__(self, WorkspaceDb):
self.WorkspaceDb = WorkspaceDb
- # key = (FilePath, Arch='COMMON')
+ # key = (FilePath, Arch=None)
def __contains__(self, Key):
FilePath = Key[0]
- Arch = 'COMMON'
if len(Key) > 1:
Arch = Key[1]
+ else:
+ Arch = None
return (FilePath, Arch) in self._CACHE_
- # key = (FilePath, Arch='COMMON')
+ # key = (FilePath, Arch=None, Target=None, Toochain=None)
def __getitem__(self, Key):
FilePath = Key[0]
- Arch = 'COMMON'
- Platform = 'COMMON'
- if len(Key) > 1:
+ KeyLength = len(Key)
+ if KeyLength > 1:
Arch = Key[1]
- if len(Key) > 2:
- Platform = Key[2]
+ else:
+ Arch = None
+ if KeyLength > 2:
+ Target = Key[2]
+ else:
+ Target = None
+ if KeyLength > 3:
+ Toolchain = Key[3]
+ else:
+ Toolchain = None
# if it's generated before, just return the cached one
- Key = (FilePath, Arch)
+ Key = (FilePath, Arch, Target, Toolchain)
if Key in self._CACHE_:
return self._CACHE_[Key]
# check file type
- Ext = FilePath.Ext.lower()
+ Ext = FilePath.Type
if Ext not in self._FILE_TYPE_:
return None
FileType = self._FILE_TYPE_[Ext]
if FileType not in self._GENERATOR_:
return None
- # get table for current file
- MetaFile = self.WorkspaceDb[FilePath, FileType, self.WorkspaceDb._GlobalMacros]
+ # get the parser ready for this file
+ MetaFile = self._FILE_PARSER_[FileType](
+ FilePath,
+ FileType,
+ MetaFileStorage(self.WorkspaceDb.Cur, FilePath, FileType)
+ )
+ # alwasy do post-process, in case of macros change
+ MetaFile.DoPostProcess()
+ # object the build is based on
BuildObject = self._GENERATOR_[FileType](
FilePath,
MetaFile,
self,
Arch,
- Platform,
- self.WorkspaceDb._GlobalMacros,
+ Target,
+ Toolchain
)
self._CACHE_[Key] = BuildObject
return BuildObject
@@ -2274,11 +2319,9 @@ 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, GlobalMacros={}, RenewDb=False):
+ def __init__(self, DbPath, RenewDb=False):
self._DbClosedFlag = False
- self._GlobalMacros = GlobalMacros
-
- if DbPath == None or DbPath == '':
+ if not DbPath:
DbPath = os.path.normpath(os.path.join(GlobalData.gWorkspace, self._DB_PATH_))
# don't create necessary path for db in memory
@@ -2306,6 +2349,7 @@ class WorkspaceDatabase(object): # create table for internal uses
self.TblDataModel = TableDataModel(self.Cur)
self.TblFile = TableFile(self.Cur)
+ self.Platform = None
# conversion object for build or file format conversion purpose
self.BuildObject = WorkspaceDatabase.BuildObjectFactory(self)
@@ -2324,41 +2368,6 @@ class WorkspaceDatabase(object): # @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
@@ -2423,6 +2432,9 @@ determine whether database file is out of date!\n") def QueryTable(self, Table):
Table.Query()
+ def __del__(self):
+ self.Close()
+
## Close entire database
#
# Commit all first
@@ -2435,83 +2447,28 @@ determine whether database file is out of date!\n") self.Conn.close()
self._DbClosedFlag = True
- ## Get unique file ID for the gvien file
- def GetFileId(self, FilePath):
- return self.TblFile.GetFileId(FilePath)
-
- ## Get file type value for the gvien file ID
- def GetFileType(self, FileId):
- return self.TblFile.GetFileType(FileId)
-
- ## Get time stamp stored in file table
- def GetTimeStamp(self, FileId):
- return self.TblFile.GetFileTimeStamp(FileId)
-
- ## Update time stamp in file table
- def SetTimeStamp(self, FileId, TimeStamp):
- return self.TblFile.SetFileTimeStamp(FileId, TimeStamp)
-
- ## Check if a table integrity flag exists or not
- def CheckIntegrity(self, TableName):
- try:
- Result = self.Cur.execute("select min(ID) from %s" % (TableName)).fetchall()
- if Result[0][0] != -1:
- return False
- #
- # Check whether the meta data file has external dependency by comparing the time stamp
- #
- Sql = "select Value1, Value2 from %s where Model=%d" % (TableName, MODEL_EXTERNAL_DEPENDENCY)
- for Dependency in self.Cur.execute(Sql).fetchall():
- if str(os.stat(Dependency[0])[8]) != Dependency[1]:
- return False
- except:
- return False
- return True
-
- ## Compose table name for given file type and file ID
- def GetTableName(self, FileType, FileId):
- return "_%s_%s" % (FileType, FileId)
-
- ## Return a temp table containing all content of the given file
- #
- # @param FileInfo The tuple containing path and type of a file
- #
- def __getitem__(self, FileInfo):
- FilePath, FileType, Macros = FileInfo
- if FileType not in self._FILE_TABLE_:
- return None
-
- # flag used to indicate if it's parsed or not
- FilePath = str(FilePath)
- Parsed = False
- FileId = self.GetFileId(FilePath)
- if FileId != None:
- TimeStamp = os.stat(FilePath)[8]
- TableName = self.GetTableName(FileType, FileId)
- if TimeStamp != self.GetTimeStamp(FileId):
- # update the timestamp in database
- self.SetTimeStamp(FileId, TimeStamp)
- else:
- # if the table exists and is integrity, don't parse it
- Parsed = self.CheckIntegrity(TableName)
- else:
- FileId = self.TblFile.InsertFile(FilePath, FileType)
- TableName = self.GetTableName(FileType, FileId)
-
- FileTable = self._FILE_TABLE_[FileType](self.Cur, TableName, FileId)
- FileTable.Create(not Parsed)
- Parser = self._FILE_PARSER_[FileType](FilePath, FileType, FileTable, Macros)
- # set the "Finished" flag in parser in order to avoid re-parsing (if parsed)
- Parser.Finished = Parsed
- return Parser
-
## Summarize all packages in the database
- def _GetPackageList(self):
- PackageList = []
- for Module in self.ModuleList:
- for Package in Module.Packages:
+ def GetPackageList(self, Platform, Arch, TargetName, ToolChainTag):
+ self.Platform = Platform
+ PackageList =[]
+ Pa = self.BuildObject[self.Platform, 'COMMON']
+ #
+ # Get Package related to Modules
+ #
+ for Module in Pa.Modules:
+ ModuleObj = self.BuildObject[Module, Arch, TargetName, ToolChainTag]
+ for Package in ModuleObj.Packages:
if Package not in PackageList:
PackageList.append(Package)
+ #
+ # Get Packages related to Libraries
+ #
+ for Lib in Pa.LibraryInstances:
+ LibObj = self.BuildObject[Lib, Arch, TargetName, ToolChainTag]
+ for Package in LibObj.Packages:
+ if Package not in PackageList:
+ PackageList.append(Package)
+
return PackageList
## Summarize all platforms in the database
@@ -2526,21 +2483,7 @@ determine whether database file is out of date!\n") PlatformList.append(Platform)
return PlatformList
- ## Summarize all modules in the database
- def _GetModuleList(self):
- ModuleList = []
- for ModuleFile in self.TblFile.GetFileList(MODEL_FILE_INF):
- try:
- Module = self.BuildObject[PathClass(ModuleFile), 'COMMON']
- except:
- Module = None
- if Module != None:
- ModuleList.append(Module)
- return ModuleList
-
PlatformList = property(_GetPlatformList)
- PackageList = property(_GetPackageList)
- ModuleList = property(_GetModuleList)
##
#
|