xref: /aosp_15_r20/external/stardoc/docs/skydoc_deprecation.md (revision b2fa42943c124aa9c7163734493fc7a7559681cf)
1*b2fa4294SXin Li## Why was Skydoc deprecated?
2*b2fa4294SXin Li
3*b2fa4294SXin LiSkydoc functioned by evaluating Starlark files as if they were Python. Unfortunately, while
4*b2fa4294SXin LiStarlark is **similar** to Python, there are some important syntactic differences between
5*b2fa4294SXin Lithe languages. Assuming compatibility between the languages was inherently brittle, and resulted
6*b2fa4294SXin Liin a maintenance burden on the Starlark code. Specifically, if one of your transitive dependencies
7*b2fa4294SXin Liwere to adopt a Starlark-compatible, Python-incompatible construct, your Skydoc integration would
8*b2fa4294SXin Libreak!
9*b2fa4294SXin Li
10*b2fa4294SXin LiSkydoc still exists under [bazelbuild/skydoc](https://github.com/bazelbuild/skydoc), as it's a
11*b2fa4294SXin Linontrivial migration to Stardoc, but Skydoc is completely unsupported as of September 2019.
12*b2fa4294SXin LiThe [bazelbuild/skydoc](https://github.com/bazelbuild/skydoc) will be archived by end of 2019.
13*b2fa4294SXin Li
14*b2fa4294SXin Li## How to migrate
15*b2fa4294SXin Li
16*b2fa4294SXin LiStardoc is not a drop-in replacement for Skydoc. Its usage is slightly different, and it has some
17*b2fa4294SXin Linew features. It's recommended to take a look at the root Stardoc documentation, but here is
18*b2fa4294SXin Lia brief summary of some things to note for migration:
19*b2fa4294SXin Li
20*b2fa4294SXin Li### Docstring specification
21*b2fa4294SXin Li
22*b2fa4294SXin LiStardoc uses inline documentation strings instead of Python-style docstrings.
23*b2fa4294SXin LiFor example, Skydoc documentation may have been specified with:
24*b2fa4294SXin Li
25*b2fa4294SXin Li```python
26*b2fa4294SXin Limy_rule = rule(
27*b2fa4294SXin Li    implementation = _my_rule_impl,
28*b2fa4294SXin Li    attrs = {
29*b2fa4294SXin Li        "srcs": attr.label_list(),
30*b2fa4294SXin Li        "deps": attr.label_list(),
31*b2fa4294SXin Li    },
32*b2fa4294SXin Li)
33*b2fa4294SXin Li"""Example rule documentation.
34*b2fa4294SXin Li
35*b2fa4294SXin LiExample:
36*b2fa4294SXin Li  Here is an example of how to use this rule.
37*b2fa4294SXin Li
38*b2fa4294SXin LiArgs:
39*b2fa4294SXin Li  srcs: Source files used to build this target.
40*b2fa4294SXin Li  deps: Dependencies for this target.
41*b2fa4294SXin Li"""
42*b2fa4294SXin Li```
43*b2fa4294SXin Li
44*b2fa4294SXin Li...the equivalent for Stardoc is:
45*b2fa4294SXin Li
46*b2fa4294SXin Li```python
47*b2fa4294SXin Limy_rule = rule(
48*b2fa4294SXin Li    implementation = _my_rule_impl,
49*b2fa4294SXin Li    doc = """
50*b2fa4294SXin LiExample rule documentation.
51*b2fa4294SXin Li
52*b2fa4294SXin LiExample:
53*b2fa4294SXin Li  Here is an example of how to use this rule.
54*b2fa4294SXin Li""",
55*b2fa4294SXin Li    attrs = {
56*b2fa4294SXin Li        "srcs" : attr.label_list(
57*b2fa4294SXin Li            doc = "Source files used to build this target.",
58*b2fa4294SXin Li        ),
59*b2fa4294SXin Li        "deps" : attr.label_list(
60*b2fa4294SXin Li            doc = "Dependencies for this target.",
61*b2fa4294SXin Li        ),
62*b2fa4294SXin Li    }
63*b2fa4294SXin Li)
64*b2fa4294SXin Li```
65*b2fa4294SXin Li
66*b2fa4294SXin Li### Different Starlark Rule
67*b2fa4294SXin Li
68*b2fa4294SXin LiStardoc uses a different Starlark rule than Skydoc with different attributes.
69*b2fa4294SXin Li
70*b2fa4294SXin LiSee [Generating Documentation](generating_stardoc.md) for a
71*b2fa4294SXin Litutorial on using the new rule, and the
72*b2fa4294SXin Li[Build Rule Reference](docs/stardoc_reference.md) for information
73*b2fa4294SXin Liabout the new `stardoc` rule itself.
74*b2fa4294SXin Li
75*b2fa4294SXin Li### Starlark Dependencies
76*b2fa4294SXin Li
77*b2fa4294SXin LiStardoc depends on your `bzl` file, all of its dependencies, and all of its **transitive**
78*b2fa4294SXin Lidependencies, so that it can fully evaluate your Starlark code.
79*b2fa4294SXin Li`bazel-skylib`'s `bzl_library` is the recommend approach for tracking `bzl` dependencies.
80*b2fa4294SXin Li
81*b2fa4294SXin LiFor example, suppose your `mypackage/foo.bzl` file depends on `other/package/bar.bzl`, which
82*b2fa4294SXin Lidepends on `third/package/baz.bzl`.
83*b2fa4294SXin Li
84*b2fa4294SXin Li**BUILD**:
85*b2fa4294SXin Li
86*b2fa4294SXin Li```python
87*b2fa4294SXin Liload("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
88*b2fa4294SXin Li
89*b2fa4294SXin Listardoc(
90*b2fa4294SXin Li    name = "foo_docs",
91*b2fa4294SXin Li    input = "foo.bzl",
92*b2fa4294SXin Li    out = "foo_doc.md",
93*b2fa4294SXin Li    deps = ["//other/package:bar"],
94*b2fa4294SXin Li)
95*b2fa4294SXin Li```
96*b2fa4294SXin Li
97*b2fa4294SXin Li**other/package/BUILD**:
98*b2fa4294SXin Li
99*b2fa4294SXin Li```python
100*b2fa4294SXin Liload("@bazel_skylib//:bzl_library.bzl", "bzl_library")
101*b2fa4294SXin Li
102*b2fa4294SXin Libzl_library(
103*b2fa4294SXin Li    name = "bar",
104*b2fa4294SXin Li    srcs = ["bar.bzl"],
105*b2fa4294SXin Li    deps = ["//third/package:baz"],
106*b2fa4294SXin Li)
107*b2fa4294SXin Li```
108*b2fa4294SXin Li
109*b2fa4294SXin Li**third/package/BUILD**:
110*b2fa4294SXin Li
111*b2fa4294SXin Li```python
112*b2fa4294SXin Liload("@bazel_skylib//:bzl_library.bzl", "bzl_library")
113*b2fa4294SXin Li
114*b2fa4294SXin Libzl_library(
115*b2fa4294SXin Li    name = "baz",
116*b2fa4294SXin Li    srcs = ["baz.bzl"],
117*b2fa4294SXin Li)
118*b2fa4294SXin Li```
119*b2fa4294SXin Li
120*b2fa4294SXin LiThus, each `.bzl` file should appear in the `srcs` of a `bzl_library` target defined in the same
121*b2fa4294SXin Lipackage. The `deps` of this `bzl_library` should be (only) the `bzl_library` targets corresponding
122*b2fa4294SXin Lito the files that are _directly_ `load()`ed by the `srcs`. This structure mirrors that of other
123*b2fa4294SXin Li`<language>_library` rules in Bazel.
124*b2fa4294SXin Li
125*b2fa4294SXin LiThis migration might involve creating a large number of new `bzl_library` targets,
126*b2fa4294SXin Libut this work is useful beyond Stardoc. For example, `bzl_library` can be also used to gather
127*b2fa4294SXin Litransitive Starlark dependencies for use in shell tests or other test frameworks.
128*b2fa4294SXin Li
129*b2fa4294SXin LiSee [Generating Documentation](docs/generating_stardoc.md) for
130*b2fa4294SXin Lia tutorial.
131*b2fa4294SXin Li
132*b2fa4294SXin Li## Migration Issues
133*b2fa4294SXin Li
134*b2fa4294SXin LiIf you run into any issues migrating, please file a
135*b2fa4294SXin Li[GitHub issue](https://github.com/bazelbuild/stardoc/issues).
136*b2fa4294SXin Li
137*b2fa4294SXin Li
138