From 8885550dbc1972311cdf8f08b6fc8c0778fc1d33 Mon Sep 17 00:00:00 2001 From: Ben Wagner Date: Thu, 12 Oct 2017 17:55:19 -0400 Subject: Make CR and trailing whitespace errors. The canned CR and trailing whitespace presubmit checks only emit warnings, so no one pays any attention to them and they don't fail the build. All trailing whitespace was removed recently, and it has already returned. This makes these checks actual errors so they will fail the presubmit check on the bots, so that they will actually be seen. Change-Id: I5d774ae45a68b8eb881548d0158c37a8f5fe052e Reviewed-on: https://skia-review.googlesource.com/59164 Reviewed-by: Mike Klein Commit-Queue: Mike Klein --- PRESUBMIT.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/PRESUBMIT.py b/PRESUBMIT.py index 271cd13ada..dec667d988 100644 --- a/PRESUBMIT.py +++ b/PRESUBMIT.py @@ -234,6 +234,18 @@ def _CheckGNFormatted(input_api, output_api): return results +class _WarningsAsErrors(): + def __init__(self, output_api): + self.output_api = output_api + self.old_warning = None + def __enter__(self): + self.old_warning = self.output_api.PresubmitPromptWarning + self.output_api.PresubmitPromptWarning = self.output_api.PresubmitError + return self.output_api + def __exit__(self, ex_type, ex_value, ex_traceback): + self.output_api.PresubmitPromptWarning = self.old_warning + + def _CommonChecks(input_api, output_api): """Presubmit checks common to upload and commit.""" results = [] @@ -246,15 +258,13 @@ def _CommonChecks(input_api, output_api): x.LocalPath().endswith('.c') or x.LocalPath().endswith('.cc') or x.LocalPath().endswith('.cpp')) - results.extend( - _CheckChangeHasEol( - input_api, output_api, source_file_filter=sources)) - results.extend( - input_api.canned_checks.CheckChangeHasNoCR( - input_api, output_api, source_file_filter=sources)) - results.extend( - input_api.canned_checks.CheckChangeHasNoStrayWhitespace( - input_api, output_api, source_file_filter=sources)) + results.extend(_CheckChangeHasEol( + input_api, output_api, source_file_filter=sources)) + with _WarningsAsErrors(output_api): + results.extend(input_api.canned_checks.CheckChangeHasNoCR( + input_api, output_api, source_file_filter=sources)) + results.extend(input_api.canned_checks.CheckChangeHasNoStrayWhitespace( + input_api, output_api, source_file_filter=sources)) results.extend(_PythonChecks(input_api, output_api)) results.extend(_JsonChecks(input_api, output_api)) results.extend(_IfDefChecks(input_api, output_api)) -- cgit v1.2.3