1*b2fa4294SXin Li**Last updated:** January 2021. 2*b2fa4294SXin Li 3*b2fa4294SXin Li**Summary:** We'll be redesigning how Stardoc works, and deprioritizing feature 4*b2fa4294SXin Lirequests and minor bugs until that work is complete (targeting 2021 Q2). 5*b2fa4294SXin Li 6*b2fa4294SXin Li## Technical motivation 7*b2fa4294SXin Li 8*b2fa4294SXin LiStardoc is currently the recommended tool for generating documentation of 9*b2fa4294SXin LiStarlark rules. It [replaces](skydoc_deprecation.md) *Sky*doc, the previous 10*b2fa4294SXin Litool, which worked by evaluating .bzl files in a Python interpreter, using 11*b2fa4294SXin Lifake versions of functions from Bazel's Build Language. 12*b2fa4294SXin Li 13*b2fa4294SXin LiMocking is an inherently problematic approach for two reasons: 14*b2fa4294SXin Li 15*b2fa4294SXin Li1. It creates a maintenance burden for the tool maintainer (us). We have to 16*b2fa4294SXin Liensure that the mocked definitions stay up-to-date as Bazel changes. These 17*b2fa4294SXin Liinclude not just `rule()` and `provider()`, but also a number of other symbols 18*b2fa4294SXin Lithat don't directly affect documentation but still require stubs. 19*b2fa4294SXin Li 20*b2fa4294SXin Li2. It puts a constraint on the user: All of their documented .bzl files, as 21*b2fa4294SXin Liwell as all of the .bzl dependencies they transitively load, must be 22*b2fa4294SXin Licompatible with the mock evaluation. This means users must be vigilant about 23*b2fa4294SXin Liwriting Starlark code that lies in the intersection of what is understood as 24*b2fa4294SXin Livalid by Bazel and by Stardoc. 25*b2fa4294SXin Li 26*b2fa4294SXin LiThe Python-based Skydoc experienced an extreme version of this problem because 27*b2fa4294SXin Liit didn't even treat .bzl files as being written in the Starlark language. 28*b2fa4294SXin LiHowever, the Java-based Stardoc still uses mocking -- not of the Starlark 29*b2fa4294SXin Lilanguage, but of Bazel's Build Language functions. 30*b2fa4294SXin Li 31*b2fa4294SXin LiIn addition, Stardoc's mocking approach tightly integrates it with Bazel. 32*b2fa4294SXin LiIndeed much of its source code lives inside the bazelbuild/bazel repository. 33*b2fa4294SXin LiThis makes refactoring and evolving the Bazel source code more difficult. 34*b2fa4294SXin Li 35*b2fa4294SXin LiWhile the Starlark language has a specification and several implementations, 36*b2fa4294SXin Lithe Build Language is more complicated and has only one accurate 37*b2fa4294SXin Liimplementation: Bazel. Any tooling that operates on BUILD and .bzl files must 38*b2fa4294SXin Licarefully consider whether it is feasible to ask Bazel for the authoritative 39*b2fa4294SXin Liinformation. The alternative, falling back on simulation, not only produces 40*b2fa4294SXin Liless accurate results, but ties our hands as we try to improve Bazel. 41*b2fa4294SXin Li 42*b2fa4294SXin Li## Our plans 43*b2fa4294SXin Li 44*b2fa4294SXin LiWe will rewrite the part of Stardoc that extracts documentation information from 45*b2fa4294SXin Li.bzl files, so that instead of using mocking to pseudo-evaluate individual .bzl 46*b2fa4294SXin Lifiles, it performs a real Bazel evaluation of the workspace. Think of how `bazel 47*b2fa4294SXin Liquery` is used to dump out information from Bazel's loading phase about the 48*b2fa4294SXin Litarget dependency graph. Now imagine that it's extended to also dump out the 49*b2fa4294SXin Lirules and providers declared in the .bzl files used by a build, and that this 50*b2fa4294SXin Lidump also includes their docstrings. 51*b2fa4294SXin Li 52*b2fa4294SXin LiThis approach intersects other work we are doing to simplify and better specify 53*b2fa4294SXin LiBazel's loading phase, so that users have access to all sorts of information 54*b2fa4294SXin Lithat was previously not readily available. 55*b2fa4294SXin Li 56*b2fa4294SXin LiNote that this new internal approach does not necessarily have to mean the 57*b2fa4294SXin Liuser's workflow changes. You could still write a target in your BUILD file to 58*b2fa4294SXin Lisay exactly what content you want documented and how you'd like it formatted. 59*b2fa4294SXin LiThe rendering logic may very well continue to live outside of Bazel, in the 60*b2fa4294SXin Libazelbuild/stardoc repository. 61*b2fa4294SXin Li 62*b2fa4294SXin Li## Prioritization 63*b2fa4294SXin Li 64*b2fa4294SXin LiWe're aiming to explore this design in more concrete detail in 2021 Q1, and 65*b2fa4294SXin Liimplement it in Q2. 66*b2fa4294SXin Li 67*b2fa4294SXin LiIn the meantime, *we will not be focusing on improvements to the current 68*b2fa4294SXin Liimplementation of Stardoc*, even the formatting parts which might remain the 69*b2fa4294SXin Lisame. We still commit to keeping Stardoc working for its existing essential use 70*b2fa4294SXin Licases. 71