Reputation: 1
I have a python program that takes 2 command line arguments and execute the logic to do desired action. And I'm generating a executable by using py_binary for python program. I want to have a bazel rule to invoke the py_binary and pass 2 command line arguments to that rule by calling it from where ever I want.
//example/Build : py_binary:
py_binary(
name = "py_pgm",
srcs = glob(["*.py"]),
main = "main.py",
visibility = ["//visibility:public"],
)
examples/defs.bzl:
def _impl(ctx):
ctx.action(
)
ex_rule= rule(
implementation = _impl,
attrs = { } )
I need a rule to invoke the "example"
application/Build:
load('//examples:defs.bzl', 'ex_rule')
ex_rule(
name:run
args = device_name and file path
)
Can someone help me with the bazel rule to invoke py_binary. I looked online for some hints but the ones present are from 2016 and many of the logics are deprecated so I couldn't get anything to work. Referred Sources: https://github.com/bazelbuild/bazel/issues/1147 https://github.com/bazelbuild/bazel/issues/1192
If someone can help me with the rule it would be of great help.
Upvotes: 0
Views: 1549
Reputation: 1342
Like this?
genrule(
name = "run_my_thing",
srcs = ["//example:py_pgm"],
outs = ["fractal.pgm"],
cmd = "$(location //example:py_pgm) output $@"
)
https://bazel.build/reference/be/general#genrule
Your question didn't include any explanation of why you need a rule that runs a command. Everything in the BUILD file exists to create some output from some input, so in my example, I have it producing "fractal.pgm".
Upvotes: 1