summaryrefslogtreecommitdiff
path: root/.pytool/Plugin/EccCheck
diff options
context:
space:
mode:
authorMichael D Kinney <michael.d.kinney@intel.com>2021-11-22 21:20:48 -0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2021-11-29 06:38:51 +0000
commit854462bd347974da73d36519c8187554b7719680 (patch)
treee42975b1c35905903898a3049d8753adc95290a9 /.pytool/Plugin/EccCheck
parent69877614fdeef64b8d1d6f21d5a209dce22983b7 (diff)
downloadedk2-854462bd347974da73d36519c8187554b7719680.zip
edk2-854462bd347974da73d36519c8187554b7719680.tar.gz
edk2-854462bd347974da73d36519c8187554b7719680.tar.bz2
.pytool/Plugin/EccCheck: Remove temp directory on exception
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>
Diffstat (limited to '.pytool/Plugin/EccCheck')
-rw-r--r--.pytool/Plugin/EccCheck/EccCheck.py78
1 files changed, 47 insertions, 31 deletions
diff --git a/.pytool/Plugin/EccCheck/EccCheck.py b/.pytool/Plugin/EccCheck/EccCheck.py
index c4c2af1..de766d9 100644
--- a/.pytool/Plugin/EccCheck/EccCheck.py
+++ b/.pytool/Plugin/EccCheck/EccCheck.py
@@ -72,45 +72,61 @@ class EccCheck(ICiBuildPlugin):
# Create temp directory
temp_path = os.path.join(workspace_path, 'Build', '.pytool', 'Plugin', 'EccCheck')
- # Delete temp directory
- if os.path.exists(temp_path):
- shutil.rmtree(temp_path)
- # Copy package being scanned to temp_path
- shutil.copytree (
- os.path.join(workspace_path, packagename),
- os.path.join(temp_path, packagename),
- symlinks=True
- )
- # Copy exception.xml to temp_path
- shutil.copyfile (
- os.path.join(basetools_path, "Source", "Python", "Ecc", "exception.xml"),
- os.path.join(temp_path, "exception.xml")
- )
+ try:
+ # Delete temp directory
+ if os.path.exists(temp_path):
+ shutil.rmtree(temp_path)
+ # Copy package being scanned to temp_path
+ shutil.copytree (
+ os.path.join(workspace_path, packagename),
+ os.path.join(temp_path, packagename),
+ symlinks=True
+ )
+ # Copy exception.xml to temp_path
+ shutil.copyfile (
+ os.path.join(basetools_path, "Source", "Python", "Ecc", "exception.xml"),
+ os.path.join(temp_path, "exception.xml")
+ )
- self.ApplyConfig(pkgconfig, temp_path, packagename)
- modify_dir_list = self.GetModifyDir(packagename)
- patch = self.GetDiff(packagename)
- ecc_diff_range = self.GetDiffRange(patch, packagename, temp_path)
- #
- # Use temp_path as working directory when running ECC tool
- #
- self.GenerateEccReport(modify_dir_list, ecc_diff_range, temp_path, basetools_path)
- ecc_log = os.path.join(temp_path, "Ecc.log")
- if self.ECC_PASS:
+ self.ApplyConfig(pkgconfig, temp_path, packagename)
+ modify_dir_list = self.GetModifyDir(packagename)
+ patch = self.GetDiff(packagename)
+ ecc_diff_range = self.GetDiffRange(patch, packagename, temp_path)
+ #
+ # Use temp_path as working directory when running ECC tool
+ #
+ self.GenerateEccReport(modify_dir_list, ecc_diff_range, temp_path, basetools_path)
+ ecc_log = os.path.join(temp_path, "Ecc.log")
+ if self.ECC_PASS:
+ # Delete temp directory
+ if os.path.exists(temp_path):
+ shutil.rmtree(temp_path)
+ tc.SetSuccess()
+ return 0
+ else:
+ with open(ecc_log, encoding='utf8') as output:
+ ecc_output = output.readlines()
+ for line in ecc_output:
+ logging.error(line.strip())
+ # Delete temp directory
+ if os.path.exists(temp_path):
+ shutil.rmtree(temp_path)
+ tc.SetFailed("EccCheck failed for {0}".format(packagename), "CHECK FAILED")
+ return 1
+ except KeyboardInterrupt:
+ # If EccCheck is interrupted by keybard interrupt, then return failure
# Delete temp directory
if os.path.exists(temp_path):
shutil.rmtree(temp_path)
- tc.SetSuccess()
- return 0
+ tc.SetFailed("EccCheck interrupted for {0}".format(packagename), "CHECK FAILED")
+ return 1
else:
- with open(ecc_log, encoding='utf8') as output:
- ecc_output = output.readlines()
- for line in ecc_output:
- logging.error(line.strip())
+ # If EccCheck fails for any other exception type, raise the exception
# Delete temp directory
if os.path.exists(temp_path):
shutil.rmtree(temp_path)
- tc.SetFailed("EccCheck failed for {0}".format(packagename), "CHECK FAILED")
+ tc.SetFailed("EccCheck exception for {0}".format(packagename), "CHECK FAILED")
+ raise
return 1
def GetDiff(self, pkg: str) -> List[str]: