xref: /aosp_15_r20/external/bazelbuild-rules_python/sphinxdocs/tests/sphinx_stardoc/BUILD.bazel (revision 60517a1edbc8ecf509223e9af94a7adec7d736b8)
1load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
2load("//python:py_test.bzl", "py_test")
3load("//python/private:util.bzl", "IS_BAZEL_7_OR_HIGHER")  # buildifier: disable=bzl-visibility
4load("//sphinxdocs:sphinx.bzl", "sphinx_build_binary", "sphinx_docs")
5load("//sphinxdocs:sphinx_stardoc.bzl", "sphinx_stardoc", "sphinx_stardocs")
6
7# We only build for Linux and Mac because:
8# 1. The actual doc process only runs on Linux
9# 2. Mac is a common development platform, and is close enough to Linux
10#    it's feasible to make work.
11# Making CI happy under Windows is too much of a headache, though, so we don't
12# bother with that.
13_TARGET_COMPATIBLE_WITH = select({
14    "@platforms//os:linux": [],
15    "@platforms//os:macos": [],
16    "//conditions:default": ["@platforms//:incompatible"],
17}) if IS_BAZEL_7_OR_HIGHER else ["@platforms//:incompatible"]
18
19sphinx_docs(
20    name = "docs",
21    srcs = glob(
22        include = [
23            "*.md",
24        ],
25    ),
26    config = "conf.py",
27    formats = [
28        "html",
29    ],
30    renamed_srcs = {
31        "//sphinxdocs/inventories:bazel_inventory": "bazel_inventory.inv",
32    },
33    sphinx = ":sphinx-build",
34    strip_prefix = package_name() + "/",
35    target_compatible_with = _TARGET_COMPATIBLE_WITH,
36    deps = [
37        ":bzl_function",
38        ":bzl_providers",
39        ":simple_bzl_docs",
40    ],
41)
42
43sphinx_stardocs(
44    name = "simple_bzl_docs",
45    srcs = [":bzl_rule_bzl"],
46    target_compatible_with = _TARGET_COMPATIBLE_WITH,
47)
48
49sphinx_stardoc(
50    name = "bzl_function",
51    src = ":bzl_function.bzl",
52    target_compatible_with = _TARGET_COMPATIBLE_WITH,
53    deps = [":func_and_providers_bzl"],
54)
55
56sphinx_stardoc(
57    name = "bzl_providers",
58    src = ":bzl_providers.bzl",
59    prefix = "addprefix_",
60    target_compatible_with = _TARGET_COMPATIBLE_WITH,
61    deps = [":func_and_providers_bzl"],
62)
63
64# A bzl_library with multiple sources
65bzl_library(
66    name = "func_and_providers_bzl",
67    srcs = [
68        "bzl_function.bzl",
69        "bzl_providers.bzl",
70    ],
71)
72
73bzl_library(
74    name = "bzl_rule_bzl",
75    srcs = ["bzl_rule.bzl"],
76    deps = [":func_and_providers_bzl"],
77)
78
79sphinx_build_binary(
80    name = "sphinx-build",
81    tags = ["manual"],  # Only needed as part of sphinx doc building
82    deps = [
83        "//sphinxdocs/src/sphinx_bzl",
84        "@dev_pip//myst_parser",
85        "@dev_pip//sphinx",
86        "@dev_pip//typing_extensions",  # Needed by sphinx_stardoc
87    ],
88)
89
90py_test(
91    name = "sphinx_output_test",
92    srcs = ["sphinx_output_test.py"],
93    data = [":docs"],
94    deps = ["@dev_pip//absl_py"],
95)
96