bazel

Is there a way to create an executable bazel target that would actually call other executable bazel target but with parameters?


Lets say I have a bazel executable target target and I can run a command bazel run //my/lib:target -- --param=pam --pam. I want to enable user to create a default preconfigured way to run the same target: bazel run //my/lib:target_with_defaults that would essentially map to the same command as before: bazel run //my/lib:target -- --param=pam --pam. Is there a way to do in bazel?

I would imagine it would look something like:

executable(
    name = "target",
    deps = [":target_lib"],
)

executable_proxy(
    name = "target_with_defaults",
    deps = [":target"],
    defaults = ["--param=pam", "--pam"]
)

If not, what exactly breaks bazel philosophy here?

Why am I doing this? Later I want to gather all executable_proxy targets to run automatically for testing.


Solution

  • executable_proxy() would be an executable rule that generates a script that executes the executable with the flags from executable().

    There are some similar ideas in: How to properly handle args in sh_binary target?