Bazel genrule where outputs depend on the input

1.2k views Asked by At

This answer to Looking for examples of Bazel genrules that generate data files states that "A genrule needs to know all its input files and output files".

Is it possible to write a genrule whose outputs depend on the input file? For example

genrule(
    name = "creator",
    cmd = "xargs -a $< touch",
    srcs = [ "meow.txt" ],
)

This would create a file for each word in meow.txt, e.g.

Chico
Groucho
Harpo

would create three files.

The list of output files depends entirely on the content of meow.txt and is not known in the BUILD file.

1

There are 1 answers

0
Benjamin Peterson On

That is beyond the capabilities of genrule. However, it is possible write a custom rule that outputs a directory, into which arbitrary files can be written when the action executes.