From 028f4615ada9f4de58d5edbce5791e949ae220ca Mon Sep 17 00:00:00 2001 From: Bruce Dawson Date: Tue, 29 Mar 2022 21:18:27 +0000 Subject: [PATCH] Fix CheckDirMetadataFormat for Windows command limits CheckDirMetadataFormat executes dirmd on all applicable files. When running "git cl presubmit --all" that ends up being ~7,500 files and the command line that is generated is ~500,000 characters. Windows does not like that. This change breaks up the check into multiple invocations of dirmd in order to avoid these limits. This is important because running all presubmits is the only way to systematically find bugs, and avoid being surprised by them when submitting a change. Bug: 1309977 Change-Id: I24fbc340cdb975dbe7f6a2132e516d6f7e2f9165 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3554633 Reviewed-by: Robbie Iannucci Reviewed-by: Josip Sokcevic Commit-Queue: Bruce Dawson --- presubmit_canned_checks.py | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index f2ce0e3ca6..63bba80e2c 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -1101,14 +1101,32 @@ def CheckDirMetadataFormat(input_api, output_api, dirmd_bin=None): return [] name = 'Validate metadata in OWNERS and DIR_METADATA files' - kwargs = {} if dirmd_bin is None: dirmd_bin = 'dirmd.bat' if input_api.is_windows else 'dirmd' - cmd = [dirmd_bin, 'validate'] + sorted(affected_files) - return [input_api.Command( - name, cmd, kwargs, output_api.PresubmitError)] + # When running git cl presubmit --all this presubmit may be asked to check + # ~7,500 files, leading to a command line that is about 500,000 characters. + # This goes past the Windows 8191 character cmd.exe limit and causes cryptic + # failures. To avoid these we break the command up into smaller pieces. The + # non-Windows limit is chosen so that the code that splits up commands will + # get some exercise on other platforms. + # Depending on how long the command is on Windows the error may be: + # The command line is too long. + # Or it may be: + # OSError: Execution failed with error: [WinError 206] The filename or + # extension is too long. + # I suspect that the latter error comes from CreateProcess hitting its 32768 + # character limit. + files_per_command = 50 if input_api.is_windows else 1000 + affected_files = sorted(affected_files) + results = [] + for i in range(0, len(affected_files), files_per_command): + kwargs = {} + cmd = [dirmd_bin, 'validate'] + affected_files[i : i + files_per_command] + results.extend([input_api.Command( + name, cmd, kwargs, output_api.PresubmitError)]) + return results def CheckNoNewMetadataInOwners(input_api, output_api):