Working with directories in Bazel is discouraged since Bazel will not accurately track the directory contents, however, I often find myself
running into the same problem where the input to rule just has to be a directory. Most commonly, I am setting something like PATH
, PYTHONPATH
, RESOURCES
, or TOOL_PATH
in a rule’s env dictionary and these environment variables have to be either a single directory or column separated paths/directories.
This question suggests a workaround for genrule
, but that approach does not work in rules like cc_binary
since you cannot use bash builtins like realpath
there.
Trivial example/MRE with cc_binary
:
filegroup(
name = "tool",
srcs = ["tool1", "tool1_config"],
)
cc_binary(
name = "example",
srcs = ["example.cc"],
env = {
# does not work, this is the paths to the generated files not the directory
"TOOL_PATH": "$(execpaths :tool)"
},
)
What is the idiomatic way of solving this problem in general in Bazel?