2
0
Fork 0
mirror of https://github.com/bazel-contrib/rules_foreign_cc synced 2024-11-28 08:43:26 +00:00
rules_foreign_cc/docs/BUILD.bazel

137 lines
4.3 KiB
Python

load("@bazel_skylib//rules:build_test.bzl", "build_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 + [
"index.md",
"rules.md",
],
outs = ["generate_docs.sh"],
cmd = """\
export COMMIT="$$(cat bazel-out/stable-status.txt | grep STABLE_SCM_VERSION | cut -d' ' -f2)"
export SHORT_COMMIT="$$(cat bazel-out/stable-status.txt | grep STABLE_SCM_SHORT_VERSION | cut -d' ' -f2)"
export RELEASE="$$(cat bazel-out/stable-status.txt | grep STABLE_RELEASE | cut -d' ' -f2)"
cat << EOF > $@
#!/bin/bash
set -euo pipefail
short_commit="$${SHORT_COMMIT}"
commit="$${COMMIT}"
release="$${RELEASE}"
release_archive="$${RELEASE}"
# TODO: If a release is set, we assume it's set to a branch name.
# thus we defautl the archive value to a commit. This is likely
# only appropriate when publishing on the branch in specified
# and a smarter solution should be found to avoid unexpected behavior.
if [[ -n "\\$${RELEASE:-}" ]]; then
release="\\$${RELEASE}"
release_archive="\\$${commit}"
fi
mkdir -p \\$${BUILD_WORKSPACE_DIRECTORY}/src
cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:flatten_docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/src/flatten.md
cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:cmake_docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/src/cmake.md
cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:ninja_docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/src/ninja.md
cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:make_docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/src/make.md
cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:configure_make_docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/src/configure_make.md
cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:providers_docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/src/providers.md
# Non generated sourrces
cp \\$${BUILD_WORKSPACE_DIRECTORY}/$(rootpath rules.md) \\$${BUILD_WORKSPACE_DIRECTORY}/src/rules.md
cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(rootpath index.md) \
| sed "s/{short_commit}/\\$${short_commit}/" \
| sed "s/{commit}/\\$${commit}/" \
| sed "s/{release}/\\$${release}/" \
| sed "s/{release_archive}/\\$${release_archive}/" \
> \\$${BUILD_WORKSPACE_DIRECTORY}/src/index.md
EOF
""",
stamp = True,
)
sh_binary(
name = "generate_docs",
srcs = [":generate_docs_src"],
data = DOCS_TARGETS,
)