如何在 bazel 中获取目标目录
How do I get the target directory in bazel
我有一个 genrule
可以生成一些输出文件,但我使用的工具需要知道将文件放在哪里。
到目前为止,我已经能够通过使用 dirname $(location outputfile)
开始工作,但这似乎是一个非常脆弱的解决方案
您可以在此处阅读 genrule
中可用的 make 变量:
https://docs.bazel.build/versions/master/be/make-variables.html
特别是:
@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 the genfiles
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.
一般来说,如果该工具允许您(或者如果您正在编写自己的工具),最好为该工具提供单独的输入和输出文件名。例如,如果该工具仅将输入理解为目录,并且如果该目录仅包含您想要的内容通常没问题,但如果不包含,则您必须依靠沙盒来仅向该工具显示您想要的文件,或者您必须手动创建临时目录。作为目录的输出使您对输出命名的控制较少,并且您仍然必须枚举 genrule
的 outs
.
中的文件
我有一个 genrule
可以生成一些输出文件,但我使用的工具需要知道将文件放在哪里。
到目前为止,我已经能够通过使用 dirname $(location outputfile)
开始工作,但这似乎是一个非常脆弱的解决方案
您可以在此处阅读 genrule
中可用的 make 变量:
https://docs.bazel.build/versions/master/be/make-variables.html
特别是:
@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.
一般来说,如果该工具允许您(或者如果您正在编写自己的工具),最好为该工具提供单独的输入和输出文件名。例如,如果该工具仅将输入理解为目录,并且如果该目录仅包含您想要的内容通常没问题,但如果不包含,则您必须依靠沙盒来仅向该工具显示您想要的文件,或者您必须手动创建临时目录。作为目录的输出使您对输出命名的控制较少,并且您仍然必须枚举 genrule
的 outs
.