In Bazel, given a build target, how would a script (which is running outside of Bazel) get the path to the generated file?
Scenario: I\'m using Bazel to do the build
Between two runs of bazel
, the output path should be identical. That is to say, if you build //path/to:target
then bazel clean
and build again, it should produce the same file. Since this output file is constant, you could run
ls "$(bazel info bazel-genfiles)/main.out"
and I believe that would give you a reference to where that file will be created once a build occurs (it will not build it for you).
If you're looking to go from a target to a filename that is going to be dependent on the rules_*
you're running. For example in rules_go, the output path depends on the arguments to the go_library
target. The rules_go team has recently documented this behavior for their project.
Binary output paths should, generally, be stable from version to version and you can rely on them not differing too much. However, in my experience this problem is generally a sign that you should consider moving that formerly external part of your process into Bazel as a genrule or custom rule. For example, I was formerly using this very trick to assemble a NPM package but now I do the whole thing in Bazel and have a single target that generates the .tar that I was interested in uploading to NPM. Maybe you could follow up with some specifics on what it is you're interested in doing and we might be able to work through a solution that doesn't depend on external systems understanding the Bazel build paths.