]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Improve GetDependencyList function
authorFeng, Bob C <bob.c.feng@intel.com>
Wed, 28 Aug 2019 08:56:11 +0000 (16:56 +0800)
committerFeng, Bob C <bob.c.feng@intel.com>
Tue, 17 Sep 2019 02:19:05 +0000 (10:19 +0800)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2102

GetDependencyList get the header file via
re.findall in the whole header file.

This patch is to pre-process the header file and
to feed the shorter string to re.findall.

This patch is to improve GetDependencyList() efficiency

Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/AutoGen/GenMake.py

index 3185ebe36816fffb1f2e12cda09f5d4cd3d3ca82..cda1fbe610e50edf1281aac2eecfa9dff64b89a4 100755 (executable)
@@ -1694,22 +1694,25 @@ def GetDependencyList(AutoGenObject, FileCache, File, ForceList, SearchPathList)
             CurrentFileDependencyList = DepDb[F]\r
         else:\r
             try:\r
-                Fd = open(F.Path, 'rb')\r
-                FileContent = Fd.read()\r
-                Fd.close()\r
+                with open(F.Path, 'rb') as Fd:\r
+                    FileContent = Fd.read(1)\r
+                    Fd.seek(0)\r
+                    if not FileContent:\r
+                        continue\r
+                    if FileContent[0] == 0xff or FileContent[0] == 0xfe:\r
+                        FileContent2 = Fd.read()\r
+                        FileContent2 = FileContent2.decode('utf-16')\r
+                        IncludedFileList = gIncludePattern.findall(FileContent2)\r
+                    else:\r
+                        FileLines = Fd.readlines()\r
+                        FileContent2 = [line for line in FileLines if str(line).lstrip("#\t ")[:8] == "include "]\r
+                        simpleFileContent="".join(FileContent2)\r
+\r
+                        IncludedFileList = gIncludePattern.findall(simpleFileContent)\r
             except BaseException as X:\r
                 EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=F.Path + "\n\t" + str(X))\r
-            if len(FileContent) == 0:\r
-                continue\r
-            try:\r
-                if FileContent[0] == 0xff or FileContent[0] == 0xfe:\r
-                    FileContent = FileContent.decode('utf-16')\r
-                else:\r
-                    FileContent = FileContent.decode()\r
-            except:\r
-                # The file is not txt file. for example .mcb file\r
+            if not FileContent:\r
                 continue\r
-            IncludedFileList = gIncludePattern.findall(FileContent)\r
 \r
             for Inc in IncludedFileList:\r
                 Inc = Inc.strip()\r