aboutsummaryrefslogtreecommitdiff
path: root/doc_build/BUILD
blob: c50e2d41d8cbf4a728da4b988743298f514e79fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Copyright 2022 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Generate the reference documentation.

How to:
   bazel build //doc_build:reference
   cp bazel-bin/doc_build/reference.md docs/latest.md
   git commit -m 'update docs' docs/latest.md
"""

load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
load("@rules_python//python:defs.bzl", "py_library")
load("//:version.bzl", "version")

package(default_package_metadata = ["//:license", "//:package_info"])

filegroup(
    name = "standard_package",
    srcs = [
        "BUILD",
    ] + glob([
        "*.bzl",
        "*.py",
    ]),
    visibility = ["//distro:__pkg__"],
)

exports_files(
    glob([
        "*.bzl",
    ]),
    visibility = [
        "//distro:__pkg__",
    ],
)

# pairs of rule name and the source file to get it from
# Must put macro wrapped rules after their wrapper
# buildifier: leave-alone, do not sort
ORDER = [
    ("license",         "//rules:license.bzl"),
    ("_license",        "//rules:license.bzl"),
    ("license_kind",    "//rules:license_kind.bzl"),
    ("_license_kind",   "//rules:license_kind.bzl"),
    ("package_info",    "//rules:package_info.bzl"),
    ("_package_info",   "//rules:package_info.bzl"),
    ("LicenseInfo",     "//rules:providers.bzl"),
    ("LicenseKindInfo", "//rules:providers.bzl"),
    ("PackageInfo",     "//rules:providers.bzl"),
]

genrule(
    name = "reference",
    srcs = ["%s.md" % rule for rule, _ in ORDER],
    outs = ["reference.md"],
    cmd = "$(location :merge) $(SRCS) >$@",
    tools = [":merge"],
)

[
    stardoc(
        name = "%s_gen" % rule,
        out = "%s.md" % rule,
        input = src,
        symbol_names = [
            rule,
        ],
        deps = [":lib_of_everything"],
    )
    for rule, src in ORDER
    if src
]

# gather all rules that should be documented
bzl_library(
    name = "lib_of_everything",
    srcs = [
        "//:version.bzl",
        "//rules:standard_package",
        "//rules/private:standard_package",
        # "@bazel_skylib//lib:paths",
    ],
    visibility = ["//visibility:public"],
)

# This is experimental. We are waiting for stardoc to get the features which
# are done in merge.
py_binary(
    name = "merge",
    srcs = ["merge.py"],
    python_version = "PY3",
    srcs_version = "PY3",
    visibility = ["//visibility:private"],
)