Commit 6e70e86d authored by Bruce Dawson's avatar Bruce Dawson Committed by LUCI CQ

Fix presubmit_support.py to handle CRLF in PRESUBMIT.py

PRESUBMIT.py files should not have CRLF line endings, but if a git repo
is misconfigured this may happen and it is important for the presubmits
to run properly so that they can report on this issue.

In particular, the regex which detects USE_PYTHON3 = True did not work
with CRLF line endings.

It was supposed to handle these, and there is even a comment saying:

  # Accept CRLF presubmit script.

However the line after that uses 'rU' as the file open mode in order to
try to get universal newlines, but FileRead ignores the file mode. So,
the replace method is now used instead.

Bug: angleproject:7475, angleproject:4905
Change-Id: I38321176feca089a5796b24756b371709d852243
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3739269Reviewed-by: 's avatarEddie Hatfield <eddiehatfield@google.com>
Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
parent 5a7c824f
......@@ -1483,7 +1483,7 @@ def DoPostUploadExecuter(change, gerrit_obj, verbose, use_python3=False):
if verbose:
sys.stdout.write('Running %s\n' % filename)
# Accept CRLF presubmit script.
presubmit_script = gclient_utils.FileRead(filename, 'rU')
presubmit_script = gclient_utils.FileRead(filename).replace('\r\n', '\n')
if _ShouldRunPresubmit(presubmit_script, use_python3):
results.extend(executer.ExecPresubmitScript(
presubmit_script, filename, gerrit_obj, change))
......@@ -1755,7 +1755,7 @@ def DoPresubmitChecks(change,
if verbose:
sys.stdout.write('Running %s\n' % filename)
# Accept CRLF presubmit script.
presubmit_script = gclient_utils.FileRead(filename, 'rU')
presubmit_script = gclient_utils.FileRead(filename).replace('\r\n', '\n')
if _ShouldRunPresubmit(presubmit_script, use_python3):
results += executer.ExecPresubmitScript(presubmit_script, filename)
else:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment