From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.151, mailfrom: bob.c.feng@intel.com) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by groups.io with SMTP; Tue, 10 Sep 2019 02:16:57 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2019 02:16:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,489,1559545200"; d="scan'208";a="189284989" Received: from shwdepsi1121.ccr.corp.intel.com ([10.239.158.47]) by orsmga006.jf.intel.com with ESMTP; 10 Sep 2019 02:16:54 -0700 From: "Bob Feng" To: devel@edk2.groups.io Cc: Liming Gao , Bob Feng Subject: [Patch 1/3] BaseTools: Improve GetDependencyList function Date: Tue, 10 Sep 2019 17:16:50 +0800 Message-Id: <20190910091650.33060-1-bob.c.feng@intel.com> X-Mailer: git-send-email 2.20.1.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Bob Feng --- BaseTools/Source/Python/AutoGen/GenMake.py | 29 ++++++++++++---------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/BaseTools/Source/Python/AutoGen/GenMake.py b/BaseTools/Source/Python/AutoGen/GenMake.py index 47dae82e1aeb..5d02d9a05694 100755 --- a/BaseTools/Source/Python/AutoGen/GenMake.py +++ b/BaseTools/Source/Python/AutoGen/GenMake.py @@ -1690,26 +1690,29 @@ def GetDependencyList(AutoGenObject, FileCache, File, ForceList, SearchPathList) CurrentFileDependencyList = [] if F in DepDb: CurrentFileDependencyList = DepDb[F] else: try: - Fd = open(F.Path, 'rb') - FileContent = Fd.read() - Fd.close() + with open(F.Path, 'rb') as Fd: + FileContent = Fd.read(1) + 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: EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=F.Path + "\n\t" + str(X)) - if len(FileContent) == 0: + if not FileContent: 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: Inc = Inc.strip() # if there's macro used to reference header file, expand it HeaderList = gMacroPattern.findall(Inc) -- 2.20.1.windows.1