Skip to content

Commit b34d7bb

Browse files
mattemalexeagle
authored andcommitted
feat: add templated_args_file to allow long agrs to be written to a file
1 parent f871be6 commit b34d7bb

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

internal/node/node.bzl

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,23 @@ def _nodejs_binary_impl(ctx):
176176
node_tool_files += node_tool_info.target_tool.files.to_list()
177177
node_tool = _short_path_to_manifest_path(ctx, node_tool_files[0].short_path)
178178

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+
179194
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,
184196
"TEMPLATED_env_vars": env_vars,
185197
"TEMPLATED_expected_exit_code": str(expected_exit_code),
186198
"TEMPLATED_node": node_tool,
@@ -376,6 +388,13 @@ _NODEJS_EXECUTABLE_ATTRS = {
376388
`--node_options=--preserve-symlinks`
377389
""",
378390
),
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+
),
379398
"_launcher_template": attr.label(
380399
default = Label("//internal/node:node_launcher.sh"),
381400
allow_single_file = True,

0 commit comments

Comments
 (0)