Generate InspectorBackendCommands.js on presubmit

This checks in the InspectorBackendCommands in the source tree file
and ensures that it is kept in sync whenever the third_party
location has been updated.

In the process, I discovered multiple misconfigurations in the formatting
presubmit check. First of all, it was never running, because the
.eslintignore had an empty line. Second of all, it was running twice,
which is unnecessary since we now check for changed files at the end
of the presubmit. Lastly, it was only formatting JS files, while it
should check all files.

I have also updated the _CheckGeneratedFiles check to only run if it
is actually necessary. If there are no changes made to any affected of
the files, it will skip the step. This should thus reduce the presubmit
time and we will only pay the cost if we actually update any of the
files.

Lastly, it will now properly format and lint the generated files. This
makes reading the code a lot easier and makes it easier to digest the
diff when a protocol update goes through. I have verified that, in a
full build, the files are still minified. Thus, this has no impact on
the loading performance.

DISABLE_THIRD_PARTY_CHECK=Updating protocol generation

Fixed: 1056614
Change-Id: If49b0e749978ea1a7838992ec13507ee761ad76c
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2087765
Reviewed-by: Paul Lewis <[email protected]>
Commit-Queue: Tim van der Lippe <[email protected]>
diff --git a/PRESUBMIT.py b/PRESUBMIT.py
index d0ad1f2..fc41e61 100644
--- a/PRESUBMIT.py
+++ b/PRESUBMIT.py
@@ -138,22 +138,12 @@
     if len(formattable_files) == 0:
         return results
 
-    check_formatting_process = popen(['git', 'cl', 'format', '--js', '--dry-run'] + formattable_files)
-    check_formatting_process.communicate()
-    if check_formatting_process.returncode == 0:
-        return results
-
     format_args = ['git', 'cl', 'format', '--js'] + formattable_files
     format_process = popen(format_args)
     format_out, _ = format_process.communicate()
     if format_process.returncode != 0:
         results.append(output_api.PresubmitError(format_out))
-        return results
 
-    results.append(output_api.PresubmitError('ERROR: Found formatting violations.\n'
-                                  'Ran clang-format on diff\n'
-                                  'Use git status to check the formatting changes'))
-    results.append(output_api.PresubmitError(format_out))
     return results
 
 
@@ -232,13 +222,48 @@
 
 
 def _CheckGeneratedFiles(input_api, output_api):
+    v8_directory_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'v8')
+    blink_directory_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'third_party', 'blink')
+    protocol_location = input_api.os_path.join(blink_directory_path, 'public', 'devtools_protocol')
+    scripts_build_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'build')
+
+    generated_aria_path = input_api.os_path.join(scripts_build_path, 'generate_aria.py')
+    generated_supported_css_path = input_api.os_path.join(scripts_build_path, 'generate_supported_css.py')
+    generated_protocol_path = input_api.os_path.join(scripts_build_path, 'code_generator_frontend.py')
+    concatenate_protocols_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'third_party', 'inspector_protocol',
+                                                        'concatenate_protocols.py')
+
+    affected_files = _getAffectedFiles(input_api, [
+        v8_directory_path,
+        blink_directory_path,
+        input_api.os_path.join(input_api.PresubmitLocalPath(), 'third_party', 'pyjson5'),
+        generated_aria_path,
+        generated_supported_css_path,
+        concatenate_protocols_path,
+        generated_protocol_path,
+    ], [], ['.pdl', '.json5', '.py'])
+
+    if len(affected_files) == 0:
+        return []
+
     results = [output_api.PresubmitNotifyResult('Running Generated Files Check:')]
 
-    generated_aria_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'build', 'generate_aria.py')
     results = _ExecuteSubProcess(input_api, output_api, generated_aria_path, [], results)
+    results = _ExecuteSubProcess(input_api, output_api, generated_supported_css_path, [], results)
 
-    generated_aria_path = input_api.os_path.join(input_api.PresubmitLocalPath(), 'scripts', 'build', 'generate_supported_css.py')
-    results = _ExecuteSubProcess(input_api, output_api, generated_aria_path, [], results)
+    results = _ExecuteSubProcess(
+        input_api,
+        output_api,
+        concatenate_protocols_path,
+        [
+            input_api.os_path.join(protocol_location, 'browser_protocol.pdl'),
+            input_api.os_path.join(v8_directory_path, 'include', 'js_protocol.pdl'),
+            # output_file
+            input_api.os_path.join(protocol_location, 'browser_protocol.json'),
+        ],
+        results)
+
+    results = _ExecuteSubProcess(input_api, output_api, generated_protocol_path, [], results)
 
     return results