如何使用Stardoc生成多个文件的文档?

时间:2019-04-18 17:49:37

标签: bazel

我无法使用Stardoc 0.3.0和Bazel 0.24.1在单独的文件中生成多个bazel规则的文档。

这是我的设置。在单独的文件中有三个bazel规则。

BUILD

bzl_library(
    name = "bzl",
    srcs = ["antlr2.bzl", "antlr3.bzl", "antlr4.bzl"],
    deps = [
        "@bazel_skylib//:bzl_library",
    ],
)
stardoc(
    name = "single-docs",
    input = "antlr2.bzl",
    out = "antlr2_single.md",
)
stardoc(
    name = "multi-docs",
    input = "doc.bzl",
    out = "doc.md",
    deps = [":bzl"],
)

和一个文件加载它们:

doc.bzl

load("//antlr:antlr2.bzl", "antlr2")
load("//antlr:antlr3.bzl", "antlr3")
load("//antlr:antlr4.bzl", "antlr4")

它可以构建,但是生成的文件本质上是空的:

doc.md

<!-- Generated with Stardoc: http://skydoc.bazel.build -->

如果我按照文档的建议进行操作:

BUILD

...
stardoc(
    name = "multi-docs",
    input = "doc.bzl",
    out = "doc.md",
)

我收到一个错误:

Exception in thread "main" java.lang.IllegalStateException: File antlr/doc.bzl imported '//antlr:antlr2.bzl', yet antlr/antlr2.bzl was not found, even at roots [.].
    at com.google.devtools.build.skydoc.SkydocMain.recursiveEval(SkydocMain.java:420)
    at com.google.devtools.build.skydoc.SkydocMain.eval(SkydocMain.java:338)
    at com.google.devtools.build.skydoc.SkydocMain.main(SkydocMain.java:205)
Caused by: java.nio.file.NoSuchFileException: antlr/antlr2.bzl
    at com.google.devtools.build.skydoc.SkydocMain.getInputSource(SkydocMain.java:453)
    at com.google.devtools.build.skydoc.SkydocMain.recursiveEval(SkydocMain.java:404)
    at com.google.devtools.build.skydoc.SkydocMain.recursiveEval(SkydocMain.java:416)
    ... 2 more

我做错了还是这是一个错误?

顺便说一句,单个文件目标single-docs正确生成。

1 个答案:

答案 0 :(得分:1)

我终于明白了。不知道这是将来要更改/修复的东西还是只是尚未正确记录的东西:您必须为规则加上别名!

doc.bzl

load("//antlr:antlr4.bzl", _antlr4 = "antlr4")  
load("//antlr:antlr2.bzl", _antlr2 = "antlr2")  
load("//antlr:antlr3.bzl", _antlr3 = "antlr3")  

antlr4 = _antlr4  
antlr3 = _antlr3  
antlr2 = _antlr2