]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/build/build.py
BaseTools: Library hashing fix and optimization for --hash feature
[mirror_edk2.git] / BaseTools / Source / Python / build / build.py
index af8bba47b1407ba42cd0f921cdfc29cc082a5e93..027061191c5eee3aa06867d83008f58a3b00ead8 100644 (file)
@@ -593,7 +593,7 @@ class BuildTask:
     #\r
     def AddDependency(self, Dependency):\r
         for Dep in Dependency:\r
-            if not Dep.BuildObject.IsBinaryModule:\r
+            if not Dep.BuildObject.IsBinaryModule and not Dep.BuildObject.CanSkipbyHash():\r
                 self.DependencyList.append(BuildTask.New(Dep))    # BuildTask list\r
 \r
     ## The thread wrapper of LaunchCommand function\r
@@ -605,6 +605,11 @@ class BuildTask:
         try:\r
             self.BuildItem.BuildObject.BuildTime = LaunchCommand(Command, WorkingDir)\r
             self.CompleteFlag = True\r
+\r
+            # Run hash operation post dependency, to account for libs\r
+            if GlobalData.gUseHashCache and self.BuildItem.BuildObject.IsLibrary:\r
+                HashFile = path.join(self.BuildItem.BuildObject.BuildDir, self.BuildItem.BuildObject.Name + ".hash")\r
+                SaveFileOnChange(HashFile, self.BuildItem.BuildObject.GenModuleHash(), True)\r
         except:\r
             #\r
             # TRICK: hide the output of threads left running, so that the user can\r
@@ -620,6 +625,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 +1145,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.gBinCacheDest:\r
+                FileDir = path.join(GlobalData.gBinCacheDest, 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 +1833,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 +1846,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 +1856,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 +1866,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 +2017,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 +2032,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 +2042,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 +2062,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