Skip to content

Commit

Permalink
Docs are now auto-generated using mdbook (#692)
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Jun 22, 2021
1 parent 4a3b072 commit a7f1c9e
Show file tree
Hide file tree
Showing 31 changed files with 362 additions and 948 deletions.
2 changes: 1 addition & 1 deletion .bazelci/config.yaml
Expand Up @@ -165,7 +165,7 @@ tasks:
name: Docs
platform: ubuntu2004
working_directory: docs
test_targets:
build_targets:
- //...
min_supported_version:
name: "Minimum Supported Version"
Expand Down
42 changes: 42 additions & 0 deletions .github/docs-0.1.0.patch
@@ -0,0 +1,42 @@
diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel
index a5a37ac..e381ce8 100644
--- a/docs/BUILD.bazel
+++ b/docs/BUILD.bazel
@@ -35,7 +35,7 @@ genrule(
cmd = """cat << EOF > $@
#!/bin/bash
set -e
-cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/README.md
+cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/src/index.md
""",
)

diff --git a/docs/book.toml b/docs/book.toml
new file mode 100644
index 0000000..5096728
--- /dev/null
+++ b/docs/book.toml
@@ -0,0 +1,5 @@
+[book]
+title = "Rules ForeignCc"
+
+[output.html]
+git-repository-url = "https://github.com/bazelbuild/rules_foreign_cc"
diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md
new file mode 100644
index 0000000..69fbd4d
--- /dev/null
+++ b/docs/src/SUMMARY.md
@@ -0,0 +1,3 @@
+# SUMMARY
+
+- [Rules ForeignCc](index.md)
diff --git a/version.bzl b/version.bzl
new file mode 100644
index 0000000..98bb722
--- /dev/null
+++ b/version.bzl
@@ -0,0 +1,3 @@
+"""A module represeting the version of rules_foreign_cc"""
+
+VERSION = "0.1.0"
42 changes: 42 additions & 0 deletions .github/docs-0.2.0.patch
@@ -0,0 +1,42 @@
diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel
index a5a37ac..091e679 100644
--- a/docs/BUILD.bazel
+++ b/docs/BUILD.bazel
@@ -35,7 +35,7 @@ genrule(
cmd = """cat << EOF > $@
#!/bin/bash
set -e
-cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/README.md
+cat \\$${BUILD_WORKSPACE_DIRECTORY}/$(location //:docs) > \\$${BUILD_WORKSPACE_DIRECTORY}/src/index.md
""",
)

diff --git a/docs/book.toml b/docs/book.toml
new file mode 100644
index 0000000..5096728
--- /dev/null
+++ b/docs/book.toml
@@ -0,0 +1,5 @@
+[book]
+title = "Rules ForeignCc"
+
+[output.html]
+git-repository-url = "https://github.com/bazelbuild/rules_foreign_cc"
diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md
new file mode 100644
index 0000000..69fbd4d
--- /dev/null
+++ b/docs/src/SUMMARY.md
@@ -0,0 +1,3 @@
+# SUMMARY
+
+- [Rules ForeignCc](index.md)
diff --git a/version.bzl b/version.bzl
new file mode 100644
index 0000000..98bb722
--- /dev/null
+++ b/version.bzl
@@ -0,0 +1,3 @@
+"""A module represeting the version of rules_foreign_cc"""
+
+VERSION = "0.2.0"
82 changes: 82 additions & 0 deletions .github/docs-0.3.0.patch
@@ -0,0 +1,82 @@
diff --git a/docs/BUILD.bazel b/docs/BUILD.bazel
index 461df15..efa4c26 100644
--- a/docs/BUILD.bazel
+++ b/docs/BUILD.bazel
@@ -68,16 +68,17 @@ build_test(

genrule(
name = "generate_docs_src",
- srcs = DOCS_TARGETS,
+ srcs = DOCS_TARGETS + ["index.md"],
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 //: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
+cp \\$${BUILD_WORKSPACE_DIRECTORY}/$(rootpath index.md) \\$${BUILD_WORKSPACE_DIRECTORY}/src/index.md
EOF
""",
)
diff --git a/docs/book.toml b/docs/book.toml
new file mode 100644
index 0000000..5096728
--- /dev/null
+++ b/docs/book.toml
@@ -0,0 +1,5 @@
+[book]
+title = "Rules ForeignCc"
+
+[output.html]
+git-repository-url = "https://github.com/bazelbuild/rules_foreign_cc"
diff --git a/docs/index.md b/docs/index.md
index 3a91e41..14c8e3b 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -21,9 +21,12 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "rules_foreign_cc",
- sha256 = "d54742ffbdc6924f222d2179f0e10e911c5c659c4ae74158e9fe827aad862ac6",
- strip_prefix = "rules_foreign_cc-0.2.0",
- url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.2.0.tar.gz",
+ # TODO: Get the latest sha256 value from the latest release on the releases page
+ # https://github.com/bazelbuild/rules_foreign_cc/releases
+ #
+ # sha256 = "...",
+ strip_prefix = "rules_foreign_cc-0.3.0",
+ url = "https://github.com/bazelbuild/rules_foreign_cc/archive/0.3.0.tar.gz",
)

load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md
new file mode 100644
index 0000000..9e77270
--- /dev/null
+++ b/docs/src/SUMMARY.md
@@ -0,0 +1,8 @@
+# SUMMARY
+
+- [Rules ForeignCc](index.md)
+ - [cmake](cmake.md)
+ - [configure_make](configure_make.md)
+ - [make](make.md)
+ - [ninja](ninja.md)
+ - [Full API](flatten.md)
diff --git a/version.bzl b/version.bzl
new file mode 100644
index 0000000..98bb722
--- /dev/null
+++ b/version.bzl
@@ -0,0 +1,3 @@
+"""A module represeting the version of rules_foreign_cc"""
+
+VERSION = "0.3.0"
91 changes: 91 additions & 0 deletions .github/workflows/pages.yaml
@@ -0,0 +1,91 @@
name: Deploy mdBook
on:
push:
branches:
- main
jobs:
pages:
runs-on: ubuntu-latest
strategy:
matrix:
# Create a job for each target triple
include:
- ref: main
- ref: "0.3.0"
- ref: "0.2.0"
- ref: "0.1.0"
steps:
- uses: actions/checkout@v2
if: ${{ matrix.ref == 'main' }}
- uses: actions/checkout@v2
with:
ref: ${{ matrix.ref }}
if: ${{ matrix.ref != 'main' }}
- name: Pin the release to main
run: echo "RELEASE=main" >> $GITHUB_ENV
if: ${{ matrix.ref == 'main' }}
- name: Patch older branches
run: |
mkdir -p ${{ github.workspace }}/.github
curl https://raw.githubusercontent.com/bazelbuild/rules_foreign_cc/main/.github/docs-${{ matrix.ref }}.patch > ${{ github.workspace }}/.github/docs-${{ matrix.ref }}.patch
git apply ${{ github.workspace }}/.github/docs-${{ matrix.ref }}.patch
if: ${{ matrix.ref == '0.3.0' || matrix.ref == '0.2.0' || matrix.ref == '0.1.0' }}
- name: Install bazelisk
run: |
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/v1.9.0/bazelisk-linux-amd64"
mkdir -p "${{ github.workspace }}/bin/"
mv bazelisk-linux-amd64 "${{ github.workspace }}/bin/bazel"
chmod +x "${{ github.workspace }}/bin/bazel"
- name: Generate docs
run: |
"${{ github.workspace }}/bin/bazel" run //:generate_docs
"${{ github.workspace }}/bin/bazel" clean
working-directory: ${{ github.workspace }}/docs
- name: Install mdbook
run: |
curl -LO "https://github.com/rust-lang/mdBook/releases/download/v0.4.10/mdbook-v0.4.10-x86_64-unknown-linux-gnu.tar.gz"
mkdir -p "${{ github.workspace }}/bin/"
tar -xvf mdbook-v0.4.10-x86_64-unknown-linux-gnu.tar.gz
mv mdbook "${{ github.workspace }}/bin/mdbook"
chmod +x "${{ github.workspace }}/bin/mdbook"
- name: mdbook build
run: ${{ github.workspace }}/bin/mdbook build
working-directory: ${{ github.workspace }}/docs
- name: Save the newly built book
uses: actions/upload-artifact@v2
with:
name: "${{ matrix.ref }}"
path: ${{ github.workspace }}/docs/book
if-no-files-found: error
- name: Build root
run: ${{ github.workspace }}/bin/mdbook build
if: ${{ matrix.ref == 'main' }}
working-directory: ${{ github.workspace }}/docs/root
- name: Save the newly built book
uses: actions/upload-artifact@v2
with:
name: "${{ matrix.ref }}-root"
path: ${{ github.workspace }}/docs/root/book
if-no-files-found: error
if: ${{ matrix.ref == 'main' }}
publish:
needs: pages
runs-on: ubuntu-latest
steps:
- name: Fetch artifacts (first root then others so the ordering is correct)
uses: actions/download-artifact@v2
with:
name: main-root
path: ${{ github.workspace }}/docs/book
- name: Fetch artifacts (first root then others so the ordering is correct)
uses: actions/download-artifact@v2
with:
path: ${{ github.workspace }}/docs/pages
- name: Install pages
run: mv ${{ github.workspace }}/docs/pages/* ${{ github.workspace }}/docs/book/
- name: publish
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: docs
publish_dir: ./docs/book
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -9,7 +9,7 @@ This is **not an officially supported Google product**

## Documentation

Documentation for all rules and providers are available [here](./docs/index.md).
Documentation for all rules and providers are available at: https://bazelbuild.github.io/rules_foreign_cc/

## Bazel versions compatibility

Expand Down
3 changes: 3 additions & 0 deletions docs/.bazelrc
@@ -0,0 +1,3 @@
# Bazel configuration flags for rules_foregin_cc_docs

build --workspace_status_command=tools/workspace_status.sh
2 changes: 2 additions & 0 deletions docs/.gitignore
@@ -0,0 +1,2 @@
src
book
58 changes: 30 additions & 28 deletions docs/BUILD.bazel
@@ -1,5 +1,4 @@
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(
Expand Down Expand Up @@ -83,40 +82,43 @@ build_test(
# Run this target to upate/generate docs
genrule(
name = "generate_docs_src",
srcs = DOCS_TARGETS,
srcs = DOCS_TARGETS + [
"index.md",
"rules.md",
],
outs = ["generate_docs.sh"],
cmd = """cat << EOF > $@
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
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
short_commit="$${SHORT_COMMIT}"
commit="$${COMMIT}"
release="$${RELEASE}"
if [[ -n "\\$${RELEASE}" ]]; then
release="\\$${RELEASE}"
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}/" \
> \\$${BUILD_WORKSPACE_DIRECTORY}/src/index.md
EOF
""",
stamp = True,
)

# 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"],
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Expand Up @@ -2,7 +2,7 @@

# Rules ForeignCc Docs

Up to date documentation can be found [here](./index.md)
Up to date documentation can be found at: https://bazelbuild.github.io/rules_foreign_cc/

## Legacy documentation

Expand Down
17 changes: 0 additions & 17 deletions docs/WORKSPACE.bazel
Expand Up @@ -7,23 +7,6 @@ local_repository(

load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")

# `bazel_skylib` is explicitly loaded so a patch can be applied to allow for unique error
# messages to be added to `diff_test` targets. This can be removed after an upstream PR is
# merged and the rev updated in `rules_foreign_cc`: https://github.com/bazelbuild/bazel-skylib/pull/307

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "bazel_skylib",
patch_args = ["-p1"],
patches = ["//:bazel_skylib-diff_test.patch"],
sha256 = "1c531376ac7e5a180e0237938a2536de0c54d93f5c278634818e0efc952dd56c",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.3/bazel-skylib-1.0.3.tar.gz",
],
)

rules_foreign_cc_dependencies()

load("//:stardoc_repository.bzl", "stardoc_repository")
Expand Down
1 change: 0 additions & 1 deletion docs/_config.yml

This file was deleted.

0 comments on commit a7f1c9e

Please sign in to comment.