BaseTools: Improve GetDependencyList function
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>
This commit is contained in:
@ -1694,22 +1694,25 @@ def GetDependencyList(AutoGenObject, FileCache, File, ForceList, SearchPathList)
|
|||||||
CurrentFileDependencyList = DepDb[F]
|
CurrentFileDependencyList = DepDb[F]
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
Fd = open(F.Path, 'rb')
|
with open(F.Path, 'rb') as Fd:
|
||||||
FileContent = Fd.read()
|
FileContent = Fd.read(1)
|
||||||
Fd.close()
|
Fd.seek(0)
|
||||||
|
if not FileContent:
|
||||||
|
continue
|
||||||
|
if FileContent[0] == 0xff or FileContent[0] == 0xfe:
|
||||||
|
FileContent2 = Fd.read()
|
||||||
|
FileContent2 = FileContent2.decode('utf-16')
|
||||||
|
IncludedFileList = gIncludePattern.findall(FileContent2)
|
||||||
|
else:
|
||||||
|
FileLines = Fd.readlines()
|
||||||
|
FileContent2 = [line for line in FileLines if str(line).lstrip("#\t ")[:8] == "include "]
|
||||||
|
simpleFileContent="".join(FileContent2)
|
||||||
|
|
||||||
|
IncludedFileList = gIncludePattern.findall(simpleFileContent)
|
||||||
except BaseException as X:
|
except BaseException as X:
|
||||||
EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=F.Path + "\n\t" + str(X))
|
EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=F.Path + "\n\t" + str(X))
|
||||||
if len(FileContent) == 0:
|
if not FileContent:
|
||||||
continue
|
continue
|
||||||
try:
|
|
||||||
if FileContent[0] == 0xff or FileContent[0] == 0xfe:
|
|
||||||
FileContent = FileContent.decode('utf-16')
|
|
||||||
else:
|
|
||||||
FileContent = FileContent.decode()
|
|
||||||
except:
|
|
||||||
# The file is not txt file. for example .mcb file
|
|
||||||
continue
|
|
||||||
IncludedFileList = gIncludePattern.findall(FileContent)
|
|
||||||
|
|
||||||
for Inc in IncludedFileList:
|
for Inc in IncludedFileList:
|
||||||
Inc = Inc.strip()
|
Inc = Inc.strip()
|
||||||
|
Reference in New Issue
Block a user