summaryrefslogtreecommitdiff
path: root/BaseTools/Source/Python/UPT/Library/Parsing.py
diff options
context:
space:
mode:
Diffstat (limited to 'BaseTools/Source/Python/UPT/Library/Parsing.py')
-rw-r--r--BaseTools/Source/Python/UPT/Library/Parsing.py115
1 files changed, 70 insertions, 45 deletions
diff --git a/BaseTools/Source/Python/UPT/Library/Parsing.py b/BaseTools/Source/Python/UPT/Library/Parsing.py
index 95c51406b2..db0fec3a73 100644
--- a/BaseTools/Source/Python/UPT/Library/Parsing.py
+++ b/BaseTools/Source/Python/UPT/Library/Parsing.py
@@ -2,7 +2,7 @@
# This file is used to define common parsing related functions used in parsing
# INF/DEC/DSC process
#
-# Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
#
# This program and the accompanying materials are licensed and made available
# under the terms and conditions of the BSD License which accompanies this
@@ -42,6 +42,7 @@ from Logger import StringTable as ST
import Logger.Log as Logger
from Parser.DecParser import Dec
+import GlobalData
gPKG_INFO_DICT = {}
@@ -53,7 +54,7 @@ gPKG_INFO_DICT = {}
# @param String: String with BuildOption statement
# @param File: The file which defines build option, used in error report
#
-def GetBuildOption(String, File, LineNo=-1):
+def GetBuildOption(String, File, LineNo= -1):
(Family, ToolChain, Flag) = ('', '', '')
if String.find(DataType.TAB_EQUAL_SPLIT) < 0:
RaiseParserError(String, 'BuildOptions', File, \
@@ -76,7 +77,7 @@ def GetBuildOption(String, File, LineNo=-1):
# @param ContainerFile: The file which describes the library class, used for
# error report
#
-def GetLibraryClass(Item, ContainerFile, WorkspaceDir, LineNo=-1):
+def GetLibraryClass(Item, ContainerFile, WorkspaceDir, LineNo= -1):
List = GetSplitValueList(Item[0])
SupMod = DataType.SUP_MODULE_LIST_STRING
if len(List) != 2:
@@ -101,7 +102,7 @@ def GetLibraryClass(Item, ContainerFile, WorkspaceDir, LineNo=-1):
# @param ContainerFile: The file which describes the library class, used for
# error report
#
-def GetLibraryClassOfInf(Item, ContainerFile, WorkspaceDir, LineNo = -1):
+def GetLibraryClassOfInf(Item, ContainerFile, WorkspaceDir, LineNo= -1):
ItemList = GetSplitValueList((Item[0] + DataType.TAB_VALUE_SPLIT * 2))
SupMod = DataType.SUP_MODULE_LIST_STRING
@@ -131,7 +132,7 @@ def GetLibraryClassOfInf(Item, ContainerFile, WorkspaceDir, LineNo = -1):
# @param Section: Used for error report
# @param File: Used for error report
#
-def CheckPcdTokenInfo(TokenInfoString, Section, File, LineNo=-1):
+def CheckPcdTokenInfo(TokenInfoString, Section, File, LineNo= -1):
Format = '<TokenSpaceGuidCName>.<PcdCName>'
if TokenInfoString != '' and TokenInfoString != None:
TokenInfoList = GetSplitValueList(TokenInfoString, DataType.TAB_SPLIT)
@@ -151,7 +152,7 @@ def CheckPcdTokenInfo(TokenInfoString, Section, File, LineNo=-1):
# report
#
-def GetPcd(Item, Type, ContainerFile, LineNo=-1):
+def GetPcd(Item, Type, ContainerFile, LineNo= -1):
TokenGuid, TokenName, Value, MaximumDatumSize, Token = '', '', '', '', ''
List = GetSplitValueList(Item + DataType.TAB_VALUE_SPLIT * 2)
@@ -178,7 +179,7 @@ def GetPcd(Item, Type, ContainerFile, LineNo=-1):
# @param ContainerFile: The file which describes the pcd, used for error
# report
#
-def GetFeatureFlagPcd(Item, Type, ContainerFile, LineNo=-1):
+def GetFeatureFlagPcd(Item, Type, ContainerFile, LineNo= -1):
TokenGuid, TokenName, Value = '', '', ''
List = GetSplitValueList(Item)
if len(List) != 2:
@@ -202,7 +203,7 @@ def GetFeatureFlagPcd(Item, Type, ContainerFile, LineNo=-1):
# @param ContainerFile: The file which describes the pcd, used for error
# report
#
-def GetDynamicDefaultPcd(Item, Type, ContainerFile, LineNo=-1):
+def GetDynamicDefaultPcd(Item, Type, ContainerFile, LineNo= -1):
TokenGuid, TokenName, Value, DatumTyp, MaxDatumSize = '', '', '', '', ''
List = GetSplitValueList(Item + DataType.TAB_VALUE_SPLIT * 2)
if len(List) < 4 or len(List) > 8:
@@ -228,7 +229,7 @@ def GetDynamicDefaultPcd(Item, Type, ContainerFile, LineNo=-1):
# @param ContainerFile: The file which describes the pcd, used for error
# report
#
-def GetDynamicHiiPcd(Item, Type, ContainerFile, LineNo = -1):
+def GetDynamicHiiPcd(Item, Type, ContainerFile, LineNo= -1):
TokenGuid, TokenName, List1, List2, List3, List4, List5 = \
'', '', '', '', '', '', ''
List = GetSplitValueList(Item + DataType.TAB_VALUE_SPLIT * 2)
@@ -255,7 +256,7 @@ def GetDynamicHiiPcd(Item, Type, ContainerFile, LineNo = -1):
# @param ContainerFile: The file which describes the pcd, used for error
# report
#
-def GetDynamicVpdPcd(Item, Type, ContainerFile, LineNo=-1):
+def GetDynamicVpdPcd(Item, Type, ContainerFile, LineNo= -1):
TokenGuid, TokenName, List1, List2 = '', '', '', ''
List = GetSplitValueList(Item + DataType.TAB_VALUE_SPLIT)
if len(List) < 3 or len(List) > 4:
@@ -533,7 +534,7 @@ def GetComponents(Lines, KeyValues, CommentCharacter):
# @param ContainerFile: The file which describes the library class, used
# for error report
#
-def GetSource(Item, ContainerFile, FileRelativePath, LineNo=-1):
+def GetSource(Item, ContainerFile, FileRelativePath, LineNo= -1):
ItemNew = Item + DataType.TAB_VALUE_SPLIT * 4
List = GetSplitValueList(ItemNew)
if len(List) < 5 or len(List) > 9:
@@ -558,7 +559,7 @@ def GetSource(Item, ContainerFile, FileRelativePath, LineNo=-1):
# @param ContainerFile: The file which describes the library class,
# used for error report
#
-def GetBinary(Item, ContainerFile, LineNo=-1):
+def GetBinary(Item, ContainerFile, LineNo= -1):
ItemNew = Item + DataType.TAB_VALUE_SPLIT
List = GetSplitValueList(ItemNew)
if len(List) < 3 or len(List) > 5:
@@ -596,7 +597,7 @@ def GetGuidsProtocolsPpisOfInf(Item):
# @param ContainerFile: The file which describes the library class,
# used for error report
#
-def GetGuidsProtocolsPpisOfDec(Item, Type, ContainerFile, LineNo=-1):
+def GetGuidsProtocolsPpisOfDec(Item, Type, ContainerFile, LineNo= -1):
List = GetSplitValueList(Item, DataType.TAB_EQUAL_SPLIT)
if len(List) != 2:
RaiseParserError(Item, Type, ContainerFile, '<CName>=<GuidValue>', \
@@ -614,7 +615,7 @@ def GetGuidsProtocolsPpisOfDec(Item, Type, ContainerFile, LineNo=-1):
RegisterFormatGuid = List[1]
else:
RaiseParserError(Item, Type, ContainerFile, \
- 'CFormat or RegisterFormat', LineNo)
+ 'CFormat or RegisterFormat', LineNo)
return (List[0], RegisterFormatGuid)
@@ -627,7 +628,7 @@ def GetGuidsProtocolsPpisOfDec(Item, Type, ContainerFile, LineNo=-1):
# @param ContainerFile: The file which describes the library class,
# used for error report
#
-def GetPackage(Item, ContainerFile, FileRelativePath, LineNo=-1):
+def GetPackage(Item, ContainerFile, FileRelativePath, LineNo= -1):
ItemNew = Item + DataType.TAB_VALUE_SPLIT
List = GetSplitValueList(ItemNew)
CheckFileType(List[0], '.Dec', ContainerFile, 'package', List[0], LineNo)
@@ -683,7 +684,7 @@ def GetPcdOfInf(Item, Type, File, LineNo):
# @param File: Dec file
# @param LineNo: Line number
#
-def GetPcdOfDec(Item, Type, File, LineNo=-1):
+def GetPcdOfDec(Item, Type, File, LineNo= -1):
Format = '<TokenSpaceGuidCName>.<PcdCName>|<Value>|<DatumType>|<Token>'
TokenGuid, TokenName, Value, DatumType, Token = '', '', '', '', ''
List = GetSplitValueList(Item)
@@ -756,7 +757,7 @@ def InsertSectionItems(Model, SectionItemList, ArchList, \
LineValue, StartLine, Comment = SectionItem[0], \
SectionItem[1], SectionItem[2]
- Logger.Debug(4, ST.MSG_PARSING %LineValue)
+ Logger.Debug(4, ST.MSG_PARSING % LineValue)
#
# And then parse DEFINE statement
#
@@ -782,7 +783,7 @@ def GenMetaDatSectionItem(Key, Value, List):
List[Key] = [Value]
else:
List[Key].append(Value)
-
+
## GetPkgInfoFromDec
#
# get package name, guid, version info from dec files
@@ -793,17 +794,23 @@ def GetPkgInfoFromDec(Path):
PkgName = None
PkgGuid = None
PkgVersion = None
-
+
Path = Path.replace('\\', '/')
-
+
if not os.path.exists(Path):
- Logger.Error("\nUPT", FILE_NOT_FOUND, File = Path)
+ Logger.Error("\nUPT", FILE_NOT_FOUND, File=Path)
if Path in gPKG_INFO_DICT:
return gPKG_INFO_DICT[Path]
try:
- DecParser = Dec(Path)
+ DecParser = None
+ if Path not in GlobalData.gPackageDict:
+ DecParser = Dec(Path)
+ GlobalData.gPackageDict[Path] = DecParser
+ else:
+ DecParser = GlobalData.gPackageDict[Path]
+
PkgName = DecParser.GetPackageName()
PkgGuid = DecParser.GetPackageGuid()
PkgVersion = DecParser.GetPackageVersion()
@@ -819,7 +826,7 @@ def GetPkgInfoFromDec(Path):
#
def GetWorkspacePackage():
DecFileList = []
- WorkspaceDir = os.environ["WORKSPACE"]
+ WorkspaceDir = GlobalData.gWORKSPACE
for Root, Dirs, Files in os.walk(WorkspaceDir):
if 'CVS' in Dirs:
Dirs.remove('CVS')
@@ -843,7 +850,7 @@ def GetWorkspacePackage():
(PkgName, PkgGuid, PkgVersion) = GetPkgInfoFromDec(DecFile)
if PkgName and PkgGuid and PkgVersion:
PkgList.append((PkgName, PkgGuid, PkgVersion, DecFile))
-
+
return PkgList
## GetWorkspaceModule
@@ -852,7 +859,7 @@ def GetWorkspacePackage():
#
def GetWorkspaceModule():
InfFileList = []
- WorkspaceDir = os.environ["WORKSPACE"]
+ WorkspaceDir = GlobalData.gWORKSPACE
for Root, Dirs, Files in os.walk(WorkspaceDir):
if 'CVS' in Dirs:
Dirs.remove('CVS')
@@ -870,7 +877,7 @@ def GetWorkspaceModule():
if Ext.lower() in ['.inf']:
InfFileList.append\
(os.path.normpath(os.path.join(Root, FileSp)))
-
+
return InfFileList
## MacroParser used to parse macro definition
@@ -890,7 +897,7 @@ def MacroParser(Line, FileName, SectionType, FileLocalMacros):
# Not 'DEFINE/EDK_GLOBAL' statement, call decorated method
#
return None, None
-
+
TokenList = GetSplitValueList(LineContent[Match.end(1):], \
DataType.TAB_EQUAL_SPLIT, 1)
#
@@ -910,16 +917,16 @@ def MacroParser(Line, FileName, SectionType, FileLocalMacros):
#
if SectionType == DataType.MODEL_META_DATA_HEADER:
FileLocalMacros[Name] = Value
-
+
ReIsValidMacroName = re.compile(r"^[A-Z][A-Z0-9_]*$", re.DOTALL)
if ReIsValidMacroName.match(Name) == None:
- Logger.Error('Parser',
- FORMAT_INVALID,
- ST.ERR_MACRONAME_INVALID%(Name),
- ExtraData=LineContent,
- File=FileName,
+ Logger.Error('Parser',
+ FORMAT_INVALID,
+ ST.ERR_MACRONAME_INVALID % (Name),
+ ExtraData=LineContent,
+ File=FileName,
Line=LineNo)
-
+
# Validate MACRO Value
#
# <MacroDefinition> ::= [<Comments>]{0,}
@@ -932,13 +939,13 @@ def MacroParser(Line, FileName, SectionType, FileLocalMacros):
#
ReIsValidMacroValue = re.compile(r"^[\x20-\x7e]*$", re.DOTALL)
if ReIsValidMacroValue.match(Value) == None:
- Logger.Error('Parser',
- FORMAT_INVALID,
- ST.ERR_MACROVALUE_INVALID%(Value),
- ExtraData=LineContent,
- File=FileName,
+ Logger.Error('Parser',
+ FORMAT_INVALID,
+ ST.ERR_MACROVALUE_INVALID % (Value),
+ ExtraData=LineContent,
+ File=FileName,
Line=LineNo)
-
+
return Name, Value
## GenSection
@@ -952,7 +959,7 @@ def MacroParser(Line, FileName, SectionType, FileLocalMacros):
# seperated by space,
# value is statement
#
-def GenSection(SectionName, SectionDict, SplitArch=True):
+def GenSection(SectionName, SectionDict, SplitArch=True, NeedBlankLine=False):
Content = ''
for SectionAttrs in SectionDict:
StatementList = SectionDict[SectionAttrs]
@@ -969,11 +976,29 @@ def GenSection(SectionName, SectionDict, SplitArch=True):
Section = '[' + SectionName + '.' + (', ' + SectionName + '.').join(ArchList) + ']'
else:
Section = '[' + SectionName + ']'
- Content += '\n\n' + Section + '\n'
+ Content += '\n' + Section + '\n'
if StatementList != None:
for Statement in StatementList:
- Content += Statement + '\n'
+ LineList = Statement.split('\n')
+ NewStatement = ""
+ for Line in LineList:
+ # ignore blank comment
+ if not Line.replace("#", '').strip() and SectionName != 'Defines':
+ continue
+ # add two space before non-comments line except the comments in Defines section
+ if Line.strip().startswith('#') and SectionName == 'Defines':
+ NewStatement += "%s\n" % Line
+ continue
+ NewStatement += " %s\n" % Line
+ if NeedBlankLine:
+ Content += NewStatement + '\n'
+ else:
+ Content += NewStatement
+ if NeedBlankLine:
+ Content = Content[:-1]
+ if not Content.replace('\\n', '').strip():
+ return ''
return Content
## ConvertArchForInstall
@@ -984,10 +1009,10 @@ def GenSection(SectionName, SectionDict, SplitArch=True):
# @return: the arch string that get converted
#
def ConvertArchForInstall(Arch):
- if Arch.upper() in [DataType.TAB_ARCH_IA32, DataType.TAB_ARCH_X64,
+ if Arch.upper() in [DataType.TAB_ARCH_IA32, DataType.TAB_ARCH_X64,
DataType.TAB_ARCH_IPF, DataType.TAB_ARCH_EBC]:
Arch = Arch.upper()
elif Arch.upper() == DataType.TAB_ARCH_COMMON:
Arch = Arch.lower()
-
+
return Arch