Running bazel build //:run_b will then result in an error message:
$ bazel build //:run_b
INFO: Analyzed target //:run_b (0 packages loaded, 3 targets configured).
INFO: Found 1 target...
ERROR: /home/knakayam/dev/playground/misc/bazel/BUILD:8:11: RunBinary out.txt failed: (Exit 1): generate_file failed: error executing command (from target //:run_b) bazel-out/k8-opt-exec-2B5CBBC6/bin/generate_file '$(RULEDIR)'
Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
touch: cannot touch '$(RULEDIR)/out.txt': No such file or directory
Target //:run_b failed to build
Use --verbose_failures to see the command lines of failed build steps.
This is because $(RULEDIR) is not expanded in args. Using genrule instead of run_binary can solve the problem.
Example:
WORKSPACE:
BUILD:
generate_file.sh:
Running
bazel build //:run_b
will then result in an error message:This is because
$(RULEDIR)
is not expanded inargs
. Usinggenrule
instead ofrun_binary
can solve the problem.genrule
documetation says:genrule - https://bazel.build/reference/be/general
but
run_binary
cannot be considered only when running a single tool.