]> git.proxmox.com Git - mirror_edk2.git/blobdiff - .pytool/Plugin/EccCheck/EccCheck.py
.pytool/Plugin/EccCheck: Remove temp directory on exception
[mirror_edk2.git] / .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