1

I want to integrate checkstyle with bazel following this SO thread: What is the best way to invoke Checkstyle from within Bazel?
which works perfectly as long as I provide the full harcoded path when building the classpath

checkstyle.bzl

for file in ctx.files._classpath:
    if add:
        classpath += ":"
    add=True
    classpath += "/home/user/src/repo/" + file.path
for file in ctx.files.deps:
    classpath += ":" + "/home/user/src/repo/" + file.path

The downloaded jars are living in the bazel-out dir on the same level with my WORKSPACE.

/home/user/src/repo/
- /bazel-out
- /tools
-- checkstyle.bzl
-- BUILD
- WORKSPACE

How can I get the full path of bazel-out so I can append it to file.path?

Also, it's my 3rd day working with bazel, if there is a better way to do this then please suggest.

KeykoYume
  • 2,497
  • 6
  • 24
  • 48
  • Basically, you either want to use `ctx.bin_dir` or `ctx.genfiles_dir`. The output usually links to former. – oakad Jun 15 '21 at 10:58
  • `ctx.bin_dir.path` and `ctx.genfiles_dir.path` return `bazel-out/k8-opt/bin`. I'm looking for the full path to `bazel-out` – KeykoYume Jun 15 '21 at 11:12
  • Would something like this help? https://github.com/bazelbuild/bazel/issues/12351#issuecomment-729743609 – user2515975 Jun 15 '21 at 17:46
  • Aren't genrules only writing the output to files? I have something similar where I write the full path I need in a file but then can't read files with bazel, can I? – KeykoYume Jun 16 '21 at 07:09

0 Answers0