]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/build/build: refactor and move functions
authorCarsey, Jaben <jaben.carsey@intel.com>
Thu, 10 Jan 2019 18:39:45 +0000 (02:39 +0800)
committerFeng, Bob C <bob.c.feng@intel.com>
Mon, 21 Jan 2019 10:03:30 +0000 (18:03 +0800)
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 <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Jaben Carsey <jaben.carsey@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
BaseTools/Source/Python/Common/Misc.py
BaseTools/Source/Python/build/build.py

index feb2c7e394e1aaf7d717da1116b31340e86b4980..32de5d9100c8035b8a1f4cae91319babb9462f0f 100644 (file)
@@ -487,43 +487,6 @@ def SaveFileOnChange(File, Content, IsBinaryFile=True):
 \r
     return True\r
 \r
-## Make a Python object persistent on file system\r
-#\r
-#   @param      Data    The object to be stored in file\r
-#   @param      File    The path of file to store the object\r
-#\r
-def DataDump(Data, File):\r
-    Fd = None\r
-    try:\r
-        Fd = open(File, 'wb')\r
-        pickle.dump(Data, Fd, pickle.HIGHEST_PROTOCOL)\r
-    except:\r
-        EdkLogger.error("", FILE_OPEN_FAILURE, ExtraData=File, RaiseError=False)\r
-    finally:\r
-        if Fd is not None:\r
-            Fd.close()\r
-\r
-## Restore a Python object from a file\r
-#\r
-#   @param      File    The path of file stored the object\r
-#\r
-#   @retval     object  A python object\r
-#   @retval     None    If failure in file operation\r
-#\r
-def DataRestore(File):\r
-    Data = None\r
-    Fd = None\r
-    try:\r
-        Fd = open(File, 'rb')\r
-        Data = pickle.load(Fd)\r
-    except Exception as e:\r
-        EdkLogger.verbose("Failed to load [%s]\n\t%s" % (File, str(e)))\r
-        Data = None\r
-    finally:\r
-        if Fd is not None:\r
-            Fd.close()\r
-    return Data\r
-\r
 ## Retrieve and cache the real path name in file system\r
 #\r
 #   @param      Root    The root directory of path relative to\r
index f41b1754ec31232f34d67f7564efb2a38c47140b..44ad86b780da5326ca965968340855bd74da90e0 100644 (file)
@@ -32,6 +32,7 @@ import multiprocessing
 \r
 from struct import *\r
 from threading import *\r
+import threading\r
 from optparse import OptionParser\r
 from subprocess import *\r
 from Common import Misc as Utils\r
@@ -71,6 +72,43 @@ gToolsDefinition = "tools_def.txt"
 TemporaryTablePattern = re.compile(r'^_\d+_\d+_[a-fA-F0-9]+$')\r
 TmpTableDict = {}\r
 \r
+## Make a Python object persistent on file system\r
+#\r
+#   @param      Data    The object to be stored in file\r
+#   @param      File    The path of file to store the object\r
+#\r
+def _DataDump(Data, File):\r
+    Fd = None\r
+    try:\r
+        Fd = open(File, 'wb')\r
+        pickle.dump(Data, Fd, pickle.HIGHEST_PROTOCOL)\r
+    except:\r
+        EdkLogger.error("", FILE_OPEN_FAILURE, ExtraData=File, RaiseError=False)\r
+    finally:\r
+        if Fd is not None:\r
+            Fd.close()\r
+\r
+## Restore a Python object from a file\r
+#\r
+#   @param      File    The path of file stored the object\r
+#\r
+#   @retval     object  A python object\r
+#   @retval     None    If failure in file operation\r
+#\r
+def _DataRestore(File):\r
+    Data = None\r
+    Fd = None\r
+    try:\r
+        Fd = open(File, 'rb')\r
+        Data = pickle.load(Fd)\r
+    except Exception as e:\r
+        EdkLogger.verbose("Failed to load [%s]\n\t%s" % (File, str(e)))\r
+        Data = None\r
+    finally:\r
+        if Fd is not None:\r
+            Fd.close()\r
+    return Data\r
+\r
 ## Check environment PATH variable to make sure the specified tool is found\r
 #\r
 #   If the tool is found in the PATH, then True is returned\r
@@ -2163,19 +2201,19 @@ class Build():
     def DumpBuildData(self):\r
         CacheDirectory = os.path.dirname(GlobalData.gDatabasePath)\r
         Utils.CreateDirectory(CacheDirectory)\r
-        Utils.DataDump(Utils.gFileTimeStampCache, os.path.join(CacheDirectory, "gFileTimeStampCache"))\r
-        Utils.DataDump(Utils.gDependencyDatabase, os.path.join(CacheDirectory, "gDependencyDatabase"))\r
+        Utils._DataDump(Utils.gFileTimeStampCache, os.path.join(CacheDirectory, "gFileTimeStampCache"))\r
+        Utils._DataDump(Utils.gDependencyDatabase, os.path.join(CacheDirectory, "gDependencyDatabase"))\r
 \r
     def RestoreBuildData(self):\r
         FilePath = os.path.join(os.path.dirname(GlobalData.gDatabasePath), "gFileTimeStampCache")\r
         if Utils.gFileTimeStampCache == {} and os.path.isfile(FilePath):\r
-            Utils.gFileTimeStampCache = Utils.DataRestore(FilePath)\r
+            Utils.gFileTimeStampCache = Utils._DataRestore(FilePath)\r
             if Utils.gFileTimeStampCache is None:\r
                 Utils.gFileTimeStampCache = {}\r
 \r
         FilePath = os.path.join(os.path.dirname(GlobalData.gDatabasePath), "gDependencyDatabase")\r
         if Utils.gDependencyDatabase == {} and os.path.isfile(FilePath):\r
-            Utils.gDependencyDatabase = Utils.DataRestore(FilePath)\r
+            Utils.gDependencyDatabase = Utils._DataRestore(FilePath)\r
             if Utils.gDependencyDatabase is None:\r
                 Utils.gDependencyDatabase = {}\r
 \r