]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Workspace - refactor RegEx to minimize multiple compiling
authorCarsey, Jaben <jaben.carsey@intel.com>
Fri, 20 Apr 2018 15:51:24 +0000 (23:51 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Thu, 26 Apr 2018 06:35:36 +0000 (14:35 +0800)
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>
BaseTools/Source/Python/Workspace/DscBuildData.py
BaseTools/Source/Python/Workspace/MetaFileParser.py

index 7e3187fb5d2d82720dd353d1f27371c3cdad1528..e335b3df85af8980cba337b8000463ab062bae00 100644 (file)
@@ -89,6 +89,8 @@ MAKEROOT ?= $(EDK_TOOLS_PATH)/Source/C
 LIBS = -lCommon\r
 '''\r
 \r
+variablePattern = re.compile(r'[\t\s]*0[xX][a-fA-F0-9]+$')\r
+\r
 ## regular expressions for finding decimal and hex numbers\r
 Pattern = re.compile('^[1-9]\d*|0$')\r
 HexPattern = re.compile(r'0[xX][0-9a-fA-F]+$')\r
@@ -2415,7 +2417,7 @@ class DscBuildData(PlatformBuildClassObject):
             if VariableOffset.isdigit():\r
                 if int(VariableOffset, 10) > 0xFFFF:\r
                     ExceedMax = True\r
-            elif re.match(r'[\t\s]*0[xX][a-fA-F0-9]+$', VariableOffset):\r
+            elif variablePattern.match(VariableOffset):\r
                 if int(VariableOffset, 16) > 0xFFFF:\r
                     ExceedMax = True\r
             # For Offset written in "A.B"\r
index 322ed384496658635e8b87c1de4e75d6d564713c..550359f9abb261367600dd269784912419b841b8 100644 (file)
@@ -35,6 +35,10 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
 from MetaFileTable import MetaFileStorage\r
 from MetaFileCommentParser import CheckInfComment\r
 \r
+## RegEx for finding file versions\r
+hexVersionPattern = re.compile(r'0[xX][\da-f-A-F]{5,8}')\r
+decVersionPattern = re.compile(r'\d+\.\d+')\r
+\r
 ## A decorator used to parse macro definition\r
 def ParseMacro(Parser):\r
     def MacroParser(self):\r
@@ -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)\r
         # Sometimes, we need to make differences between EDK and EDK2 modules \r
         if Name == 'INF_VERSION':\r
-            if re.match(r'0[xX][\da-f-A-F]{5,8}', Value):\r
+            if hexVersionPattern.match(Value):\r
                 self._Version = int(Value, 0)   \r
-            elif re.match(r'\d+\.\d+', Value):\r
+            elif decVersionPattern.match(Value):\r
                 ValueList = Value.split('.')\r
                 Major = '%04o' % int(ValueList[0], 0)\r
                 Minor = '%04o' % int(ValueList[1], 0)\r