From: "Michael D Kinney" <michael.d.kinney@intel.com>
To: devel@edk2.groups.io
Cc: Sean Brogan <sean.brogan@microsoft.com>,
Bret Barkelew <Bret.Barkelew@microsoft.com>,
Liming Gao <gaoliming@byosoft.com.cn>,
Michael Kubacki <michael.kubacki@microsoft.com>
Subject: [Patch 2/3] .pytool/Plugin/EccCheck: Remove temp directory on exception
Date: Mon, 22 Nov 2021 21:44:54 -0800 [thread overview]
Message-ID: <20211123054455.600-3-michael.d.kinney@intel.com> (raw)
In-Reply-To: <20211123054455.600-1-michael.d.kinney@intel.com>
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>
---
.pytool/Plugin/EccCheck/EccCheck.py | 84 +++++++++++++++++------------
1 file changed, 50 insertions(+), 34 deletions(-)
diff --git a/.pytool/Plugin/EccCheck/EccCheck.py b/.pytool/Plugin/EccCheck/EccCheck.py
index 82a3f14d6d5c..25583f15bf54 100644
--- a/.pytool/Plugin/EccCheck/EccCheck.py
+++ b/.pytool/Plugin/EccCheck/EccCheck.py
@@ -72,48 +72,64 @@ class EccCheck(ICiBuildPlugin):
# Create temp directory
temp_path = os.path.join(workspace_path, 'Build', 'ecctemp')
- # 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)
- #
- # Set workingdir to Build output directory because Ecc generates temp files
- # Can not set workingdir to temp_path because that can be on a different
- # drive letter for some CI platforms and RunCmd() does not work correctly
- # if working dir is on a different drive letter.
- #
- self.GenerateEccReport(modify_dir_list, ecc_diff_range, temp_path, basetools_path, os.path.join (workspace_path, 'Build'))
- 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)
+ #
+ # Set workingdir to Build output directory because Ecc generates temp files
+ # Can not set workingdir to temp_path because that can be on a different
+ # drive letter for some CI platforms and RunCmd() does not work correctly
+ # if working dir is on a different drive letter.
+ #
+ self.GenerateEccReport(modify_dir_list, ecc_diff_range, temp_path, basetools_path, os.path.join (workspace_path, 'Build'))
+ 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
next prev parent reply other threads:[~2021-11-23 5:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-23 5:44 [Patch 0/3] .pytool/Plugin/EccCheck: Remove git reset and optimize Michael D Kinney
2021-11-23 5:44 ` [Patch 1/3] .pytool/Plugin/EccCheck: Remove RevertCode() Michael D Kinney
2021-11-23 5:44 ` Michael D Kinney [this message]
2021-11-23 5:44 ` [Patch 3/3] .pytool/Plugin/EccCheck: Add performance optimizations Michael D Kinney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211123054455.600-3-michael.d.kinney@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox