bazelbuild / stardoc

Stardoc: Starlark Documentation Generator
Apache License 2.0
108 stars 45 forks source link

Cannot generate docs for rule depending on rules_jvm_external #107

Closed ngeor closed 3 years ago

ngeor commented 3 years ago

Bazel version: 4.1.0 rules_jvm_external version: 4.1

Hi, I'm trying to use stardoc for the first time in our Bazel repo. The repo is mostly for Java code, so it needs rules_jvm_external to pull in external Maven dependencies.

First of all, I tried to document just one Bazel rule. stardoc doesn't seem to be able to resolve this type of statements:

load("//some_other_package:config.bzl", "some_symbol")

it complains that the file doesn't exist.

So I moved on with the second attempt, trying to explicitly declare all the dependencies myself with a bzl_library. This bypassed the previous problem (which in my mind shouldn't be necessary) but then I hit this blocker:

target '@rules_jvm_external//:specs.bzl' is not visible from target '//rules/docs:deps'. Check the visibility declaration of the former target if you think the dependency is legitimate. To set the visibility of that source file target, use the exports_files() function

I can't modify rules_jvm_external, and it isn't exporting that file.

Is there some way I can bypass this problem?

tetromino commented 3 years ago

Can you please add more details about what specific load statements were giving you errors, and what you had in your bzl_library?

Note that rules_jvm_external exports defs.bzl - that's the entry point to the rules set, and afaict loading it should not raise an error in stardoc.

If you need to stick it into your own bzl_library, you can add a dependency to your bzl_library on the corresponding publicly visible bzl_library wrapping the defs.bzl file and all its dependencies - @rules_jvm_external//:implementation. See comment at https://github.com/bazelbuild/rules_jvm_external/blob/master/BUILD#L56

ngeor commented 3 years ago

Thank you, the @rules_jvm_external//:implementation did the trick (together with some liberal usage of bzl_library due to the structure of our project)!