Some things to keep in mind when writing genrules:
- A genrule needs to know all its input files and output files (
srcs
and outs
attributes)
- It needs to know the tools it's going to use in the command (
exec_tools
attribute). These tools can be other things that need to be built, like binary targets (cc_binary, java_binary, sh_binary, py_binary, etc), or they can be pre-compiled binaries.
- The tools have to produce the same files that the genrule declares in the
outs
attribute. It's often easier to declare the files in the outs
attribute and then pass the file names to the tool using $(OUTS)
in the cmd
attribute.
See the documentation for genrule, which includes some simple examples: https://docs.bazel.build/versions/master/be/general.html#genrule
It would look something like this:
genrule(
name = "gen_data",
srcs = [":dataFiles"],
outs = ["data.dat"],
exec_tools = ["//libpackfiles:FilePacker"],
cmd = "$(location //libpackfiles:FilePacker) $(OUTS) $(SRCS)"
)
This assumes that :dataFiles
is a filegroup
target in the same BUILD file as the gen_data
target which has a list of files of all the inputs you want to pack. Or it could be a filegroup
target in a BUILD file in the dataFiles directory, in which case it would be something like //app/MyApp/dataFiles:dataFiles
(and don't forget to set its visibility
attribute to //visibility:public
).
$(location //libpackfiles:FilePacker)
is replaced with the file path of that target. $(OUTS)
is replaced with all the files in the outs
attribute, and similarly for $(SRCS)
.