1#!/bin/bash 2# 3# NOTE: This is meant to be run using `bazel run`. Directly running it 4# won't work. 5# 6# Build docs for Sphinx. This is usually run by the readthedocs build process. 7# 8# It can also be run locally during development using Bazel, in which case, 9# it will run Sphinx and start a local webserver to server HTML. 10# 11# To make the local devx nicer, run it using ibazel, and it will automatically 12# update docs: 13# ibazel run //docs:run_sphinx_build 14 15set -e 16 17if [[ -z "$BUILD_WORKSPACE_DIRECTORY" ]]; then 18 echo "ERROR: Must be run using bazel run" 19 exit 1 20fi 21 22sphinx=$(pwd)/$1 23shift 24 25crossrefs=$1 26shift 27 28dest_dir="$BUILD_WORKSPACE_DIRECTORY/docs/source/api" 29mkdir -p "$dest_dir" 30for path in "$@"; do 31 dest="$dest_dir/$(basename $path)" 32 if [[ -e $dest ]]; then 33 chmod +w $dest 34 fi 35 cat $path $crossrefs > $dest 36done 37 38if [[ -z "$READTHEDOCS" ]]; then 39 sourcedir="$BUILD_WORKSPACE_DIRECTORY/docs/source" 40 outdir="$BUILD_WORKSPACE_DIRECTORY/docs/_build" 41 # This avoids stale files or since-deleted files from being processed. 42 rm -fr "$outdir" 43 "$sphinx" -T -b html "$sourcedir" "$outdir" 44 45 echo "HTML built, to view, run:" 46 echo "python3 -m http.server --directory $outdir" 47 python3 -m http.server --directory "$outdir" 48fi 49