diff options
Diffstat (limited to 'BaseTools/Source/Python/Workspace/MetaFileParser.py')
-rw-r--r-- | BaseTools/Source/Python/Workspace/MetaFileParser.py | 78 |
1 files changed, 72 insertions, 6 deletions
diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py index 7a6152c8fb..fb66e41fb5 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -82,6 +82,7 @@ class MetaFileParser(object): self.MetaFile = FilePath self._FileDir = os.path.dirname(self.MetaFile) self._Macros = copy.copy(Macros) + self._Macros["WORKSPACE"] = os.environ["WORKSPACE"] # for recursive parsing self._Owner = Owner @@ -490,7 +491,12 @@ class InfParser(MetaFileParser): ## [FixedPcd], [FeaturePcd], [PatchPcd], [Pcd] and [PcdEx] sections parser def _PcdParser(self): TokenList = GetSplitValueList(self._CurrentLine, TAB_VALUE_SPLIT, 1) - self._ValueList[0:1] = GetSplitValueList(TokenList[0], TAB_SPLIT) + ValueList = GetSplitValueList(TokenList[0], TAB_SPLIT) + if len(ValueList) != 2: + EdkLogger.error('Parser', FORMAT_INVALID, "Illegal token space GUID and PCD name format", + ExtraData=self._CurrentLine + " (<TokenSpaceGuidCName>.<PcdCName>)", + File=self.MetaFile, Line=self._LineIndex+1) + self._ValueList[0:1] = ValueList if len(TokenList) > 1: self._ValueList[2] = TokenList[1] if self._ValueList[0] == '' or self._ValueList[1] == '': @@ -564,6 +570,7 @@ class DscParser(MetaFileParser): # sections which allow "!include" directive _IncludeAllowedSection = [ + TAB_COMMON_DEFINES.upper(), TAB_LIBRARIES.upper(), TAB_LIBRARY_CLASSES.upper(), TAB_SKUIDS.upper(), @@ -648,7 +655,25 @@ class DscParser(MetaFileParser): continue # file private macros elif Line.upper().startswith('DEFINE '): - self._MacroParser() + (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 '): (Name, Value) = self._MacroParser() @@ -715,6 +740,22 @@ class DscParser(MetaFileParser): 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): @@ -762,7 +803,7 @@ class DscParser(MetaFileParser): 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 the parsing file - IncludedFile = os.path.join(self._FileDir, self._ValueList[1]) + IncludedFile = os.path.join(self._FileDir, 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 @@ -781,6 +822,7 @@ class DscParser(MetaFileParser): 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 @@ -965,6 +1007,7 @@ class DecParser(MetaFileParser): # def __init__(self, FilePath, FileType, Table, Macro=None): MetaFileParser.__init__(self, FilePath, FileType, Table, Macro, -1) + self._Comments = [] ## Parser starter def Start(self): @@ -975,27 +1018,34 @@ class DecParser(MetaFileParser): EdkLogger.error("Parser", FILE_READ_FAILURE, ExtraData=self.MetaFile) for Index in range(0, len(self._Content)): - Line = CleanString(self._Content[Index]) + Line, Comment = CleanString2(self._Content[Index]) + self._CurrentLine = Line + self._LineIndex = Index + + # save comment for later use + if Comment: + self._Comments.append((Comment, self._LineIndex+1)) # skip empty line if Line == '': continue - self._CurrentLine = Line - self._LineIndex = Index # section header if Line[0] == TAB_SECTION_START and Line[-1] == TAB_SECTION_END: self._SectionHeaderParser() + self._Comments = [] continue elif Line.startswith('DEFINE '): self._MacroParser() continue elif len(self._SectionType) == 0: + self._Comments = [] continue # section content self._ValueList = ['','',''] self._SectionParser[self._SectionType[0]](self) if self._ValueList == None: + self._Comments = [] continue # @@ -1017,6 +1067,22 @@ class DecParser(MetaFileParser): -1, 0 ) + for Comment, LineNo in self._Comments: + self._Store( + MODEL_META_DATA_COMMENT, + Comment, + self._ValueList[0], + self._ValueList[1], + Arch, + ModuleType, + self._LastItem, + LineNo, + -1, + LineNo, + -1, + 0 + ) + self._Comments = [] self._Done() ## Section header parser |