Ian Hickson | 449f4a6 | 2019-11-27 15:04:02 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | # Copyright 2014 The Flutter Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
Seth Ladd | 1ac08b2 | 2016-07-12 12:53:47 -0700 | [diff] [blame] | 6 | set -e |
Devon Carew | cd8f65d | 2016-05-02 14:33:39 -0700 | [diff] [blame] | 7 | |
Greg Spencer | 77645df | 2018-08-06 17:33:31 -0700 | [diff] [blame] | 8 | function script_location() { |
| 9 | local script_location="${BASH_SOURCE[0]}" |
| 10 | # Resolve symlinks |
| 11 | while [[ -h "$script_location" ]]; do |
| 12 | DIR="$(cd -P "$( dirname "$script_location")" >/dev/null && pwd)" |
| 13 | script_location="$(readlink "$script_location")" |
| 14 | [[ "$script_location" != /* ]] && script_location="$DIR/$script_location" |
| 15 | done |
| 16 | echo "$(cd -P "$(dirname "$script_location")" >/dev/null && pwd)" |
| 17 | } |
| 18 | |
Todd Volkert | 8e0eee9 | 2020-07-26 23:38:01 -0700 | [diff] [blame] | 19 | function generate_docs() { |
| 20 | # Install and activate dartdoc. |
Michael Goderbauer | 923eb76 | 2020-09-22 12:57:13 -0700 | [diff] [blame] | 21 | # NOTE: When updating to a new dartdoc version, please also update |
| 22 | # `dartdoc_options.yaml` to include newly introduced error and warning types. |
Janice Collins | d1f78b4 | 2020-12-08 16:13:04 -0800 | [diff] [blame] | 23 | "$PUB" global activate dartdoc 0.38.0 |
Todd Volkert | 8e0eee9 | 2020-07-26 23:38:01 -0700 | [diff] [blame] | 24 | |
| 25 | # This script generates a unified doc set, and creates |
| 26 | # a custom index.html, placing everything into dev/docs/doc. |
| 27 | (cd "$FLUTTER_ROOT/dev/tools" && "$FLUTTER" pub get) |
| 28 | (cd "$FLUTTER_ROOT/dev/tools" && "$PUB" get) |
Michael Goderbauer | 3e867f7 | 2020-08-18 19:11:05 -0700 | [diff] [blame] | 29 | (cd "$FLUTTER_ROOT" && "$DART" --disable-dart-dev --enable-asserts "$FLUTTER_ROOT/dev/tools/dartdoc.dart") |
| 30 | (cd "$FLUTTER_ROOT" && "$DART" --disable-dart-dev --enable-asserts "$FLUTTER_ROOT/dev/tools/java_and_objc_doc.dart") |
Todd Volkert | 8e0eee9 | 2020-07-26 23:38:01 -0700 | [diff] [blame] | 31 | } |
| 32 | |
Greg Spencer | f20adcc | 2018-11-15 15:05:57 -0800 | [diff] [blame] | 33 | # Zip up the docs so people can download them for offline usage. |
| 34 | function create_offline_zip() { |
| 35 | # Must be run from "$FLUTTER_ROOT/dev/docs" |
Todd Volkert | 81bf39e | 2020-07-24 22:38:17 -0700 | [diff] [blame] | 36 | echo "$(date): Zipping Flutter offline docs archive." |
Greg Spencer | f20adcc | 2018-11-15 15:05:57 -0800 | [diff] [blame] | 37 | rm -rf flutter.docs.zip doc/offline |
| 38 | (cd ./doc; zip -r -9 -q ../flutter.docs.zip .) |
| 39 | } |
| 40 | |
| 41 | # Generate the docset for Flutter docs for use with Dash, Zeal, and Velocity. |
| 42 | function create_docset() { |
| 43 | # Must be run from "$FLUTTER_ROOT/dev/docs" |
| 44 | # Must have dashing installed: go get -u github.com/technosophos/dashing |
Greg Spencer | 02dbb08 | 2019-01-25 08:48:52 -0800 | [diff] [blame] | 45 | # Dashing produces a LOT of log output (~30MB), so we redirect it, and just |
| 46 | # show the end of it if there was a problem. |
Todd Volkert | 81bf39e | 2020-07-24 22:38:17 -0700 | [diff] [blame] | 47 | echo "$(date): Building Flutter docset." |
Greg Spencer | f20adcc | 2018-11-15 15:05:57 -0800 | [diff] [blame] | 48 | rm -rf flutter.docset |
Christopher Fujino | e3ad034 | 2020-07-01 19:41:41 -0700 | [diff] [blame] | 49 | # If dashing gets stuck, Cirrus will time out the build after an hour, and we |
Todd Volkert | 35e7005 | 2020-07-25 09:44:17 -0700 | [diff] [blame] | 50 | # never get to see the logs. Thus, we run it in the background and tail the logs |
| 51 | # while we wait for it to complete. |
Todd Volkert | 39fa002 | 2020-07-27 21:11:43 -0700 | [diff] [blame] | 52 | dashing_log=/tmp/dashing.log |
| 53 | dashing build --source ./doc --config ./dashing.json > $dashing_log 2>&1 & |
Todd Volkert | 35e7005 | 2020-07-25 09:44:17 -0700 | [diff] [blame] | 54 | dashing_pid=$! |
Todd Volkert | 35e7005 | 2020-07-25 09:44:17 -0700 | [diff] [blame] | 55 | wait $dashing_pid && \ |
Greg Spencer | 625a37b | 2018-12-11 09:53:33 -0800 | [diff] [blame] | 56 | cp ./doc/flutter/static-assets/favicon.png ./flutter.docset/icon.png && \ |
Michael Goderbauer | 3e867f7 | 2020-08-18 19:11:05 -0700 | [diff] [blame] | 57 | "$DART" --disable-dart-dev --enable-asserts ./dashing_postprocess.dart && \ |
Todd Volkert | 39fa002 | 2020-07-27 21:11:43 -0700 | [diff] [blame] | 58 | tar cf flutter.docset.tar.gz --use-compress-program="gzip --best" flutter.docset |
| 59 | if [[ $? -ne 0 ]]; then |
| 60 | >&2 echo "Dashing docset generation failed" |
| 61 | tail -200 $dashing_log |
| 62 | exit 1 |
| 63 | fi |
Greg Spencer | f20adcc | 2018-11-15 15:05:57 -0800 | [diff] [blame] | 64 | } |
| 65 | |
Todd Volkert | 8e0eee9 | 2020-07-26 23:38:01 -0700 | [diff] [blame] | 66 | function deploy_docs() { |
Todd Volkert | 8e0eee9 | 2020-07-26 23:38:01 -0700 | [diff] [blame] | 67 | # Ensure google webmaster tools can verify our site. |
| 68 | cp "$FLUTTER_ROOT/dev/docs/google2ed1af765c529f57.html" "$FLUTTER_ROOT/dev/docs/doc" |
| 69 | |
godofredoc | f8f6963 | 2020-10-13 17:06:49 -0700 | [diff] [blame] | 70 | case "$LUCI_BRANCH" in |
Todd Volkert | 8e0eee9 | 2020-07-26 23:38:01 -0700 | [diff] [blame] | 71 | master) |
godofredoc | f8f6963 | 2020-10-13 17:06:49 -0700 | [diff] [blame] | 72 | echo "$(date): Updating $LUCI_BRANCH docs: https://master-api.flutter.dev/" |
Todd Volkert | 8e0eee9 | 2020-07-26 23:38:01 -0700 | [diff] [blame] | 73 | # Disable search indexing on the master staging site so searches get only |
| 74 | # the stable site. |
| 75 | echo -e "User-agent: *\nDisallow: /" > "$FLUTTER_ROOT/dev/docs/doc/robots.txt" |
Todd Volkert | 8e0eee9 | 2020-07-26 23:38:01 -0700 | [diff] [blame] | 76 | ;; |
| 77 | stable) |
godofredoc | f8f6963 | 2020-10-13 17:06:49 -0700 | [diff] [blame] | 78 | echo "$(date): Updating $LUCI_BRANCH docs: https://api.flutter.dev/" |
Todd Volkert | 8e0eee9 | 2020-07-26 23:38:01 -0700 | [diff] [blame] | 79 | # Enable search indexing on the master staging site so searches get only |
| 80 | # the stable site. |
| 81 | echo -e "# All robots welcome!" > "$FLUTTER_ROOT/dev/docs/doc/robots.txt" |
Todd Volkert | 8e0eee9 | 2020-07-26 23:38:01 -0700 | [diff] [blame] | 82 | ;; |
| 83 | *) |
godofredoc | f8f6963 | 2020-10-13 17:06:49 -0700 | [diff] [blame] | 84 | >&2 echo "Docs deployment cannot be run on the $LUCI_BRANCH branch." |
Christopher Fujino | d6e308c | 2020-08-19 18:16:05 -0700 | [diff] [blame] | 85 | exit 0 |
Todd Volkert | 8e0eee9 | 2020-07-26 23:38:01 -0700 | [diff] [blame] | 86 | esac |
| 87 | } |
| 88 | |
Greg Spencer | f20adcc | 2018-11-15 15:05:57 -0800 | [diff] [blame] | 89 | # Move the offline archives into place, after all the processing of the doc |
| 90 | # directory is done. This avoids the tools recursively processing the archives |
| 91 | # as part of their process. |
| 92 | function move_offline_into_place() { |
| 93 | # Must be run from "$FLUTTER_ROOT/dev/docs" |
Todd Volkert | 81bf39e | 2020-07-24 22:38:17 -0700 | [diff] [blame] | 94 | echo "$(date): Moving offline data into place." |
Greg Spencer | f20adcc | 2018-11-15 15:05:57 -0800 | [diff] [blame] | 95 | mkdir -p doc/offline |
| 96 | mv flutter.docs.zip doc/offline/flutter.docs.zip |
| 97 | du -sh doc/offline/flutter.docs.zip |
godofredoc | f8f6963 | 2020-10-13 17:06:49 -0700 | [diff] [blame] | 98 | if [[ "$LUCI_BRANCH" == "stable" ]]; then |
| 99 | echo -e "<entry>\n <version>${FLUTTER_VERSION}</version>\n <url>https://api.flutter.dev/offline/flutter.docset.tar.gz</url>\n</entry>" > doc/offline/flutter.xml |
| 100 | else |
| 101 | echo -e "<entry>\n <version>${FLUTTER_VERSION}</version>\n <url>https://master-api.flutter.dev/offline/flutter.docset.tar.gz</url>\n</entry>" > doc/offline/flutter.xml |
| 102 | fi |
| 103 | mv flutter.docset.tar.gz doc/offline/flutter.docset.tar.gz |
| 104 | du -sh doc/offline/flutter.docset.tar.gz |
Greg Spencer | f20adcc | 2018-11-15 15:05:57 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Greg Spencer | 77645df | 2018-08-06 17:33:31 -0700 | [diff] [blame] | 107 | # So that users can run this script from anywhere and it will work as expected. |
| 108 | SCRIPT_LOCATION="$(script_location)" |
| 109 | # Sets the Flutter root to be "$(script_location)/../..": This script assumes |
| 110 | # that it resides two directory levels down from the root, so if that changes, |
| 111 | # then this line will need to as well. |
| 112 | FLUTTER_ROOT="$(dirname "$(dirname "$SCRIPT_LOCATION")")" |
| 113 | |
Todd Volkert | 8c5c720 | 2020-07-28 01:07:42 -0700 | [diff] [blame] | 114 | echo "$(date): Running docs.sh" |
Ian Hickson | 45e8114 | 2018-01-30 09:00:57 -0800 | [diff] [blame] | 115 | |
Greg Spencer | 77645df | 2018-08-06 17:33:31 -0700 | [diff] [blame] | 116 | if [[ ! -d "$FLUTTER_ROOT" || ! -f "$FLUTTER_ROOT/bin/flutter" ]]; then |
Todd Volkert | 8e0eee9 | 2020-07-26 23:38:01 -0700 | [diff] [blame] | 117 | >&2 echo "Unable to locate the Flutter installation (using FLUTTER_ROOT: $FLUTTER_ROOT)" |
Greg Spencer | 77645df | 2018-08-06 17:33:31 -0700 | [diff] [blame] | 118 | exit 1 |
| 119 | fi |
Ian Hickson | 127545a | 2017-05-06 15:08:14 -0700 | [diff] [blame] | 120 | |
Greg Spencer | 77645df | 2018-08-06 17:33:31 -0700 | [diff] [blame] | 121 | FLUTTER_BIN="$FLUTTER_ROOT/bin" |
| 122 | DART_BIN="$FLUTTER_ROOT/bin/cache/dart-sdk/bin" |
| 123 | FLUTTER="$FLUTTER_BIN/flutter" |
| 124 | DART="$DART_BIN/dart" |
| 125 | PUB="$DART_BIN/pub" |
| 126 | export PATH="$FLUTTER_BIN:$DART_BIN:$PATH" |
Greg Spencer | 711ecf7 | 2018-07-30 12:35:15 -0700 | [diff] [blame] | 127 | |
Greg Spencer | 77645df | 2018-08-06 17:33:31 -0700 | [diff] [blame] | 128 | # Make sure dart is installed by invoking flutter to download it. |
| 129 | "$FLUTTER" --version |
Greg Spencer | f20adcc | 2018-11-15 15:05:57 -0800 | [diff] [blame] | 130 | FLUTTER_VERSION=$(cat "$FLUTTER_ROOT/version") |
Ian Hickson | 1e6c7eb | 2017-05-11 09:42:08 -0700 | [diff] [blame] | 131 | |
Greg Spencer | f29ecba | 2017-12-05 14:46:39 -0800 | [diff] [blame] | 132 | # If the pub cache directory exists in the root, then use that. |
| 133 | FLUTTER_PUB_CACHE="$FLUTTER_ROOT/.pub-cache" |
Greg Spencer | 77645df | 2018-08-06 17:33:31 -0700 | [diff] [blame] | 134 | if [[ -d "$FLUTTER_PUB_CACHE" ]]; then |
Greg Spencer | f20adcc | 2018-11-15 15:05:57 -0800 | [diff] [blame] | 135 | # This has to be exported, because pub interprets setting it to the empty |
| 136 | # string in the same way as setting it to ".". |
Greg Spencer | f29ecba | 2017-12-05 14:46:39 -0800 | [diff] [blame] | 137 | export PUB_CACHE="${PUB_CACHE:-"$FLUTTER_PUB_CACHE"}" |
| 138 | fi |
| 139 | |
Todd Volkert | 8c5c720 | 2020-07-28 01:07:42 -0700 | [diff] [blame] | 140 | generate_docs |
Christopher Fujino | d6e308c | 2020-08-19 18:16:05 -0700 | [diff] [blame] | 141 | # Skip publishing docs for PRs and release candidate branches |
godofredoc | f8f6963 | 2020-10-13 17:06:49 -0700 | [diff] [blame] | 142 | if [[ -n "$LUCI_CI" && -z "$LUCI_PR" ]]; then |
Christopher Fujino | d6e308c | 2020-08-19 18:16:05 -0700 | [diff] [blame] | 143 | (cd "$FLUTTER_ROOT/dev/docs"; create_offline_zip) |
godofredoc | f8f6963 | 2020-10-13 17:06:49 -0700 | [diff] [blame] | 144 | (cd "$FLUTTER_ROOT/dev/docs"; create_docset) |
Christopher Fujino | d6e308c | 2020-08-19 18:16:05 -0700 | [diff] [blame] | 145 | (cd "$FLUTTER_ROOT/dev/docs"; move_offline_into_place) |
| 146 | deploy_docs |
Todd Volkert | 8c5c720 | 2020-07-28 01:07:42 -0700 | [diff] [blame] | 147 | fi |