From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.100; helo=mga07.intel.com; envelope-from=bob.c.feng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 44743211B6C0E for ; Wed, 16 Jan 2019 23:46:46 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2019 23:46:45 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,488,1539673200"; d="scan'208";a="128478042" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga001.jf.intel.com with ESMTP; 16 Jan 2019 23:46:45 -0800 Received: from fmsmsx158.amr.corp.intel.com (10.18.116.75) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 16 Jan 2019 23:46:45 -0800 Received: from shsmsx108.ccr.corp.intel.com (10.239.4.97) by fmsmsx158.amr.corp.intel.com (10.18.116.75) with Microsoft SMTP Server (TLS) id 14.3.408.0; Wed, 16 Jan 2019 23:46:45 -0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.196]) by SHSMSX108.ccr.corp.intel.com ([169.254.8.85]) with mapi id 14.03.0415.000; Thu, 17 Jan 2019 15:46:42 +0800 From: "Feng, Bob C" To: "Carsey, Jaben" , "edk2-devel@lists.01.org" CC: "Gao, Liming" Thread-Topic: [Patch v1 1/5] BaseTools/build/build: refactor and move functions Thread-Index: AQHUqRPhmptamF5AWEWQuPbjY9TG46WzH1hg Date: Thu, 17 Jan 2019 07:46:41 +0000 Message-ID: <08650203BA1BD64D8AD9B6D5D74A85D16005CF7D@SHSMSX101.ccr.corp.intel.com> References: <38e1ccf7c2d5fe144f9fb63ddba77cc0c491fb67.1547145461.git.jaben.carsey@intel.com> In-Reply-To: <38e1ccf7c2d5fe144f9fb63ddba77cc0c491fb67.1547145461.git.jaben.carsey@intel.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [Patch v1 1/5] BaseTools/build/build: refactor and move functions X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jan 2019 07:46:46 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Bob Feng =20 -----Original Message----- From: Carsey, Jaben=20 Sent: Friday, January 11, 2019 2:40 AM To: edk2-devel@lists.01.org Cc: Feng, Bob C ; Gao, Liming Subject: [Patch v1 1/5] BaseTools/build/build: refactor and move functions Move DataDump and DataRestore from Common.Misc to this file. There were no other consumers of these 2 functions. Import threading since that module is used in build. Cc: Bob Feng Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Jaben Carsey --- BaseTools/Source/Python/Common/Misc.py | 37 ---------------- BaseTools/So= urce/Python/build/build.py | 46 ++++++++++++++++++-- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Pyth= on/Common/Misc.py index 76a73d1c33db..43e016febcbb 100644 --- a/BaseTools/Source/Python/Common/Misc.py +++ b/BaseTools/Source/Python/Common/Misc.py @@ -487,43 +487,6 @@ def SaveFileOnChange(File, Content, IsBinaryFile=3DTru= e): =20 return True =20 -## Make a Python object persistent on file system -# -# @param Data The object to be stored in file -# @param File The path of file to store the object -# -def DataDump(Data, File): - Fd =3D None - try: - Fd =3D open(File, 'wb') - pickle.dump(Data, Fd, pickle.HIGHEST_PROTOCOL) - except: - EdkLogger.error("", FILE_OPEN_FAILURE, ExtraData=3DFile, RaiseErro= r=3DFalse) - finally: - if Fd is not None: - Fd.close() - -## Restore a Python object from a file -# -# @param File The path of file stored the object -# -# @retval object A python object -# @retval None If failure in file operation -# -def DataRestore(File): - Data =3D None - Fd =3D None - try: - Fd =3D open(File, 'rb') - Data =3D pickle.load(Fd) - except Exception as e: - EdkLogger.verbose("Failed to load [%s]\n\t%s" % (File, str(e))) - Data =3D None - finally: - if Fd is not None: - Fd.close() - return Data - ## Retrieve and cache the real path name in file system # # @param Root The root directory of path relative to diff --git a/BaseTools/Source/Python/build/build.py b/BaseTools/Source/Pyth= on/build/build.py index b992a4c1b303..85b36cacd00c 100644 --- a/BaseTools/Source/Python/build/build.py +++ b/BaseTools/Source/Python/build/build.py @@ -32,6 +32,7 @@ import multiprocessing =20 from struct import * from threading import * +import threading from optparse import OptionParser from subprocess import * from Common import Misc as Utils @@ -71,6 +72,43 @@ gToolsDefinition =3D "tools_def.txt" TemporaryTablePattern =3D re.compile(r'^_\d+_\d+_[a-fA-F0-9]+$') TmpTableDict =3D {} =20 +## Make a Python object persistent on file system # +# @param Data The object to be stored in file +# @param File The path of file to store the object +# +def _DataDump(Data, File): + Fd =3D None + try: + Fd =3D open(File, 'wb') + pickle.dump(Data, Fd, pickle.HIGHEST_PROTOCOL) + except: + EdkLogger.error("", FILE_OPEN_FAILURE, ExtraData=3DFile, RaiseErro= r=3DFalse) + finally: + if Fd is not None: + Fd.close() + +## Restore a Python object from a file +# +# @param File The path of file stored the object +# +# @retval object A python object +# @retval None If failure in file operation +# +def _DataRestore(File): + Data =3D None + Fd =3D None + try: + Fd =3D open(File, 'rb') + Data =3D pickle.load(Fd) + except Exception as e: + EdkLogger.verbose("Failed to load [%s]\n\t%s" % (File, str(e))) + Data =3D None + finally: + if Fd is not None: + Fd.close() + return Data + ## Check environment PATH variable to make sure the specified tool is foun= d # # If the tool is found in the PATH, then True is returned @@ -2242,19 +2280,19 @@ class Build(): def DumpBuildData(self): CacheDirectory =3D os.path.dirname(GlobalData.gDatabasePath) Utils.CreateDirectory(CacheDirectory) - Utils.DataDump(Utils.gFileTimeStampCache, os.path.join(CacheDirect= ory, "gFileTimeStampCache")) - Utils.DataDump(Utils.gDependencyDatabase, os.path.join(CacheDirect= ory, "gDependencyDatabase")) + Utils._DataDump(Utils.gFileTimeStampCache, os.path.join(CacheDirec= tory, "gFileTimeStampCache")) + Utils._DataDump(Utils.gDependencyDatabase,=20 + os.path.join(CacheDirectory, "gDependencyDatabase")) =20 def RestoreBuildData(self): FilePath =3D os.path.join(os.path.dirname(GlobalData.gDatabasePath= ), "gFileTimeStampCache") if Utils.gFileTimeStampCache =3D=3D {} and os.path.isfile(FilePath= ): - Utils.gFileTimeStampCache =3D Utils.DataRestore(FilePath) + Utils.gFileTimeStampCache =3D Utils._DataRestore(FilePath) if Utils.gFileTimeStampCache is None: Utils.gFileTimeStampCache =3D {} =20 FilePath =3D os.path.join(os.path.dirname(GlobalData.gDatabasePath= ), "gDependencyDatabase") if Utils.gDependencyDatabase =3D=3D {} and os.path.isfile(FilePath= ): - Utils.gDependencyDatabase =3D Utils.DataRestore(FilePath) + Utils.gDependencyDatabase =3D Utils._DataRestore(FilePath) if Utils.gDependencyDatabase is None: Utils.gDependencyDatabase =3D {} =20 -- 2.16.2.windows.1