[Autoroller] Pass node path to inner script in `roll_deps.py`

Bug: 40272289
Change-Id: I118ef85657f9bbced8bdb850eb862d2a90c308c0
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/5277378
Reviewed-by: Liviu Rau <[email protected]>
Commit-Queue: Ergün Erdoğmuş <[email protected]>
diff --git a/scripts/deps/generate_protocol_resources.py b/scripts/deps/generate_protocol_resources.py
index 82a62cf..45b3381 100755
--- a/scripts/deps/generate_protocol_resources.py
+++ b/scripts/deps/generate_protocol_resources.py
@@ -38,6 +38,7 @@
 # language server) would not see the types and start complaining,
 # even though the local build would succeed.
 
+import argparse
 import os.path as path
 import os
 import subprocess
@@ -69,6 +70,14 @@
 TSC_LOCATION = devtools_paths.typescript_compiler_path()
 
 
+def parse_options(cli_args):
+    parser = argparse.ArgumentParser(description='Generate protocol resources')
+    parser.add_argument(
+        '--node-path',
+        default=NODE_LOCATION,
+    )
+    return parser.parse_args(cli_args)
+
 def popen(arguments, cwd=ROOT_DIRECTORY, env=os.environ.copy()):
     process = subprocess.Popen([sys.executable] + arguments, cwd=cwd, env=env)
 
@@ -78,24 +87,30 @@
         sys.exit(process.returncode)
 
 
-def runTsc(file_to_compile):
-    process = subprocess.Popen([NODE_LOCATION, TSC_LOCATION, file_to_compile], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+def runTsc(file_to_compile, options):
+    process = subprocess.Popen(
+        [options.node_path, TSC_LOCATION, file_to_compile],
+        stdout=subprocess.PIPE,
+        stderr=subprocess.PIPE)
     stdout, stderr = process.communicate()
     # TypeScript does not correctly write to stderr because of https://github.com/microsoft/TypeScript/issues/33849
     return process.returncode, stdout + stderr
 
 
-def runNode(file_to_execute):
-    process = subprocess.Popen([NODE_LOCATION, file_to_execute], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+def runNode(file_to_execute, options):
+    process = subprocess.Popen([options.node_path, file_to_execute],
+                               stdout=subprocess.PIPE,
+                               stderr=subprocess.PIPE)
     stdout, stderr = process.communicate()
     return process.returncode, stdout + stderr
 
 
-def generate_protocol_typescript_definitions():
+def generate_protocol_typescript_definitions(options):
     generator_script_to_compile = path.join(ROOT_DIRECTORY, 'scripts', 'protocol_typescript', 'protocol_dts_generator.ts')
 
     # first run TSC to convert the script from TS to JS
-    typescript_found_errors, typescript_stderr = runTsc(generator_script_to_compile)
+    typescript_found_errors, typescript_stderr = runTsc(
+        generator_script_to_compile, options)
 
     if typescript_found_errors:
         print('')
@@ -107,7 +122,7 @@
 
     outputted_file_path = generator_script_to_compile.replace('.ts', '.js')
 
-    node_found_errors, node_stderr = runNode(outputted_file_path)
+    node_found_errors, node_stderr = runNode(outputted_file_path, options)
 
     if node_found_errors:
         print('')
@@ -120,6 +135,8 @@
 
 # Generate the required `front_end/generated` files that are based on files living in Blink
 def main():
+    options = parse_options(sys.argv[1:])
+
     popen([GENERATE_ARIA_SCRIPT])
     popen([GENERATE_SUPPORTED_CSS_SCRIPT])
     popen([GENERATE_DEPRECATIONS_SCRIPT])
@@ -133,7 +150,7 @@
 
     popen([GENERATE_PROTOCOL_DEFINITIONS_SCRIPT])
 
-    generate_protocol_typescript_definitions()
+    generate_protocol_typescript_definitions(options)
 
 
 if __name__ == '__main__':
diff --git a/scripts/deps/roll_deps.py b/scripts/deps/roll_deps.py
index b5bee60..c7ffc7e 100755
--- a/scripts/deps/roll_deps.py
+++ b/scripts/deps/roll_deps.py
@@ -139,7 +139,8 @@
     print('generating protocol resources')
     subprocess.check_call([
         os.path.join(options.devtools_dir, 'scripts', 'deps',
-                     'generate_protocol_resources.py')
+                     'generate_protocol_resources.py'), '--node-path',
+        node_path(options)
     ],
                           cwd=options.devtools_dir)