Skip to content

Commit

Permalink
feat: add templated_args_file to allow long agrs to be written to a file
Browse files Browse the repository at this point in the history
  • Loading branch information
mattem authored and alexeagle committed Aug 27, 2019
1 parent f871be6 commit b34d7bb
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions internal/node/node.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,23 @@ def _nodejs_binary_impl(ctx):
node_tool_files += node_tool_info.target_tool.files.to_list()
node_tool = _short_path_to_manifest_path(ctx, node_tool_files[0].short_path)

templated_args_substitutions = ""

if ctx.outputs.templated_args_file:
# node_options args, plus the args file arg
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
ctx.actions.write(
output = ctx.outputs.templated_args_file,
content = "\n".join([expand_location_into_runfiles(ctx, a) for a in ctx.attr.templated_args if "--node_options=" not in a]),
is_executable = False,
)
node_tool_files += [ctx.outputs.templated_args_file]
else:
templated_args = [expand_location_into_runfiles(ctx, a) for a in ctx.attr.templated_args]
templated_args_substitutions = " ".join(templated_args)

substitutions = {
"TEMPLATED_args": " ".join([
expand_location_into_runfiles(ctx, a)
for a in ctx.attr.templated_args
]),
"TEMPLATED_args": templated_args_substitutions,
"TEMPLATED_env_vars": env_vars,
"TEMPLATED_expected_exit_code": str(expected_exit_code),
"TEMPLATED_node": node_tool,
Expand Down Expand Up @@ -376,6 +388,13 @@ _NODEJS_EXECUTABLE_ATTRS = {
`--node_options=--preserve-symlinks`
""",
),
"templated_args_file": attr.output(
mandatory = False,
doc = """If specified, arguments specified in `templated_args` are instead written to this file,
which is then passed as an argument to the program. Arguments prefix with `--node_options=` are ignored,
and still passed to node.
""",
),
"_launcher_template": attr.label(
default = Label("//internal/node:node_launcher.sh"),
allow_single_file = True,
Expand Down

0 comments on commit b34d7bb

Please sign in to comment.