diff --git a/internal/providers/node_runtime_deps_info.bzl b/internal/providers/node_runtime_deps_info.bzl index 6a7920ae3f..154117f571 100644 --- a/internal/providers/node_runtime_deps_info.bzl +++ b/internal/providers/node_runtime_deps_info.bzl @@ -67,10 +67,10 @@ def run_node(ctx, inputs, arguments, executable, **kwargs): exec_exec = getattr(ctx.executable, executable) outputs = kwargs.pop("outputs", []) - extra_inputs = [] + extra_inputs = depset() link_data = [] if (NodeRuntimeDepsInfo in exec_attr): - extra_inputs = exec_attr[NodeRuntimeDepsInfo].deps.to_list() + extra_inputs = exec_attr[NodeRuntimeDepsInfo].deps link_data = exec_attr[NodeRuntimeDepsInfo].pkgs mnemonic = kwargs.get("mnemonic") @@ -114,9 +114,17 @@ def run_node(ctx, inputs, arguments, executable, **kwargs): env[var] = ctx.configuration.default_shell_env[var] env["BAZEL_NODE_MODULES_ROOT"] = _compute_node_modules_root(ctx) + # ctx.actions.run accepts both lists and a depset for inputs. Coerce the original inputs to a + # depset if they're a list, so that extra inputs can be combined in a performant manner. + inputs_depset = depset(transitive = [ + depset(direct = inputs) if type(inputs) == "list" else inputs, + extra_inputs, + depset(direct = [modules_manifest]), + ]) + ctx.actions.run( outputs = outputs, - inputs = inputs + extra_inputs + [modules_manifest], + inputs = inputs_depset, arguments = arguments, executable = exec_exec, env = env, diff --git a/internal/providers/test/BUILD.bazel b/internal/providers/test/BUILD.bazel index 2bfaad61bd..e3322dedab 100644 --- a/internal/providers/test/BUILD.bazel +++ b/internal/providers/test/BUILD.bazel @@ -17,6 +17,11 @@ nodejs_binary( entry_point = "js-write-file.js", ) +nodejs_binary( + name = "cloner_bin", + entry_point = "js-clone-file.js", +) + js_write_file( name = "write_file", content = "test file content", @@ -32,5 +37,7 @@ js_write_file( for file in [ "out", "out2", + "out3", + "out4", ] ] diff --git a/internal/providers/test/js-clone-file.js b/internal/providers/test/js-clone-file.js new file mode 100644 index 0000000000..c199d91196 --- /dev/null +++ b/internal/providers/test/js-clone-file.js @@ -0,0 +1,9 @@ +const readFileSync = require('fs').readFileSync; +const writeFileSync = require('fs').writeFileSync; + +const inputPath = process.argv[2]; +const outputPath = process.argv[3]; + +const content = readFileSync(inputPath, 'utf8'); + +writeFileSync(outputPath, content, {encoding: 'utf8'}); diff --git a/internal/providers/test/run_node_test.bzl b/internal/providers/test/run_node_test.bzl index 2c6f0cc8bf..07161cb162 100644 --- a/internal/providers/test/run_node_test.bzl +++ b/internal/providers/test/run_node_test.bzl @@ -31,14 +31,53 @@ def _js_write_file_impl(ctx): outputs = [ctx.outputs.out2], ) + content_txt = ctx.actions.declare_file("content.txt") + ctx.actions.write( + output = content_txt, + content = ctx.attr.content, + ) + + run_node( + ctx = ctx, + executable = "_clone", + mnemonic = "cloner", + # Pass inputs as a list. + inputs = [content_txt], + arguments = [ + content_txt.path, + ctx.outputs.out3.path, + ], + outputs = [ctx.outputs.out3], + ) + + run_node( + ctx = ctx, + executable = "_clone", + mnemonic = "cloner", + # Pass inputs as a depset. + inputs = depset(direct = [content_txt]), + arguments = [ + content_txt.path, + ctx.outputs.out4.path, + ], + outputs = [ctx.outputs.out4], + ) + js_write_file = rule( implementation = _js_write_file_impl, outputs = { "out": "out.txt", "out2": "out2.txt", + "out3": "out3.txt", + "out4": "out4.txt", }, attrs = { "content": attr.string(), + "_clone": attr.label( + default = Label("//internal/providers/test:cloner_bin"), + cfg = "host", + executable = True, + ), "_writer": attr.label( default = Label("//internal/providers/test:writer_bin"), cfg = "host",