From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.43; helo=mga05.intel.com; envelope-from=jaben.carsey@intel.com; receiver=edk2-devel@lists.01.org Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) (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 EEDAB2194D3B8 for ; Thu, 10 Jan 2019 10:39:53 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Jan 2019 10:39:51 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,462,1539673200"; d="scan'208";a="117134381" Received: from jcarsey-desk1.amr.corp.intel.com ([10.7.159.149]) by orsmga003.jf.intel.com with ESMTP; 10 Jan 2019 10:39:51 -0800 From: Jaben Carsey To: edk2-devel@lists.01.org Cc: Bob Feng , Liming Gao Date: Thu, 10 Jan 2019 10:39:45 -0800 Message-Id: <38e1ccf7c2d5fe144f9fb63ddba77cc0c491fb67.1547145461.git.jaben.carsey@intel.com> X-Mailer: git-send-email 2.16.2.windows.1 In-Reply-To: References: In-Reply-To: References: Subject: [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, 10 Jan 2019 18:39:54 -0000 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/Source/Python/build/build.py | 46 ++++++++++++++++++-- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/BaseTools/Source/Python/Common/Misc.py b/BaseTools/Source/Python/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=True): return True -## 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 = None - try: - Fd = open(File, 'wb') - pickle.dump(Data, Fd, pickle.HIGHEST_PROTOCOL) - except: - EdkLogger.error("", FILE_OPEN_FAILURE, ExtraData=File, RaiseError=False) - 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 = None - Fd = None - try: - Fd = open(File, 'rb') - Data = pickle.load(Fd) - except Exception as e: - EdkLogger.verbose("Failed to load [%s]\n\t%s" % (File, str(e))) - Data = 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/Python/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 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 = "tools_def.txt" TemporaryTablePattern = re.compile(r'^_\d+_\d+_[a-fA-F0-9]+$') TmpTableDict = {} +## 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 = None + try: + Fd = open(File, 'wb') + pickle.dump(Data, Fd, pickle.HIGHEST_PROTOCOL) + except: + EdkLogger.error("", FILE_OPEN_FAILURE, ExtraData=File, RaiseError=False) + 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 = None + Fd = None + try: + Fd = open(File, 'rb') + Data = pickle.load(Fd) + except Exception as e: + EdkLogger.verbose("Failed to load [%s]\n\t%s" % (File, str(e))) + Data = None + finally: + if Fd is not None: + Fd.close() + return Data + ## Check environment PATH variable to make sure the specified tool is found # # If the tool is found in the PATH, then True is returned @@ -2242,19 +2280,19 @@ class Build(): def DumpBuildData(self): CacheDirectory = os.path.dirname(GlobalData.gDatabasePath) Utils.CreateDirectory(CacheDirectory) - Utils.DataDump(Utils.gFileTimeStampCache, os.path.join(CacheDirectory, "gFileTimeStampCache")) - Utils.DataDump(Utils.gDependencyDatabase, os.path.join(CacheDirectory, "gDependencyDatabase")) + Utils._DataDump(Utils.gFileTimeStampCache, os.path.join(CacheDirectory, "gFileTimeStampCache")) + Utils._DataDump(Utils.gDependencyDatabase, os.path.join(CacheDirectory, "gDependencyDatabase")) def RestoreBuildData(self): FilePath = os.path.join(os.path.dirname(GlobalData.gDatabasePath), "gFileTimeStampCache") if Utils.gFileTimeStampCache == {} and os.path.isfile(FilePath): - Utils.gFileTimeStampCache = Utils.DataRestore(FilePath) + Utils.gFileTimeStampCache = Utils._DataRestore(FilePath) if Utils.gFileTimeStampCache is None: Utils.gFileTimeStampCache = {} FilePath = os.path.join(os.path.dirname(GlobalData.gDatabasePath), "gDependencyDatabase") if Utils.gDependencyDatabase == {} and os.path.isfile(FilePath): - Utils.gDependencyDatabase = Utils.DataRestore(FilePath) + Utils.gDependencyDatabase = Utils._DataRestore(FilePath) if Utils.gDependencyDatabase is None: Utils.gDependencyDatabase = {} -- 2.16.2.windows.1