我有一个 genrule,它将 java 二进制文件作为 src 并使用 $(location ) 作为 cmd。当执行 genrule 时,我得到
Cannot locate runfiles directory. (Set $JAVA_RUNFILES to inhibit searching.)
如果我先构建二进制文件,然后执行 genrule,它就可以正常工作。我该如何解决这个问题?
如果将在
java_binary
的 cmd
属性中调用 genrule
目标,则 java_binary
应位于 tools
的 genrule
属性中,而不是 srcs
:
BUILD
:
java_binary(
name = "Main",
srcs = ["java/com/Main.java"],
)
genrule(
name = "gen",
tools = [":Main"],
outs = ["out"],
cmd = "$(location :Main) > $@",
)
Main.java
:
package com;
public class Main {
public static void main(String[] args) {
System.out.println("hello world");
}
}
$ bazel build out
INFO: Analyzed target //:out (1 packages loaded, 4 targets configured).
INFO: Found 1 target...
Target //:out up-to-date:
bazel-bin/out
INFO: Elapsed time: 0.297s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
$ cat bazel-bin/out
hello world