@@ -12,6 +12,8 @@ _ATTRS = {
1212 "data" : attr .label_list (allow_files = True , aspects = [module_mappings_aspect , node_modules_aspect ]),
1313 "output_dir" : attr .bool (),
1414 "outs" : attr .output_list (),
15+ "stderr" : attr .output (),
16+ "stdout" : attr .output (),
1517 "tool" : attr .label (
1618 executable = True ,
1719 cfg = "host" ,
@@ -38,12 +40,13 @@ def _inputs(ctx):
3840def _impl (ctx ):
3941 if ctx .attr .output_dir and ctx .outputs .outs :
4042 fail ("Only one of output_dir and outs may be specified" )
41- if not ctx .attr .output_dir and not ctx .outputs .outs :
42- fail ("One of output_dir and outs must be specified" )
43+ if not ctx .attr .output_dir and not ctx .outputs .outs and not ctx . attr . stdout :
44+ fail ("One of output_dir, outs or stdout must be specified" )
4345
4446 args = ctx .actions .args ()
4547 inputs = _inputs (ctx )
4648 outputs = []
49+
4750 if ctx .attr .output_dir :
4851 outputs = [ctx .actions .declare_directory (ctx .attr .name )]
4952 else :
@@ -52,15 +55,25 @@ def _impl(ctx):
5255 for a in ctx .attr .args :
5356 args .add_all ([expand_variables (ctx , e , outs = ctx .outputs .outs , output_dir = ctx .attr .output_dir ) for e in _expand_locations (ctx , a )])
5457
58+ tool_outputs = []
59+ if ctx .outputs .stdout :
60+ tool_outputs .append (ctx .outputs .stdout )
61+
62+ if ctx .outputs .stderr :
63+ tool_outputs .append (ctx .outputs .stderr )
64+
5565 run_node (
5666 ctx ,
5767 executable = "tool" ,
5868 inputs = inputs ,
5969 outputs = outputs ,
6070 arguments = [args ],
6171 configuration_env_vars = ctx .attr .configuration_env_vars ,
72+ stdout = ctx .outputs .stdout ,
73+ stderr = ctx .outputs .stderr ,
6274 )
63- return [DefaultInfo (files = depset (outputs ))]
75+
76+ return [DefaultInfo (files = depset (outputs + tool_outputs ))]
6477
6578_npm_package_bin = rule (
6679 _impl ,
@@ -85,6 +98,10 @@ def npm_package_bin(tool = None, package = None, package_bin = None, data = [],
8598 output_dir: set to True if you want the output to be a directory
8699 Exactly one of `outs`, `output_dir` may be used.
87100 If you output a directory, there can only be one output, which will be a directory named the same as the target.
101+ stderr: set to capture the stderr of the binary to a file, which can later be used as an input to another target
102+ subject to the same semantics as `outs`
103+ stdout: set to capture the stdout of the binary to a file, which can later be used as an input to another target
104+ subject to the same semantics as `outs`
88105
89106 args: Command-line arguments to the tool.
90107
0 commit comments