BaseTools: Workspace - refactor RegEx to minimize multiple compiling

Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Yonghong Zhu <yonghong.zhu@intel.com>
This commit is contained in:
Carsey, Jaben
2018-04-20 23:51:24 +08:00
committed by Yonghong Zhu
parent ef42ef7e6d
commit 3e4faa268e
2 changed files with 9 additions and 3 deletions

View File

@ -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)