Reputation: 2306
I've got a genrule
that produces some output files but the tool I'm using needs to know where to put the files.
So far, I've been able to get working by using dirname $(location outputfile)
, but this seems like a very fragile solution
Upvotes: 0
Views: 7227
Reputation: 5026
You can read about which make variables are available in a genrule
here:
https://docs.bazel.build/versions/master/be/make-variables.html
In particular:
@D: The output directory. If there is only one filename in
outs
, this expands to the directory containing that file. If there are multiple filenames, this variable instead expands to the package's root directory in thegenfiles
tree, even if all the generated files belong to the same subdirectory! If the genrule needs to generate temporary intermediate files (perhaps as a result of using some other tool like a compiler) then it should attempt to write the temporary files to@D
(although/tmp
will also be writable), and to remove any such generated temporary files. Especially, avoid writing to directories containing inputs - they may be on read-only filesystems, and even if they aren't, doing so would trash the source tree.
In general, if the tool lets you (or if you're writing your own tool) it's best if you give the tool the individual input and output file names. For example, if the tool understands inputs only as directories, and that's usually ok if the directory contains only the things you want, but if it doesn't, then you have to rely on sandboxing to show the tool only the files you want, or you have to manually create temporary directories. Outputs as directories gives you less control over what the outputs are named, and you still have to enumerate the files in the genrule
's outs
.
Upvotes: 3