From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web10.13721.1637685075541196235 for ; Tue, 23 Nov 2021 08:31:15 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.100, mailfrom: michael.d.kinney@intel.com) X-IronPort-AV: E=McAfee;i="6200,9189,10176"; a="298466167" X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="298466167" Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 08:31:14 -0800 X-IronPort-AV: E=Sophos;i="5.87,258,1631602800"; d="scan'208";a="571112443" Received: from mdkinney-mobl2.amr.corp.intel.com ([10.209.59.198]) by fmsmga004-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Nov 2021 08:31:14 -0800 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Sean Brogan , Bret Barkelew , Liming Gao , Michael Kubacki Subject: [Patch V2 2/3] .pytool/Plugin/EccCheck: Remove temp directory on exception Date: Tue, 23 Nov 2021 08:31:00 -0800 Message-Id: <20211123163101.786-3-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.32.0.windows.1 In-Reply-To: <20211123163101.786-1-michael.d.kinney@intel.com> References: <20211123163101.786-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Cc: Bret Barkelew Cc: Liming Gao Cc: Michael Kubacki Signed-off-by: Michael D Kinney --- .pytool/Plugin/EccCheck/EccCheck.py | 78 +++++++++++++++++------------ 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/.pytool/Plugin/EccCheck/EccCheck.py b/.pytool/Plugin/EccCheck/EccCheck.py index c4c2af1bf6e4..de766d984f7c 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]: -- 2.32.0.windows.1