2
0
Fork 0
mirror of https://github.com/bazel-contrib/rules_foreign_cc synced 2024-12-03 02:52:58 +00:00
rules_foreign_cc/docs/BUILD.bazel
2021-06-20 15:25:43 -07:00

125 lines
3.5 KiB
Python

load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@bazel_skylib//rules:diff_test.bzl", "diff_test")
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
genrule(
name = "flatten_header_vm",
srcs = [
"gen_header.sh",
"docs.bzl",
],
outs = ["flatten_header.vm"],
cmd = "$(location gen_header.sh) $(location docs.bzl) $@",
output_to_bindir = True,
)
# Note that the stardoc `out` files are prefixed with `stardoc_` so the
# `diff_test` targets which ensure documentation is up to date can access the
# committed markdown files instead ouf the `out` targets from the stardoc rules
stardoc(
name = "flatten_docs",
out = "stardoc_flatten.md",
header_template = ":flatten_header_vm",
input = "docs.bzl",
deps = ["@rules_foreign_cc//:bzl_srcs"],
)
stardoc(
name = "cmake_docs",
out = "stardoc_cmake.md",
header_template = "common_header.vm",
input = "@rules_foreign_cc//foreign_cc:cmake.bzl",
deps = ["@rules_foreign_cc//:bzl_srcs"],
)
stardoc(
name = "make_docs",
out = "stardoc_make.md",
header_template = "common_header.vm",
input = "@rules_foreign_cc//foreign_cc:make.bzl",
deps = ["@rules_foreign_cc//:bzl_srcs"],
)
stardoc(
name = "ninja_docs",
out = "stardoc_ninja.md",
header_template = "common_header.vm",
input = "@rules_foreign_cc//foreign_cc:ninja.bzl",
deps = ["@rules_foreign_cc//:bzl_srcs"],
)
stardoc(
name = "configure_make_docs",
out = "stardoc_configure_make.md",
header_template = "common_header.vm",
input = "@rules_foreign_cc//foreign_cc:configure.bzl",
deps = ["@rules_foreign_cc//:bzl_srcs"],
)
stardoc(
name = "providers_docs",
out = "stardoc_providers.md",
header_template = "common_header.vm",
input = "@rules_foreign_cc//foreign_cc:providers.bzl",
deps = ["@rules_foreign_cc//:bzl_srcs"],
)
DOCS_TARGETS = [
":flatten_docs",
":cmake_docs",
":ninja_docs",
":make_docs",
":configure_make_docs",
":providers_docs",
]
build_test(
name = "docs_build_test",
targets = DOCS_TARGETS,
visibility = ["//visibility:public"],
)
# Run this target to upate/generate docs
genrule(
name = "generate_docs_src",
srcs = DOCS_TARGETS,
outs = ["generate_docs.sh"],
cmd = """cat << EOF > $@
#!/bin/bash
set -euo pipefail
cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:flatten_docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/flatten.md
cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:cmake_docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/cmake.md
cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:ninja_docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/ninja.md
cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:make_docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/make.md
cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:configure_make_docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/configure_make.md
cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:providers_docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/providers.md
EOF
""",
)
# When this test fails, run
# (cd docs; bazel run :generate_docs)
[
diff_test(
name = "{}_test".format(doc),
failure_message = "Please run 'cd docs && bazel run :generate_docs' to update documentation.",
file1 = ":{}_docs".format(doc),
file2 = "{}.md".format(doc),
)
for doc in [
"flatten",
"cmake",
"ninja",
"make",
"configure_make",
"providers",
]
]
sh_binary(
name = "generate_docs",
srcs = [":generate_docs_src"],
data = DOCS_TARGETS,
)