@@ -176,11 +176,23 @@ def _nodejs_binary_impl(ctx):
176
176
node_tool_files += node_tool_info .target_tool .files .to_list ()
177
177
node_tool = _short_path_to_manifest_path (ctx , node_tool_files [0 ].short_path )
178
178
179
+ templated_args_substitutions = ""
180
+
181
+ if ctx .outputs .templated_args_file :
182
+ # node_options args, plus the args file arg
183
+ templated_args_substitutions = " " .join ([a for a in ctx .attr .templated_args if "--node_options=" in a ]) + " %s" % ctx .outputs .templated_args_file .short_path
184
+ ctx .actions .write (
185
+ output = ctx .outputs .templated_args_file ,
186
+ content = "\n " .join ([expand_location_into_runfiles (ctx , a ) for a in ctx .attr .templated_args if "--node_options=" not in a ]),
187
+ is_executable = False ,
188
+ )
189
+ node_tool_files += [ctx .outputs .templated_args_file ]
190
+ else :
191
+ templated_args = [expand_location_into_runfiles (ctx , a ) for a in ctx .attr .templated_args ]
192
+ templated_args_substitutions = " " .join (templated_args )
193
+
179
194
substitutions = {
180
- "TEMPLATED_args" : " " .join ([
181
- expand_location_into_runfiles (ctx , a )
182
- for a in ctx .attr .templated_args
183
- ]),
195
+ "TEMPLATED_args" : templated_args_substitutions ,
184
196
"TEMPLATED_env_vars" : env_vars ,
185
197
"TEMPLATED_expected_exit_code" : str (expected_exit_code ),
186
198
"TEMPLATED_node" : node_tool ,
@@ -376,6 +388,13 @@ _NODEJS_EXECUTABLE_ATTRS = {
376
388
`--node_options=--preserve-symlinks`
377
389
""" ,
378
390
),
391
+ "templated_args_file" : attr .output (
392
+ mandatory = False ,
393
+ doc = """If specified, arguments specified in `templated_args` are instead written to this file,
394
+ which is then passed as an argument to the program. Arguments prefix with `--node_options=` are ignored,
395
+ and still passed to node.
396
+ """ ,
397
+ ),
379
398
"_launcher_template" : attr .label (
380
399
default = Label ("//internal/node:node_launcher.sh" ),
381
400
allow_single_file = True ,
0 commit comments