xref: /aosp_15_r20/external/bazelbuild-rules_license/doc_build/BUILD (revision f578df4fd057ffe2023728444759535685631548)
1# Copyright 2022 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#    http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Generate the reference documentation.
15
16How to:
17   bazel build //doc_build:reference
18   cp bazel-bin/doc_build/reference.md docs/latest.md
19   git commit -m 'update docs' docs/latest.md
20"""
21
22load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
23load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
24load("@rules_python//python:defs.bzl", "py_library")
25load("//:version.bzl", "version")
26
27package(default_package_metadata = ["//:license", "//:package_info"])
28
29filegroup(
30    name = "standard_package",
31    srcs = [
32        "BUILD",
33    ] + glob([
34        "*.bzl",
35        "*.py",
36    ]),
37    visibility = ["//distro:__pkg__"],
38)
39
40exports_files(
41    glob([
42        "*.bzl",
43    ]),
44    visibility = [
45        "//distro:__pkg__",
46    ],
47)
48
49# pairs of rule name and the source file to get it from
50# Must put macro wrapped rules after their wrapper
51# buildifier: leave-alone, do not sort
52ORDER = [
53    ("license",         "//rules:license.bzl"),
54    ("_license",        "//rules:license.bzl"),
55    ("license_kind",    "//rules:license_kind.bzl"),
56    ("_license_kind",   "//rules:license_kind.bzl"),
57    ("package_info",    "//rules:package_info.bzl"),
58    ("_package_info",   "//rules:package_info.bzl"),
59    ("LicenseInfo",     "//rules:providers.bzl"),
60    ("LicenseKindInfo", "//rules:providers.bzl"),
61    ("PackageInfo",     "//rules:providers.bzl"),
62]
63
64genrule(
65    name = "reference",
66    srcs = ["%s.md" % rule for rule, _ in ORDER],
67    outs = ["reference.md"],
68    cmd = "$(location :merge) $(SRCS) >$@",
69    tools = [":merge"],
70)
71
72[
73    stardoc(
74        name = "%s_gen" % rule,
75        out = "%s.md" % rule,
76        input = src,
77        symbol_names = [
78            rule,
79        ],
80        deps = [":lib_of_everything"],
81    )
82    for rule, src in ORDER
83    if src
84]
85
86# gather all rules that should be documented
87bzl_library(
88    name = "lib_of_everything",
89    srcs = [
90        "//:version.bzl",
91        "//rules:standard_package",
92        "//rules/private:standard_package",
93        # "@bazel_skylib//lib:paths",
94    ],
95    visibility = ["//visibility:public"],
96)
97
98# This is experimental. We are waiting for stardoc to get the features which
99# are done in merge.
100py_binary(
101    name = "merge",
102    srcs = ["merge.py"],
103    python_version = "PY3",
104    srcs_version = "PY3",
105    visibility = ["//visibility:private"],
106)
107