mirror of https://github.com/acidanthera/audk.git
BaseTools: Extend the Macro used in the FDF !include statement
Current it only support the system environment variables in the !include statement, $(WORKSPACE), $(PACKAGES_PATH), $(EFI_SOURCE), $(EDK_SOURCE), $(ECP_SOURCE), this patch extend the usage to support the Global macros and the macro which defined before the statement. Cc: Liming Gao <liming.gao@intel.com> Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com> Reviewed-by: Liming Gao <liming.gao@intel.com>
This commit is contained in:
parent
7cf59c854f
commit
0fdfe2742e
|
@ -620,27 +620,46 @@ class FdfParser:
|
||||||
def PreprocessIncludeFile(self):
|
def PreprocessIncludeFile(self):
|
||||||
# nested include support
|
# nested include support
|
||||||
Processed = False
|
Processed = False
|
||||||
|
MacroDict = {}
|
||||||
while self.__GetNextToken():
|
while self.__GetNextToken():
|
||||||
|
|
||||||
if self.__Token == '!include':
|
if self.__Token == 'DEFINE':
|
||||||
|
if not self.__GetNextToken():
|
||||||
|
raise Warning("expected Macro name", self.FileName, self.CurrentLineNumber)
|
||||||
|
Macro = self.__Token
|
||||||
|
if not self.__IsToken( "="):
|
||||||
|
raise Warning("expected '='", self.FileName, self.CurrentLineNumber)
|
||||||
|
Value = self.__GetExpression()
|
||||||
|
MacroDict[Macro] = Value
|
||||||
|
|
||||||
|
elif self.__Token == '!include':
|
||||||
Processed = True
|
Processed = True
|
||||||
IncludeLine = self.CurrentLineNumber
|
IncludeLine = self.CurrentLineNumber
|
||||||
IncludeOffset = self.CurrentOffsetWithinLine - len('!include')
|
IncludeOffset = self.CurrentOffsetWithinLine - len('!include')
|
||||||
if not self.__GetNextToken():
|
if not self.__GetNextToken():
|
||||||
raise Warning("expected include file name", self.FileName, self.CurrentLineNumber)
|
raise Warning("expected include file name", self.FileName, self.CurrentLineNumber)
|
||||||
IncFileName = self.__Token
|
IncFileName = self.__Token
|
||||||
__IncludeMacros = {}
|
PreIndex = 0
|
||||||
for Macro in ['WORKSPACE', 'ECP_SOURCE', 'EFI_SOURCE', 'EDK_SOURCE']:
|
StartPos = IncFileName.find('$(', PreIndex)
|
||||||
|
EndPos = IncFileName.find(')', StartPos+2)
|
||||||
|
while StartPos != -1 and EndPos != -1:
|
||||||
|
Macro = IncFileName[StartPos+2 : EndPos]
|
||||||
MacroVal = self.__GetMacroValue(Macro)
|
MacroVal = self.__GetMacroValue(Macro)
|
||||||
if MacroVal:
|
if not MacroVal:
|
||||||
__IncludeMacros[Macro] = MacroVal
|
if Macro in MacroDict:
|
||||||
|
MacroVal = MacroDict[Macro]
|
||||||
|
if MacroVal != None:
|
||||||
|
IncFileName = IncFileName.replace('$(' + Macro + ')', MacroVal, 1)
|
||||||
|
if MacroVal.find('$(') != -1:
|
||||||
|
PreIndex = StartPos
|
||||||
|
else:
|
||||||
|
PreIndex = StartPos + len(MacroVal)
|
||||||
|
else:
|
||||||
|
raise Warning("The Macro %s is not defined" %Macro, self.FileName, self.CurrentLineNumber)
|
||||||
|
StartPos = IncFileName.find('$(', PreIndex)
|
||||||
|
EndPos = IncFileName.find(')', StartPos+2)
|
||||||
|
|
||||||
try:
|
IncludedFile = NormPath(IncFileName)
|
||||||
IncludedFile = NormPath(ReplaceMacro(IncFileName, __IncludeMacros, RaiseError=True))
|
|
||||||
except:
|
|
||||||
raise Warning("only these system environment variables are permitted to start the path of the included file: "
|
|
||||||
"$(WORKSPACE), $(ECP_SOURCE), $(EFI_SOURCE), $(EDK_SOURCE)",
|
|
||||||
self.FileName, self.CurrentLineNumber)
|
|
||||||
#
|
#
|
||||||
# First search the include file under the same directory as FDF file
|
# First search the include file under the same directory as FDF file
|
||||||
#
|
#
|
||||||
|
|
Loading…
Reference in New Issue