From c4fc2eaa028115dea095d3bfce89b4be50bed56a Mon Sep 17 00:00:00 2001 From: r-shah22 <126166341+r-shah22@users.noreply.github.com> Date: Tue, 18 Apr 2023 11:29:32 +0100 Subject: [PATCH] exit cpplint only after completing all files --- hooks/cpplint.py | 9 +++++++-- hooks/utils.py | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/hooks/cpplint.py b/hooks/cpplint.py index 08de009..496e80d 100644 --- a/hooks/cpplint.py +++ b/hooks/cpplint.py @@ -19,9 +19,14 @@ def __init__(self, args: List[str]): def run(self): """Run cpplint""" + error_occurred = False for filename in self.files: - self.run_command(self.args + [filename]) # cpplint is unique in requiring args before filename - self.exit_on_error() + self.run_command_cpplint(self.args + [filename]) # cpplint is unique in requiring args before filename + if self.returncode != 0: + error_occurred = True + + if error_occurred: + sys.exit(1) def main(argv: List[str] = sys.argv): diff --git a/hooks/utils.py b/hooks/utils.py index 30cc297..d6e77b3 100755 --- a/hooks/utils.py +++ b/hooks/utils.py @@ -143,6 +143,15 @@ def run_command(self, args: List[str]): self.stderr += sp_child.stderr self.returncode = sp_child.returncode + def run_command_cpplint(self, args: List[str]): + """Run the command and check for errors. Args includes options and filepaths""" + args = [self.command, *args] + sp_child = sp.run(args, stdout=sp.PIPE, stderr=sp.PIPE) + self.returncode = sp_child.returncode + + if self.returncode != 0: + sys.stderr.buffer.write(sp_child.stderr + sp_child.stdout) + def exit_on_error(self): if self.returncode != 0: sys.stderr.buffer.write(self.stdout + self.stderr)