]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Hash false success with back to back builds
authorRodriguez, Christian <christian.rodriguez@intel.com>
Wed, 10 Apr 2019 15:27:05 +0000 (23:27 +0800)
committerFeng, Bob C <bob.c.feng@intel.com>
Tue, 16 Apr 2019 05:14:15 +0000 (13:14 +0800)
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=1692

Add error handling to the --hash feature so that hash files
are invalidated when a build error occurs.

Signed-off-by: Christian Rodriguez <christian.rodriguez@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
BaseTools/Source/Python/Common/GlobalData.py
BaseTools/Source/Python/build/build.py

index 1853f1d2f6505bb5ff2ffefb2f98770d2b2f10b9..79f23c892d486e9ca1b2d208692cdcb8148819f8 100644 (file)
@@ -108,3 +108,7 @@ gPackageHash = {}
 gModuleHash = {}\r
 gEnableGenfdsMultiThread = False\r
 gSikpAutoGenCache = set()\r
+\r
+# Dictionary for tracking Module build status as success or failure\r
+# False -> Fail : True -> Success\r
+gModuleBuildTracking = dict()\r
index af8bba47b1407ba42cd0f921cdfc29cc082a5e93..71478b7268e364640ad43d3d8972c8540433ca7c 100644 (file)
@@ -620,6 +620,8 @@ class BuildTask:
             BuildTask._ErrorFlag.set()\r
             BuildTask._ErrorMessage = "%s broken\n    %s [%s]" % \\r
                                       (threading.currentThread().getName(), Command, WorkingDir)\r
+        if self.BuildItem.BuildObject in GlobalData.gModuleBuildTracking and not BuildTask._ErrorFlag.isSet():\r
+            GlobalData.gModuleBuildTracking[self.BuildItem.BuildObject] = True\r
         # indicate there's a thread is available for another build task\r
         BuildTask._RunningQueueLock.acquire()\r
         BuildTask._RunningQueue.pop(self.BuildItem)\r
@@ -1138,6 +1140,37 @@ class Build():
             if Process.returncode != 0 :\r
                 EdkLogger.error("Postbuild", POSTBUILD_ERROR, 'Postbuild process is not success!')\r
             EdkLogger.info("\n- Postbuild Done -\n")\r
+\r
+    ## Error handling for hash feature\r
+    #\r
+    # On BuildTask error, iterate through the Module Build tracking\r
+    # dictionary to determine wheather a module failed to build. Invalidate\r
+    # the hash associated with that module by removing it from storage.\r
+    #\r
+    #\r
+    def invalidateHash(self):\r
+        # GlobalData.gModuleBuildTracking contains only modules that cannot be skipped by hash\r
+        for moduleAutoGenObj in GlobalData.gModuleBuildTracking.keys():\r
+            # False == FAIL : True == Success\r
+            # Skip invalidating for Successful module builds\r
+            if GlobalData.gModuleBuildTracking[moduleAutoGenObj] == True:\r
+                continue\r
+\r
+            # The module failed to build or failed to start building, from this point on\r
+\r
+            # Remove .hash from build\r
+            if GlobalData.gUseHashCache:\r
+                ModuleHashFile = path.join(moduleAutoGenObj.BuildDir, moduleAutoGenObj.Name + ".hash")\r
+                if os.path.exists(ModuleHashFile):\r
+                    os.remove(ModuleHashFile)\r
+\r
+            # Remove .hash file from cache\r
+            if GlobalData.gBinCacheSource:\r
+                FileDir = path.join(GlobalData.gBinCacheSource, moduleAutoGenObj.Arch, moduleAutoGenObj.SourceDir, moduleAutoGenObj.MetaFile.BaseName)\r
+                HashFile = path.join(FileDir, moduleAutoGenObj.Name + '.hash')\r
+                if os.path.exists(HashFile):\r
+                    os.remove(HashFile)\r
+\r
     ## Build a module or platform\r
     #\r
     # Create autogen code and makefile for a module or platform, and the launch\r
@@ -1795,6 +1828,9 @@ class Build():
                                 if self.Target == "genmake":\r
                                     return True\r
                             self.BuildModules.append(Ma)\r
+                            # Initialize all modules in tracking to False (FAIL)\r
+                            if Ma not in GlobalData.gModuleBuildTracking:\r
+                                GlobalData.gModuleBuildTracking[Ma] = False\r
                     self.AutoGenTime += int(round((time.time() - AutoGenStart)))\r
                     MakeStart = time.time()\r
                     for Ma in self.BuildModules:\r
@@ -1805,6 +1841,7 @@ class Build():
                             # we need a full version of makefile for platform\r
                             ExitFlag.set()\r
                             BuildTask.WaitForComplete()\r
+                            self.invalidateHash()\r
                             Pa.CreateMakeFile(False)\r
                             EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)\r
                         # Start task scheduler\r
@@ -1814,6 +1851,7 @@ class Build():
                     # in case there's an interruption. we need a full version of makefile for platform\r
                     Pa.CreateMakeFile(False)\r
                     if BuildTask.HasError():\r
+                        self.invalidateHash()\r
                         EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)\r
                     self.MakeTime += int(round((time.time() - MakeStart)))\r
 \r
@@ -1823,6 +1861,7 @@ class Build():
                 self.CreateAsBuiltInf()\r
                 self.MakeTime += int(round((time.time() - MakeContiue)))\r
                 if BuildTask.HasError():\r
+                    self.invalidateHash()\r
                     EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)\r
 \r
                 self.BuildReport.AddPlatformReport(Wa, MaList)\r
@@ -1973,6 +2012,9 @@ class Build():
                             if self.Target == "genmake":\r
                                 continue\r
                         self.BuildModules.append(Ma)\r
+                        # Initialize all modules in tracking to False (FAIL)\r
+                        if Ma not in GlobalData.gModuleBuildTracking:\r
+                            GlobalData.gModuleBuildTracking[Ma] = False\r
                     self.Progress.Stop("done!")\r
                     self.AutoGenTime += int(round((time.time() - AutoGenStart)))\r
                     MakeStart = time.time()\r
@@ -1985,6 +2027,7 @@ class Build():
                             # we need a full version of makefile for platform\r
                             ExitFlag.set()\r
                             BuildTask.WaitForComplete()\r
+                            self.invalidateHash()\r
                             Pa.CreateMakeFile(False)\r
                             EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)\r
                         # Start task scheduler\r
@@ -1994,6 +2037,7 @@ class Build():
                     # in case there's an interruption. we need a full version of makefile for platform\r
                     Pa.CreateMakeFile(False)\r
                     if BuildTask.HasError():\r
+                        self.invalidateHash()\r
                         EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)\r
                     self.MakeTime += int(round((time.time() - MakeStart)))\r
 \r
@@ -2013,6 +2057,7 @@ class Build():
                 # has been signaled.\r
                 #\r
                 if BuildTask.HasError():\r
+                    self.invalidateHash()\r
                     EdkLogger.error("build", BUILD_ERROR, "Failed to build module", ExtraData=GlobalData.gBuildingModule)\r
 \r
                 # Create MAP file when Load Fix Address is enabled.\r