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>
CurrentFileDependencyList = DepDb[F]\r
else:\r
try:\r
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
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
- IncludedFileList = gIncludePattern.findall(FileContent)\r
\r
for Inc in IncludedFileList:\r
Inc = Inc.strip()\r
\r
for Inc in IncludedFileList:\r
Inc = Inc.strip()\r