diff --git a/BaseTools/Source/Python/Workspace/DscBuildData.py b/BaseTools/Source/Python/Workspace/DscBuildData.py index 7e3187fb5d..e335b3df85 100644 --- a/BaseTools/Source/Python/Workspace/DscBuildData.py +++ b/BaseTools/Source/Python/Workspace/DscBuildData.py @@ -89,6 +89,8 @@ MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C LIBS = -lCommon ''' +variablePattern = re.compile(r'[\t\s]*0[xX][a-fA-F0-9]+$') + ## regular expressions for finding decimal and hex numbers Pattern = re.compile('^[1-9]\d*|0$') HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$') @@ -2415,7 +2417,7 @@ class DscBuildData(PlatformBuildClassObject): if VariableOffset.isdigit(): if int(VariableOffset, 10) > 0xFFFF: ExceedMax = True - elif re.match(r'[\t\s]*0[xX][a-fA-F0-9]+$', VariableOffset): + elif variablePattern.match(VariableOffset): if int(VariableOffset, 16) > 0xFFFF: ExceedMax = True # For Offset written in "A.B" diff --git a/BaseTools/Source/Python/Workspace/MetaFileParser.py b/BaseTools/Source/Python/Workspace/MetaFileParser.py index 322ed38449..550359f9ab 100644 --- a/BaseTools/Source/Python/Workspace/MetaFileParser.py +++ b/BaseTools/Source/Python/Workspace/MetaFileParser.py @@ -35,6 +35,10 @@ from Common.LongFilePathSupport import OpenLongFilePath as open from MetaFileTable import MetaFileStorage from MetaFileCommentParser import CheckInfComment +## RegEx for finding file versions +hexVersionPattern = re.compile(r'0[xX][\da-f-A-F]{5,8}') +decVersionPattern = re.compile(r'\d+\.\d+') + ## A decorator used to parse macro definition def ParseMacro(Parser): def MacroParser(self): @@ -366,9 +370,9 @@ class MetaFileParser(object): EdkLogger.error("Parser", FORMAT_INVALID, "%s not defined" % (Macro), ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1) # Sometimes, we need to make differences between EDK and EDK2 modules if Name == 'INF_VERSION': - if re.match(r'0[xX][\da-f-A-F]{5,8}', Value): + if hexVersionPattern.match(Value): self._Version = int(Value, 0) - elif re.match(r'\d+\.\d+', Value): + elif decVersionPattern.match(Value): ValueList = Value.split('.') Major = '%04o' % int(ValueList[0], 0) Minor = '%04o' % int(ValueList[1], 0)