Skip to content

Commit

Permalink
maprule: add implementation and tests
Browse files Browse the repository at this point in the history
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 produces for each source. Therefore
  N source files and M templates produce N*M
  outputs.

- Maprule supports both Bash or 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. (Particluarly 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 bazelbuild/bazel#4319
  • Loading branch information
laszlocsomor committed Dec 6, 2018
1 parent daf5137 commit a7d03ba
Show file tree
Hide file tree
Showing 5 changed files with 1,047 additions and 0 deletions.
6 changes: 6 additions & 0 deletions README.md
Expand Up @@ -14,6 +14,8 @@ Each of the `.bzl` files in the `lib` directory defines a "module"—a
`struct` that contains a set of related functions and/or other symbols that can
be loaded as a single unit, for convenience.

Skylib also provides build rules under the `rules` directory.

## Getting Started

### `WORKSPACE` file
Expand Down Expand Up @@ -68,6 +70,10 @@ s = shell.quote(p)
* [unittest](lib/unittest.bzl)
* [versions](lib/versions.bzl)

## List of rules (in rules/)

* [`cmd_maprule` and `bash_maprule`](lib/maprule.bzl)

## Writing a new module

Steps to add a module to Skylib:
Expand Down
12 changes: 12 additions & 0 deletions rules/BUILD
@@ -0,0 +1,12 @@
load("//:bzl_library.bzl", "bzl_library")

licenses(["notice"])

exports_files(["maprule.bzl"])

bzl_library(
name = "maprule",
srcs = ["maprule.bzl"],
visibility = ["//visibility:public"],
deps = ["//lib:paths"],
)

0 comments on commit a7d03ba

Please sign in to comment.