0

I am trying to create a javadoc based on the javadoc.bzl
I have added in my BUILD file under the root of my project to load the rule:

load("//rules:javadoc.bzl", "javadoc")

javadoc(
    name = "api-docs",
    srcs = glob(["**/*.java"])
)

But when I run it it fails and from what I see using the --sandbox_debug it does not seem to be calling javadoc with any source files Specifically running: bazel build --sandbox_debug :api-docs
I get:

BUILD:3:8: error executing shell command: '/bin/bash -c mkdir api-docs
external/local_jdk/bin/javadoc -quiet -d api-docs  zip -q -r
bazel-out/darwin-fastbuild/bin/api-docs.zip api-docs/*' failed (Exit
12): sandbox-exec failed: error executing command

and later on javadoc: error - No packages or classes specified.

If I understand correctly the error reported, I see external/local_jdk/bin/javadoc -quiet -d api-docs called but no files as input.
What am I doing wrong here?

Jim
  • 3,845
  • 3
  • 22
  • 47

1 Answers1

1

glob doesn't pass over package boundaries and so the glob won't match any directories that have a BUILD file in them. I suspect you have a BUILD file in the directory that you are trying to match against.

In your src directory add the following to your BUILD file

filegroup(
   name = "javasrcs",
   srcs = glob(["**/*.java"]),
   visibility = ["//visibility:public"],
)

Then in your top level BUILD file reference it like this:

load("//rules:javadoc.bzl", "javadoc")

javadoc(
    name = "api-docs",
    srcs = ["//src:javasrcs"],
)

assuming the sources are in a directory src

James Sharpe
  • 524
  • 2
  • 8
  • I do have a `BUILD` file in the package that has the java files for which I am trying to create the javadoc if I understood what you said. What can I do to fix this? – Jim Nov 17 '20 at 09:10
  • You can create a filtegroup in the `BUILD` file in the package that has the java files and then reference that in the `javadoc` rule in the top-level `BUILD` file – James Sharpe Nov 17 '20 at 09:13
  • Do you have an example snippet how to do that? Googling "bazel filter group" does not give any results that seem relevant – Jim Nov 17 '20 at 09:15
  • Is it something like this? https://docs.bazel.build/versions/master/user-manual.html#flag--strategy_regexp – Jim Nov 17 '20 at 09:16
  • Apologies that should be `filegroup` – James Sharpe Nov 17 '20 at 09:57
  • 1
    Apologies; I typoed `//visibility:public`. In you case then the top level reference would look like `"//src/main/java/com/test:javasrcs"` – James Sharpe Nov 17 '20 at 10:26
  • Now it complains that a class does not exist. My structure is: `src/main/java/test/TestClass.java` and `src/main/java/test/util/Util.java` where `Test.java` uses `Util.java`. It builds and runs fine but now the `bazel build --sandbox_debug //:api-docs` complain that the package `src.main.java.com.test.util` does not exist – Jim Nov 17 '20 at 10:29
  • If I copy that `filegroup` inside the `util` package e.g. `name="javasrcs2"` and then in the top level `BUILD` I do: `srcs = ["//src/main/java/test:javasrcs", "//src/main/java/test/util:javasrcs2]` it can find the class `Util` but it complains about an imported package (external dependency packange import) in the `Util` class – Jim Nov 17 '20 at 10:35
  • I commented out that import out of curiosity and the `bazel build --sandbox_debug //:api-docs` shows: `INFO: Build completed successfully, 1 total action` but I can't find the javadoc produced anywhere – Jim Nov 17 '20 at 10:44
  • Actually I did find the zipped java doc. So it seems something is missing to include third party dependencies. What is that? – Jim Nov 17 '20 at 10:55
  • Basically the problem now seems to be that the specific declaration somehow needs to include used libraries. What is the syntax for that? – Jim Nov 17 '20 at 11:50