def _impl(ctx):
py_runtime_info = ctx.attr._python_toolchain[PyRuntimeInfo]
python_path = py_runtime_info.interpreter.path # external/python_windows/python.exe
inputs = [ctx.file.main] + ctx.files.srcs
bindir = ctx.var["BINDIR"] # bazel-out/x64_windows-fastbuild/bin
args = ctx.actions.args()
args.add(ctx.file.main)
args.add(bindir)
args.add_all(ctx.attr.args)
ctx.actions.run(
executable = python_path,
inputs = inputs,
arguments = [args],
outputs = ctx.outputs.outs,
tools = py_runtime_info.files,
)
return DefaultInfo(
files = depset(ctx.outputs.outs),
runfiles = ctx.runfiles(files = ctx.outputs.outs),
)
run_python = rule(
implementation = _impl,
attrs = {
"main": attr.label(
allow_single_file = True,
),
"srcs": attr.label_list(
allow_files = True,
doc = "Additional inputs of the action.<br/><br/>These labels are available for" +
" <code>$(location)</code> expansion in <code>args</code> and <code>env</code>.",
),
"args": attr.string_list(
doc = "Command line arguments of the binary.<br/><br/>Subject to" +
" expansion.",
),
"outs": attr.output_list(
mandatory = True,
doc = "Output files generated by the action.<br/><br/>These labels are available for" +
" <code>$(location)</code> expansion in <code>args</code> and <code>env</code>.",
),
"_python_toolchain": attr.label(default = "@tab_toolchains//bazel/toolchains/python:tab_python_runtime"),
},
)