Move maprule() to a private directory, to
discourage use of it. I (@laszlocsomor) am
planning breaking changes to it.
Also move private files (rule implementations) to
a subdirectory "rules/private/", to clean up the
"rules/" directory.
In this PR:
- In the _resolve_locations function: use the
Bash-less ctx.resolve_tools function to resolve
the runfiles manifests and inputs of tools,
instead of using ctx.resolve_command for
the same purpose.
- In the _custom_envmap function: no longer
resolve $(location) references when
creating the envvars from custom_env, because
those references were already resolved in
_resolve_locations.
The ctx.resolve_tools() method was added in this
PR: https://github.com/bazelbuild/bazel/pull/7139
See design doc there.
maprule() is an improved version of
native.genrule(), with the following advantages:
- Maprule can process source files in parallel,
creating separate actions for each of them.
- Maprule does not require declaring all output
files. Instead you declare templates for the
output files yielded for each source. Therefore
N source files and M templates yield N*M
outputs.
- Maprule supports both Bash and cmd.exe syntax
for its commands via the specialized rules
bash_maprule and cmd_maprule.
- Maprule's cmd attribute does deliberately not
support $(location) expression nor Make
Variables, in order to avoid issues and
challenges with quoting. (In case of cmd.exe
passing empty arguments is impossible). These
paths can be passed as envvars instead.
- Maprule's add_env attribute does support
$(location) expressions (and some extra
placeholders) and is the idiomatic way to pass
execpaths of labels in "tools" or "srcs" (the
shared sources available for all actions) to the
command.
See https://github.com/bazelbuild/bazel/issues/4319