Fixed localization presubmit command line too long error

In presubmit.py, _CheckDevtoolsLocalization() gets all the paths of affected files and pass those in as arguments when running run_localization_check.py. When a lot of files need to be scanned, it casus the issue where character number exceed the limit of CreateProcess on Windows.

This PR changes the _CheckDevtoolsLocalization() to create a temp file that contains the affected file paths, and have the validation step read the affected file paths from the temp file.


Bug: 941561
Change-Id: I698e5064287eee8a8a3aca0682e3ab3521eb63d1
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2032086
Reviewed-by: Lorne Mitchell <[email protected]>
Commit-Queue: Christy Chen <[email protected]>
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index 6eb0241..05ea675 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -170,11 +170,14 @@
 
         if len(affected_front_end_files) == 0:
             return results
+
+        with input_api.CreateTemporaryFile() as file_list:
+            for affected_file in affected_front_end_files:
+                file_list.write(affected_file + '\n')
+        file_list.close()
+
         # Scan only added or modified files with specific extensions.
-        args = [
-            '--autofix',
-            '--files',
-        ] + affected_front_end_files
+        args = ['--autofix', '--file-list', file_list.name]
     process = input_api.subprocess.Popen(
         [input_api.python_executable, script_path] + args, stdout=input_api.subprocess.PIPE, stderr=input_api.subprocess.STDOUT)
     out, _ = process.communicate()
@@ -251,32 +254,32 @@
     return []
 
 def _CheckForTooLargeFiles(input_api, output_api):
-  """Avoid large files, especially binary files, in the repository since
+    """Avoid large files, especially binary files, in the repository since
   git doesn't scale well for those. They will be in everyone's repo
   clones forever, forever making Chromium slower to clone and work
   with."""
-  # Uploading files to cloud storage is not trivial so we don't want
-  # to set the limit too low, but the upper limit for "normal" large
-  # files seems to be 1-2 MB, with a handful around 5-8 MB, so
-  # anything over 20 MB is exceptional.
-  TOO_LARGE_FILE_SIZE_LIMIT = 20 * 1024 * 1024  # 10 MB
-  too_large_files = []
-  for f in input_api.AffectedFiles():
-    # Check both added and modified files (but not deleted files).
-    if f.Action() in ('A', 'M'):
-      size = input_api.os_path.getsize(f.AbsoluteLocalPath())
-      if size > TOO_LARGE_FILE_SIZE_LIMIT:
-        too_large_files.append("%s: %d bytes" % (f.LocalPath(), size))
-  if too_large_files:
-    message = (
-      'Do not commit large files to git since git scales badly for those.\n' +
-      'Instead put the large files in cloud storage and use DEPS to\n' +
-      'fetch them.\n' + '\n'.join(too_large_files)
-    )
-    return [output_api.PresubmitError(
-        'Too large files found in commit', long_text=message + '\n')]
-  else:
-    return []
+    # Uploading files to cloud storage is not trivial so we don't want
+    # to set the limit too low, but the upper limit for "normal" large
+    # files seems to be 1-2 MB, with a handful around 5-8 MB, so
+    # anything over 20 MB is exceptional.
+    TOO_LARGE_FILE_SIZE_LIMIT = 20 * 1024 * 1024  # 10 MB
+    too_large_files = []
+    for f in input_api.AffectedFiles():
+        # Check both added and modified files (but not deleted files).
+        if f.Action() in ('A', 'M'):
+            size = input_api.os_path.getsize(f.AbsoluteLocalPath())
+            if size > TOO_LARGE_FILE_SIZE_LIMIT:
+                too_large_files.append("%s: %d bytes" % (f.LocalPath(), size))
+    if too_large_files:
+        message = (
+          'Do not commit large files to git since git scales badly for those.\n' +
+          'Instead put the large files in cloud storage and use DEPS to\n' +
+          'fetch them.\n' + '\n'.join(too_large_files)
+        )
+        return [output_api.PresubmitError(
+            'Too large files found in commit', long_text=message + '\n')]
+    else:
+        return []
 
 
 def _CommonChecks(input_api, output_api):