On Mon, Dec 23, 2019 at 1:10 AM <
irs...@gmail.com> wrote:
>
> Had a time to play with genrule, and there's something I'm not sure about. I wrote a small Bash script that expects a folder (where he scans for specific files), and output a generate file that is being saved on the same folder where the script running from. It looks like so:
>
> sh_binary(
> name = "generate_file",
> srcs = ["//utils:generate_file.sh"],
> )
>
> genrule(
> name = "test",
> tools = [
> ":generate_file",
> ],
> outs = [
> "generate_file.txt",
> ],
> cmd = "$(location :tool) `pwd`",
> )
>
> This however will not work, because the file will get created in the root of the sandbox, rather than in bazel-out, and bazel will complain the out file is not being saved. I was checking examples in the wild, and almost all expeted the shell script to print the generated file into stdout like so:
>
>
> Another thing I can probably do is to modify the shell script to accept a path to save the generated file at:
>
> cmd = "$(location :tool) `pwd` $@",
>
> But is that the correct way of doing it? or there's a better way I'm missing here?
> Thanks!
You are very close. I would suggest ditching `pwd`.