]> git.proxmox.com Git - mirror_edk2.git/commitdiff
.pytool/Plugin/EccCheck: Remove temp directory on exception
authorMichael D Kinney <michael.d.kinney@intel.com>
Tue, 23 Nov 2021 05:20:48 +0000 (21:20 -0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Mon, 29 Nov 2021 06:38:51 +0000 (06:38 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2986

Add try/except to RunBuildPlugin() to remove temporary
directory if a KeyboardInterrupt exception or an unexpected
exception is detected.

Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Michael Kubacki <michael.kubacki@microsoft.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Acked-by: Sean Brogan <sean.brogan@microsoft.com>
Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>
.pytool/Plugin/EccCheck/EccCheck.py

index c4c2af1bf6e46e27215c924fb1cdb6deebc1e2a0..de766d984f7c58f0ceb1b9b01aab4c2cd0e25d9f 100644 (file)
@@ -72,45 +72,61 @@ class EccCheck(ICiBuildPlugin):
 \r
         # Create temp directory\r
         temp_path = os.path.join(workspace_path, 'Build', '.pytool', 'Plugin', 'EccCheck')\r
-        # Delete temp directory\r
-        if os.path.exists(temp_path):\r
-            shutil.rmtree(temp_path)\r
-        # Copy package being scanned to temp_path\r
-        shutil.copytree (\r
-          os.path.join(workspace_path, packagename),\r
-          os.path.join(temp_path, packagename),\r
-          symlinks=True\r
-          )\r
-        # Copy exception.xml to temp_path\r
-        shutil.copyfile (\r
-          os.path.join(basetools_path, "Source", "Python", "Ecc", "exception.xml"),\r
-          os.path.join(temp_path, "exception.xml")\r
-          )\r
+        try:\r
+            # Delete temp directory\r
+            if os.path.exists(temp_path):\r
+                shutil.rmtree(temp_path)\r
+            # Copy package being scanned to temp_path\r
+            shutil.copytree (\r
+              os.path.join(workspace_path, packagename),\r
+              os.path.join(temp_path, packagename),\r
+              symlinks=True\r
+              )\r
+            # Copy exception.xml to temp_path\r
+            shutil.copyfile (\r
+              os.path.join(basetools_path, "Source", "Python", "Ecc", "exception.xml"),\r
+              os.path.join(temp_path, "exception.xml")\r
+              )\r
 \r
-        self.ApplyConfig(pkgconfig, temp_path, packagename)\r
-        modify_dir_list = self.GetModifyDir(packagename)\r
-        patch = self.GetDiff(packagename)\r
-        ecc_diff_range = self.GetDiffRange(patch, packagename, temp_path)\r
-        #\r
-        # Use temp_path as working directory when running ECC tool\r
-        #\r
-        self.GenerateEccReport(modify_dir_list, ecc_diff_range, temp_path, basetools_path)\r
-        ecc_log = os.path.join(temp_path, "Ecc.log")\r
-        if self.ECC_PASS:\r
+            self.ApplyConfig(pkgconfig, temp_path, packagename)\r
+            modify_dir_list = self.GetModifyDir(packagename)\r
+            patch = self.GetDiff(packagename)\r
+            ecc_diff_range = self.GetDiffRange(patch, packagename, temp_path)\r
+            #\r
+            # Use temp_path as working directory when running ECC tool\r
+            #\r
+            self.GenerateEccReport(modify_dir_list, ecc_diff_range, temp_path, basetools_path)\r
+            ecc_log = os.path.join(temp_path, "Ecc.log")\r
+            if self.ECC_PASS:\r
+                # Delete temp directory\r
+                if os.path.exists(temp_path):\r
+                    shutil.rmtree(temp_path)\r
+                tc.SetSuccess()\r
+                return 0\r
+            else:\r
+                with open(ecc_log, encoding='utf8') as output:\r
+                    ecc_output = output.readlines()\r
+                    for line in ecc_output:\r
+                        logging.error(line.strip())\r
+                # Delete temp directory\r
+                if os.path.exists(temp_path):\r
+                    shutil.rmtree(temp_path)\r
+                tc.SetFailed("EccCheck failed for {0}".format(packagename), "CHECK FAILED")\r
+                return 1\r
+        except KeyboardInterrupt:\r
+            # If EccCheck is interrupted by keybard interrupt, then return failure\r
             # Delete temp directory\r
             if os.path.exists(temp_path):\r
                 shutil.rmtree(temp_path)\r
-            tc.SetSuccess()\r
-            return 0\r
+            tc.SetFailed("EccCheck interrupted for {0}".format(packagename), "CHECK FAILED")\r
+            return 1\r
         else:\r
-            with open(ecc_log, encoding='utf8') as output:\r
-                ecc_output = output.readlines()\r
-                for line in ecc_output:\r
-                    logging.error(line.strip())\r
+            # If EccCheck fails for any other exception type, raise the exception\r
             # Delete temp directory\r
             if os.path.exists(temp_path):\r
                 shutil.rmtree(temp_path)\r
-            tc.SetFailed("EccCheck failed for {0}".format(packagename), "CHECK FAILED")\r
+            tc.SetFailed("EccCheck exception for {0}".format(packagename), "CHECK FAILED")\r
+            raise\r
             return 1\r
 \r
     def GetDiff(self, pkg: str) -> List[str]:\r