David Chen | 3f69751 | 2016-05-09 08:46:21 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright 2016 The Bazel Authors. All rights reserved. |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | set -eu |
| 17 | |
| 18 | readonly OUTPUT=${PWD}/$1 |
| 19 | shift |
| 20 | readonly JEKYLL_BASE=${PWD}/$1 |
| 21 | shift |
| 22 | readonly SKYLARK_RULE_DOCS=${PWD}/$1 |
| 23 | shift |
| 24 | readonly BE_ZIP=${PWD}/$1 |
| 25 | shift |
| 26 | readonly SL_ZIP=${PWD}/$1 |
Ulf Adams | 9e24ebd | 2016-06-23 09:24:57 +0000 | [diff] [blame] | 27 | shift |
| 28 | readonly CLR_HTML=${PWD}/$1 |
David Chen | 3f69751 | 2016-05-09 08:46:21 +0000 | [diff] [blame] | 29 | |
| 30 | # Create temporary directory that is removed when this script exits. |
Damien Martin-Guillerez | 7ac7a15 | 2016-05-25 13:30:38 +0000 | [diff] [blame] | 31 | readonly TMP=$(mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXX") |
David Chen | 3f69751 | 2016-05-09 08:46:21 +0000 | [diff] [blame] | 32 | readonly OUT_DIR="$TMP/out" |
| 33 | trap "rm -rf ${TMP}" EXIT |
| 34 | |
| 35 | function setup { |
| 36 | mkdir -p "$OUT_DIR" |
| 37 | cd "$OUT_DIR" |
| 38 | tar -xf "${JEKYLL_BASE}" |
| 39 | } |
| 40 | |
| 41 | # Unpack the Build Encyclopedia into docs/be |
| 42 | function unpack_build_encyclopedia { |
David Chen | 15c09dd | 2016-08-29 08:56:37 +0000 | [diff] [blame] | 43 | local be_dir="$OUT_DIR/versions/master/docs/be" |
David Chen | 3f69751 | 2016-05-09 08:46:21 +0000 | [diff] [blame] | 44 | mkdir -p "$be_dir" |
| 45 | unzip -qq "$BE_ZIP" -d "$be_dir" |
| 46 | mv "$be_dir/be-nav.html" "$OUT_DIR/_includes" |
David Chen | 15c09dd | 2016-08-29 08:56:37 +0000 | [diff] [blame] | 47 | |
| 48 | # Create redirects to each page in the Build Encyclopedia. |
| 49 | mkdir -p "$OUT_DIR/docs/be" |
| 50 | for f in $(find "$OUT_DIR/versions/master/docs/be" -name "*.html"); do |
| 51 | local filename=$(basename "$f") |
Klaus Aehlig | 8e138f9 | 2016-08-29 12:56:13 +0000 | [diff] [blame] | 52 | cat > "$OUT_DIR/docs/be/${filename}" <<EOF |
David Chen | 15c09dd | 2016-08-29 08:56:37 +0000 | [diff] [blame] | 53 | --- |
| 54 | layout: redirect |
| 55 | redirect: docs/be/${filename} |
| 56 | --- |
| 57 | EOF |
| 58 | done |
David Chen | 3f69751 | 2016-05-09 08:46:21 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | # Unpack the Skylark Library into docs/skylark/lib |
| 62 | function unpack_skylark_library { |
David Chen | 15c09dd | 2016-08-29 08:56:37 +0000 | [diff] [blame] | 63 | local sl_dir="$OUT_DIR/versions/master/docs/skylark/lib" |
David Chen | 3f69751 | 2016-05-09 08:46:21 +0000 | [diff] [blame] | 64 | mkdir -p "$sl_dir" |
| 65 | unzip -qq "$SL_ZIP" -d "$sl_dir" |
| 66 | mv "$sl_dir/skylark-nav.html" "$OUT_DIR/_includes" |
David Chen | 15c09dd | 2016-08-29 08:56:37 +0000 | [diff] [blame] | 67 | |
| 68 | # Create redirects to each page in the Skylark Library |
| 69 | mkdir -p "$OUT_DIR/docs/skylark/lib" |
| 70 | for f in $(find "$OUT_DIR/versions/master/docs/skylark/lib" -name "*.html"); do |
| 71 | local filename=$(basename "$f") |
Klaus Aehlig | 8e138f9 | 2016-08-29 12:56:13 +0000 | [diff] [blame] | 72 | cat > "$OUT_DIR/docs/skylark/lib/${filename}" <<EOF |
David Chen | 15c09dd | 2016-08-29 08:56:37 +0000 | [diff] [blame] | 73 | --- |
| 74 | layout: redirect |
| 75 | redirect: docs/skylark/lib/${filename} |
| 76 | --- |
| 77 | EOF |
| 78 | done |
David Chen | 3f69751 | 2016-05-09 08:46:21 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | function copy_skylark_rule_doc { |
| 82 | local rule_family=$1 |
| 83 | local rule_family_name=$2 |
David Chen | 15c09dd | 2016-08-29 08:56:37 +0000 | [diff] [blame] | 84 | local be_dir="$OUT_DIR/versions/master/docs/be" |
David Chen | 3f69751 | 2016-05-09 08:46:21 +0000 | [diff] [blame] | 85 | |
| 86 | ( cat <<EOF |
| 87 | --- |
| 88 | layout: documentation |
| 89 | title: ${rule_family_name} Rules |
| 90 | --- |
| 91 | EOF |
| 92 | cat "$TMP/skylark/$rule_family/README.md"; ) > "$be_dir/${rule_family}.md" |
| 93 | } |
| 94 | |
| 95 | function unpack_skylark_rule_docs { |
| 96 | local tmp_dir=$TMP/skylark |
| 97 | mkdir -p $tmp_dir |
| 98 | cd "$tmp_dir" |
| 99 | tar -xf "${SKYLARK_RULE_DOCS}" |
| 100 | copy_skylark_rule_doc docker "Docker" |
| 101 | copy_skylark_rule_doc pkg "Packaging" |
| 102 | } |
| 103 | |
| 104 | function process_doc { |
| 105 | local f=$1 |
| 106 | local tempf=$(mktemp -t bazel-doc-XXXXXX) |
| 107 | |
| 108 | chmod +w $f |
| 109 | cat "$f" | sed 's,\.md,.html,g;s,Blaze,Bazel,g;s,blaze,bazel,g' > "$tempf" |
| 110 | cat "$tempf" > "$f" |
| 111 | } |
| 112 | |
| 113 | function process_docs { |
David Chen | a4ddb85 | 2016-08-31 15:35:33 +0000 | [diff] [blame] | 114 | for f in $(find "$OUT_DIR/versions/master/docs" -name "*.html"); do |
David Chen | 3f69751 | 2016-05-09 08:46:21 +0000 | [diff] [blame] | 115 | process_doc $f |
| 116 | done |
David Chen | a4ddb85 | 2016-08-31 15:35:33 +0000 | [diff] [blame] | 117 | for f in $(find "$OUT_DIR/versions/master/docs" -name "*.md"); do |
| 118 | process_doc $f |
| 119 | done |
| 120 | for f in $(find "$OUT_DIR/designs" -name "*.md"); do |
David Chen | 3f69751 | 2016-05-09 08:46:21 +0000 | [diff] [blame] | 121 | process_doc $f |
| 122 | done |
| 123 | } |
| 124 | |
| 125 | function package_output { |
| 126 | cd "$OUT_DIR" |
| 127 | tar -hcf $OUTPUT $(find . -type f | sort) |
| 128 | } |
| 129 | |
| 130 | function main { |
| 131 | setup |
| 132 | unpack_build_encyclopedia |
| 133 | unpack_skylark_library |
| 134 | unpack_skylark_rule_docs |
David Chen | a4ddb85 | 2016-08-31 15:35:33 +0000 | [diff] [blame] | 135 | cp ${CLR_HTML} ${OUT_DIR}/versions/master/docs |
David Chen | 3f69751 | 2016-05-09 08:46:21 +0000 | [diff] [blame] | 136 | process_docs |
| 137 | package_output |
| 138 | } |
| 139 | main |