X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FSource%2FPython%2FUPT%2FLibrary%2FParsing.py;h=81729d6cdbf7b3a2c43e6bfaf6072117e128296d;hp=db0fec3a73cc04eab10f3b52d5dddd6577a2c235;hb=ac107416484b74e5d412f7b48268761f9ba95afe;hpb=421ccda3079077dd613308526e02d797f5cc356a
diff --git a/BaseTools/Source/Python/UPT/Library/Parsing.py b/BaseTools/Source/Python/UPT/Library/Parsing.py
index db0fec3a73..81729d6cdb 100644
--- a/BaseTools/Source/Python/UPT/Library/Parsing.py
+++ b/BaseTools/Source/Python/UPT/Library/Parsing.py
@@ -1,12 +1,12 @@
## @file
-# This file is used to define common parsing related functions used in parsing
+# This file is used to define common parsing related functions used in parsing
# INF/DEC/DSC process
#
-# Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.
#
-# This program and the accompanying materials are licensed and made available
-# under the terms and conditions of the BSD License which accompanies this
-# distribution. The full text of the license may be found at
+# This program and the accompanying materials are licensed and made available
+# under the terms and conditions of the BSD License which accompanies this
+# distribution. The full text of the license may be found at
# http://opensource.org/licenses/bsd-license.php
#
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
@@ -16,6 +16,7 @@
'''
Parsing
'''
+from __future__ import absolute_import
##
# Import Modules
@@ -23,12 +24,12 @@ Parsing
import os.path
import re
-from Library.String import RaiseParserError
-from Library.String import GetSplitValueList
-from Library.String import CheckFileType
-from Library.String import CheckFileExist
-from Library.String import CleanString
-from Library.String import NormPath
+from Library.StringUtils import RaiseParserError
+from Library.StringUtils import GetSplitValueList
+from Library.StringUtils import CheckFileType
+from Library.StringUtils import CheckFileExist
+from Library.StringUtils import CleanString
+from Library.StringUtils import NormPath
from Logger.ToolError import FILE_NOT_FOUND
from Logger.ToolError import FatalError
@@ -42,7 +43,7 @@ from Logger import StringTable as ST
import Logger.Log as Logger
from Parser.DecParser import Dec
-import GlobalData
+from . import GlobalData
gPKG_INFO_DICT = {}
@@ -74,7 +75,7 @@ def GetBuildOption(String, File, LineNo= -1):
# Get Library of Dsc as |
#
# @param Item: String as |
-# @param ContainerFile: The file which describes the library class, used for
+# @param ContainerFile: The file which describes the library class, used for
# error report
#
def GetLibraryClass(Item, ContainerFile, WorkspaceDir, LineNo= -1):
@@ -99,7 +100,7 @@ def GetLibraryClass(Item, ContainerFile, WorkspaceDir, LineNo= -1):
# [|.]
#
# @param Item: String as |
-# @param ContainerFile: The file which describes the library class, used for
+# @param ContainerFile: The file which describes the library class, used for
# error report
#
def GetLibraryClassOfInf(Item, ContainerFile, WorkspaceDir, LineNo= -1):
@@ -134,7 +135,7 @@ def GetLibraryClassOfInf(Item, ContainerFile, WorkspaceDir, LineNo= -1):
#
def CheckPcdTokenInfo(TokenInfoString, Section, File, LineNo= -1):
Format = '.'
- if TokenInfoString != '' and TokenInfoString != None:
+ if TokenInfoString != '' and TokenInfoString is not None:
TokenInfoList = GetSplitValueList(TokenInfoString, DataType.TAB_SPLIT)
if len(TokenInfoList) == 2:
return True
@@ -148,7 +149,7 @@ def CheckPcdTokenInfo(TokenInfoString, Section, File, LineNo= -1):
#
# @param Item: String as .|
# [||]
-# @param ContainerFile: The file which describes the pcd, used for error
+# @param ContainerFile: The file which describes the pcd, used for error
# report
#
@@ -176,7 +177,7 @@ def GetPcd(Item, Type, ContainerFile, LineNo= -1):
#
# @param Item: String as
# .|TRUE/FALSE
-# @param ContainerFile: The file which describes the pcd, used for error
+# @param ContainerFile: The file which describes the pcd, used for error
# report
#
def GetFeatureFlagPcd(Item, Type, ContainerFile, LineNo= -1):
@@ -200,7 +201,7 @@ def GetFeatureFlagPcd(Item, Type, ContainerFile, LineNo= -1):
#
# @param Item: String as .|
# TRUE/FALSE
-# @param ContainerFile: The file which describes the pcd, used for error
+# @param ContainerFile: The file which describes the pcd, used for error
# report
#
def GetDynamicDefaultPcd(Item, Type, ContainerFile, LineNo= -1):
@@ -226,7 +227,7 @@ def GetDynamicDefaultPcd(Item, Type, ContainerFile, LineNo= -1):
#
# @param Item: String as .|
# TRUE/FALSE
-# @param ContainerFile: The file which describes the pcd, used for error
+# @param ContainerFile: The file which describes the pcd, used for error
# report
#
def GetDynamicHiiPcd(Item, Type, ContainerFile, LineNo= -1):
@@ -253,7 +254,7 @@ def GetDynamicHiiPcd(Item, Type, ContainerFile, LineNo= -1):
#
# @param Item: String as .
# |TRUE/FALSE
-# @param ContainerFile: The file which describes the pcd, used for error
+# @param ContainerFile: The file which describes the pcd, used for error
# report
#
def GetDynamicVpdPcd(Item, Type, ContainerFile, LineNo= -1):
@@ -273,7 +274,7 @@ def GetDynamicVpdPcd(Item, Type, ContainerFile, LineNo= -1):
## GetComponent
#
# Parse block of the components defined in dsc file
-# Set KeyValues as [ ['component name', [lib1, lib2, lib3],
+# Set KeyValues as [ ['component name', [lib1, lib2, lib3],
# [bo1, bo2, bo3], [pcd1, pcd2, pcd3]], ...]
#
# @param Lines: The content to be parsed
@@ -408,7 +409,7 @@ def GetExec(String):
## GetComponents
#
# Parse block of the components defined in dsc file
-# Set KeyValues as [ ['component name', [lib1, lib2, lib3], [bo1, bo2, bo3],
+# Set KeyValues as [ ['component name', [lib1, lib2, lib3], [bo1, bo2, bo3],
# [pcd1, pcd2, pcd3]], ...]
#
# @param Lines: The content to be parsed
@@ -433,7 +434,7 @@ def GetComponents(Lines, KeyValues, CommentCharacter):
LineList = Lines.split('\n')
for Line in LineList:
Line = CleanString(Line, CommentCharacter)
- if Line == None or Line == '':
+ if Line is None or Line == '':
continue
if FindBlock == False:
@@ -531,7 +532,7 @@ def GetComponents(Lines, KeyValues, CommentCharacter):
#
# @param Item: String as [|[|[|
# [|]]]]
-# @param ContainerFile: The file which describes the library class, used
+# @param ContainerFile: The file which describes the library class, used
# for error report
#
def GetSource(Item, ContainerFile, FileRelativePath, LineNo= -1):
@@ -556,7 +557,7 @@ def GetSource(Item, ContainerFile, FileRelativePath, LineNo= -1):
#
# @param Item: String as [|[|
# [|[|]]]]
-# @param ContainerFile: The file which describes the library class,
+# @param ContainerFile: The file which describes the library class,
# used for error report
#
def GetBinary(Item, ContainerFile, LineNo= -1):
@@ -580,7 +581,7 @@ def GetBinary(Item, ContainerFile, LineNo= -1):
#
# @param Item: String as [|]
# @param Type: Type of parsing string
-# @param ContainerFile: The file which describes the library class,
+# @param ContainerFile: The file which describes the library class,
# used for error report
#
def GetGuidsProtocolsPpisOfInf(Item):
@@ -594,7 +595,7 @@ def GetGuidsProtocolsPpisOfInf(Item):
#
# @param Item: String as =
# @param Type: Type of parsing string
-# @param ContainerFile: The file which describes the library class,
+# @param ContainerFile: The file which describes the library class,
# used for error report
#
def GetGuidsProtocolsPpisOfDec(Item, Type, ContainerFile, LineNo= -1):
@@ -625,7 +626,7 @@ def GetGuidsProtocolsPpisOfDec(Item, Type, ContainerFile, LineNo= -1):
#
# @param Item: String as [|]
# @param Type: Type of parsing string
-# @param ContainerFile: The file which describes the library class,
+# @param ContainerFile: The file which describes the library class,
# used for error report
#
def GetPackage(Item, ContainerFile, FileRelativePath, LineNo= -1):
@@ -827,21 +828,23 @@ def GetPkgInfoFromDec(Path):
def GetWorkspacePackage():
DecFileList = []
WorkspaceDir = GlobalData.gWORKSPACE
- for Root, Dirs, Files in os.walk(WorkspaceDir):
- if 'CVS' in Dirs:
- Dirs.remove('CVS')
- if '.svn' in Dirs:
- Dirs.remove('.svn')
- for Dir in Dirs:
- if Dir.startswith('.'):
- Dirs.remove(Dir)
- for FileSp in Files:
- if FileSp.startswith('.'):
- continue
- Ext = os.path.splitext(FileSp)[1]
- if Ext.lower() in ['.dec']:
- DecFileList.append\
- (os.path.normpath(os.path.join(Root, FileSp)))
+ PackageDir = GlobalData.gPACKAGE_PATH
+ for PkgRoot in [WorkspaceDir] + PackageDir:
+ for Root, Dirs, Files in os.walk(PkgRoot):
+ if 'CVS' in Dirs:
+ Dirs.remove('CVS')
+ if '.svn' in Dirs:
+ Dirs.remove('.svn')
+ for Dir in Dirs:
+ if Dir.startswith('.'):
+ Dirs.remove(Dir)
+ for FileSp in Files:
+ if FileSp.startswith('.'):
+ continue
+ Ext = os.path.splitext(FileSp)[1]
+ if Ext.lower() in ['.dec']:
+ DecFileList.append\
+ (os.path.normpath(os.path.join(Root, FileSp)))
#
# abstract package guid, version info from DecFile List
#
@@ -919,7 +922,7 @@ def MacroParser(Line, FileName, SectionType, FileLocalMacros):
FileLocalMacros[Name] = Value
ReIsValidMacroName = re.compile(r"^[A-Z][A-Z0-9_]*$", re.DOTALL)
- if ReIsValidMacroName.match(Name) == None:
+ if ReIsValidMacroName.match(Name) is None:
Logger.Error('Parser',
FORMAT_INVALID,
ST.ERR_MACRONAME_INVALID % (Name),
@@ -934,11 +937,11 @@ def MacroParser(Line, FileName, SectionType, FileLocalMacros):
# ::= {} {} {} {}
# {} {} {}
#
- # The definition of , , , , ,
+ # The definition of , , , , ,
# , are subset of .
#
ReIsValidMacroValue = re.compile(r"^[\x20-\x7e]*$", re.DOTALL)
- if ReIsValidMacroValue.match(Value) == None:
+ if ReIsValidMacroValue.match(Value) is None:
Logger.Error('Parser',
FORMAT_INVALID,
ST.ERR_MACROVALUE_INVALID % (Value),
@@ -948,15 +951,15 @@ def MacroParser(Line, FileName, SectionType, FileLocalMacros):
return Name, Value
-## GenSection
+## GenSection
#
# generate section contents
#
-# @param SectionName: indicate the name of the section, details refer to
+# @param SectionName: indicate the name of the section, details refer to
# INF, DEC specs
-# @param SectionDict: section statement dict, key is SectionAttrs(arch,
-# moduletype or platform may exist as needed) list
-# seperated by space,
+# @param SectionDict: section statement dict, key is SectionAttrs(arch,
+# moduletype or platform may exist as needed) list
+# seperated by space,
# value is statement
#
def GenSection(SectionName, SectionDict, SplitArch=True, NeedBlankLine=False):
@@ -977,13 +980,13 @@ def GenSection(SectionName, SectionDict, SplitArch=True, NeedBlankLine=False):
else:
Section = '[' + SectionName + ']'
Content += '\n' + Section + '\n'
- if StatementList != None:
+ if StatementList is not None:
for Statement in StatementList:
LineList = Statement.split('\n')
NewStatement = ""
for Line in LineList:
# ignore blank comment
- if not Line.replace("#", '').strip() and SectionName != 'Defines':
+ if not Line.replace("#", '').strip() and SectionName not in ('Defines', 'Hob', 'Event', 'BootMode'):
continue
# add two space before non-comments line except the comments in Defines section
if Line.strip().startswith('#') and SectionName == 'Defines':
@@ -1002,10 +1005,10 @@ def GenSection(SectionName, SectionDict, SplitArch=True, NeedBlankLine=False):
return Content
## ConvertArchForInstall
-# if Arch.upper() is in "IA32", "X64", "IPF", and "EBC", it must be upper case. "common" must be lower case.
+# if Arch.upper() is in "IA32", "X64", "IPF", and "EBC", it must be upper case. "common" must be lower case.
# Anything else, the case must be preserved
#
-# @param Arch: the arch string that need to be converted, it should be stripped before pass in
+# @param Arch: the arch string that need to be converted, it should be stripped before pass in
# @return: the arch string that get converted
#
def ConvertArchForInstall(Arch):