blob: 7e4b84bf71132e1af63a1f7fb92bd8c487b0eb96 [file] [log] [blame]
aiuto002daac2021-12-07 01:15:58 -05001# Copyright 2021 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.
aiutoa8638d62022-02-16 10:39:01 -050014"""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"""
aiuto002daac2021-12-07 01:15:58 -050021
22load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
23load("@bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
aiutoa8638d62022-02-16 10:39:01 -050024load("@rules_python//python:defs.bzl", "py_library")
aiuto002daac2021-12-07 01:15:58 -050025load("//:version.bzl", "version")
26
aiuto3c0b3642022-02-16 11:01:43 -050027package(default_applicable_licenses = ["//:license"])
28
aiutoa8638d62022-02-16 10:39:01 -050029filegroup(
30 name = "standard_package",
31 srcs = [
32 "BUILD",
33 ] + glob([
34 "*.bzl",
35 "*.py",
36 ]),
37 visibility = ["//distro:__pkg__"],
38)
aiuto002daac2021-12-07 01:15:58 -050039
aiutoa8638d62022-02-16 10:39:01 -050040exports_files(
41 glob([
42 "*.bzl",
43 ]),
44 visibility = [
45 "//distro:__pkg__",
46 "//doc_build:__pkg__",
47 ],
48)
aiuto002daac2021-12-07 01:15:58 -050049
50# pairs of rule name and the source file to get it from
aiuto74999382022-02-03 21:38:56 -050051# buildifier: leave-alone, do not sort
aiuto002daac2021-12-07 01:15:58 -050052ORDER = [
aiuto002daac2021-12-07 01:15:58 -050053 ("toc", None),
54 ("common", None),
55 ("pkg_deb", "//pkg/private/deb:deb.bzl"),
56 ("pkg_deb_impl", "//pkg/private/deb:deb.bzl"),
57 ("pkg_rpm", "//pkg:rpm_pfg.bzl"),
aiutocce90a02022-02-08 19:23:56 -050058 ("pkg_tar", "//pkg/private/tar:tar.bzl"),
59 ("pkg_tar_impl", "//pkg/private/tar:tar.bzl"),
aiuto002daac2021-12-07 01:15:58 -050060 ("pkg_zip", "//pkg/private/zip:zip.bzl"),
61 ("pkg_zip_impl", "//pkg/private/zip:zip.bzl"),
62 ("mappings", None),
63 ("legacy_pkg_rpm", None),
64]
65
66genrule(
67 name = "reference",
68 srcs = ["%s.md" % rule for rule, _ in ORDER],
69 outs = ["reference.md"],
aiutoa8638d62022-02-16 10:39:01 -050070 cmd = "$(location :merge) $(SRCS) >$@",
aiutof117c632023-03-15 10:45:49 -040071 tools = [":merge"],
aiuto002daac2021-12-07 01:15:58 -050072)
73
74[
75 stardoc(
76 name = "%s_gen" % rule,
77 out = "%s.md" % rule,
78 input = src,
79 symbol_names = [
80 rule,
81 ],
82 deps = [":rules_pkg_lib"],
83 )
84 for rule, src in ORDER
85 if src
86]
87
88genrule(
89 name = "toc",
90 srcs = ["toc.md.tpl"],
91 outs = ["toc.md"],
92 cmd = "sed -e 's/{VERSION}/%s/' $(SRCS) >$@" % version,
93)
94
95# Generate separately or there will be a conflict with the other pkg_rpm.
96stardoc(
97 name = "docs_legacy_rpm",
98 out = "legacy_pkg_rpm.md",
99 input = "//pkg/legacy:rpm.bzl",
100 deps = [":rules_pkg_lib"],
101)
102
103# Mappings has a lot of pure rules, so it is mostly in a good order.
104stardoc(
105 name = "mappings",
106 out = "mappings.md",
107 input = "//pkg:mappings.bzl",
108 deps = [
109 ":rules_pkg_lib",
110 ],
111)
112
113# gather all rules that should be documented
114bzl_library(
115 name = "rules_pkg_lib",
116 srcs = [
117 "//:version.bzl",
aiuto76f56512022-04-07 12:12:14 -0400118 "//pkg:bzl_srcs",
aiuto002daac2021-12-07 01:15:58 -0500119 "@bazel_skylib//lib:paths",
120 ],
aiuto76f56512022-04-07 12:12:14 -0400121 visibility = ["//visibility:public"],
aiuto002daac2021-12-07 01:15:58 -0500122)
aiutoa8638d62022-02-16 10:39:01 -0500123
124py_binary(
125 name = "merge",
126 srcs = ["merge.py"],
127 python_version = "PY3",
128 srcs_version = "PY3",
129 visibility = ["//visibility:private"],
130)