blob: 929f7264a8f85156c4c1e4fd16ed476356dd27d6 [file] [log] [blame]
Ian Hickson449f4a62019-11-27 15:04:02 -08001#!/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 Ladd1ac08b22016-07-12 12:53:47 -07006set -e
Devon Carewcd8f65d2016-05-02 14:33:39 -07007
Greg Spencer77645df2018-08-06 17:33:31 -07008function 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 Volkert8e0eee92020-07-26 23:38:01 -070019function generate_docs() {
20 # Install and activate dartdoc.
Michael Goderbauer923eb762020-09-22 12:57:13 -070021 # NOTE: When updating to a new dartdoc version, please also update
22 # `dartdoc_options.yaml` to include newly introduced error and warning types.
Janice Collinsd1f78b42020-12-08 16:13:04 -080023 "$PUB" global activate dartdoc 0.38.0
Todd Volkert8e0eee92020-07-26 23:38:01 -070024
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 Goderbauer3e867f72020-08-18 19:11:05 -070029 (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 Volkert8e0eee92020-07-26 23:38:01 -070031}
32
Greg Spencerf20adcc2018-11-15 15:05:57 -080033# Zip up the docs so people can download them for offline usage.
34function create_offline_zip() {
35 # Must be run from "$FLUTTER_ROOT/dev/docs"
Todd Volkert81bf39e2020-07-24 22:38:17 -070036 echo "$(date): Zipping Flutter offline docs archive."
Greg Spencerf20adcc2018-11-15 15:05:57 -080037 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.
42function create_docset() {
43 # Must be run from "$FLUTTER_ROOT/dev/docs"
44 # Must have dashing installed: go get -u github.com/technosophos/dashing
Greg Spencer02dbb082019-01-25 08:48:52 -080045 # 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 Volkert81bf39e2020-07-24 22:38:17 -070047 echo "$(date): Building Flutter docset."
Greg Spencerf20adcc2018-11-15 15:05:57 -080048 rm -rf flutter.docset
Christopher Fujinoe3ad0342020-07-01 19:41:41 -070049 # If dashing gets stuck, Cirrus will time out the build after an hour, and we
Todd Volkert35e70052020-07-25 09:44:17 -070050 # 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 Volkert39fa0022020-07-27 21:11:43 -070052 dashing_log=/tmp/dashing.log
53 dashing build --source ./doc --config ./dashing.json > $dashing_log 2>&1 &
Todd Volkert35e70052020-07-25 09:44:17 -070054 dashing_pid=$!
Todd Volkert35e70052020-07-25 09:44:17 -070055 wait $dashing_pid && \
Greg Spencer625a37b2018-12-11 09:53:33 -080056 cp ./doc/flutter/static-assets/favicon.png ./flutter.docset/icon.png && \
Michael Goderbauer3e867f72020-08-18 19:11:05 -070057 "$DART" --disable-dart-dev --enable-asserts ./dashing_postprocess.dart && \
Todd Volkert39fa0022020-07-27 21:11:43 -070058 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 Spencerf20adcc2018-11-15 15:05:57 -080064}
65
Todd Volkert8e0eee92020-07-26 23:38:01 -070066function deploy_docs() {
Todd Volkert8e0eee92020-07-26 23:38:01 -070067 # Ensure google webmaster tools can verify our site.
68 cp "$FLUTTER_ROOT/dev/docs/google2ed1af765c529f57.html" "$FLUTTER_ROOT/dev/docs/doc"
69
godofredocf8f69632020-10-13 17:06:49 -070070 case "$LUCI_BRANCH" in
Todd Volkert8e0eee92020-07-26 23:38:01 -070071 master)
godofredocf8f69632020-10-13 17:06:49 -070072 echo "$(date): Updating $LUCI_BRANCH docs: https://master-api.flutter.dev/"
Todd Volkert8e0eee92020-07-26 23:38:01 -070073 # 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 Volkert8e0eee92020-07-26 23:38:01 -070076 ;;
77 stable)
godofredocf8f69632020-10-13 17:06:49 -070078 echo "$(date): Updating $LUCI_BRANCH docs: https://api.flutter.dev/"
Todd Volkert8e0eee92020-07-26 23:38:01 -070079 # 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 Volkert8e0eee92020-07-26 23:38:01 -070082 ;;
83 *)
godofredocf8f69632020-10-13 17:06:49 -070084 >&2 echo "Docs deployment cannot be run on the $LUCI_BRANCH branch."
Christopher Fujinod6e308c2020-08-19 18:16:05 -070085 exit 0
Todd Volkert8e0eee92020-07-26 23:38:01 -070086 esac
87}
88
Greg Spencerf20adcc2018-11-15 15:05:57 -080089# 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.
92function move_offline_into_place() {
93 # Must be run from "$FLUTTER_ROOT/dev/docs"
Todd Volkert81bf39e2020-07-24 22:38:17 -070094 echo "$(date): Moving offline data into place."
Greg Spencerf20adcc2018-11-15 15:05:57 -080095 mkdir -p doc/offline
96 mv flutter.docs.zip doc/offline/flutter.docs.zip
97 du -sh doc/offline/flutter.docs.zip
godofredocf8f69632020-10-13 17:06:49 -070098 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 Spencerf20adcc2018-11-15 15:05:57 -0800105}
106
Greg Spencer77645df2018-08-06 17:33:31 -0700107# So that users can run this script from anywhere and it will work as expected.
108SCRIPT_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.
112FLUTTER_ROOT="$(dirname "$(dirname "$SCRIPT_LOCATION")")"
113
Todd Volkert8c5c7202020-07-28 01:07:42 -0700114echo "$(date): Running docs.sh"
Ian Hickson45e81142018-01-30 09:00:57 -0800115
Greg Spencer77645df2018-08-06 17:33:31 -0700116if [[ ! -d "$FLUTTER_ROOT" || ! -f "$FLUTTER_ROOT/bin/flutter" ]]; then
Todd Volkert8e0eee92020-07-26 23:38:01 -0700117 >&2 echo "Unable to locate the Flutter installation (using FLUTTER_ROOT: $FLUTTER_ROOT)"
Greg Spencer77645df2018-08-06 17:33:31 -0700118 exit 1
119fi
Ian Hickson127545a2017-05-06 15:08:14 -0700120
Greg Spencer77645df2018-08-06 17:33:31 -0700121FLUTTER_BIN="$FLUTTER_ROOT/bin"
122DART_BIN="$FLUTTER_ROOT/bin/cache/dart-sdk/bin"
123FLUTTER="$FLUTTER_BIN/flutter"
124DART="$DART_BIN/dart"
125PUB="$DART_BIN/pub"
126export PATH="$FLUTTER_BIN:$DART_BIN:$PATH"
Greg Spencer711ecf72018-07-30 12:35:15 -0700127
Greg Spencer77645df2018-08-06 17:33:31 -0700128# Make sure dart is installed by invoking flutter to download it.
129"$FLUTTER" --version
Greg Spencerf20adcc2018-11-15 15:05:57 -0800130FLUTTER_VERSION=$(cat "$FLUTTER_ROOT/version")
Ian Hickson1e6c7eb2017-05-11 09:42:08 -0700131
Greg Spencerf29ecba2017-12-05 14:46:39 -0800132# If the pub cache directory exists in the root, then use that.
133FLUTTER_PUB_CACHE="$FLUTTER_ROOT/.pub-cache"
Greg Spencer77645df2018-08-06 17:33:31 -0700134if [[ -d "$FLUTTER_PUB_CACHE" ]]; then
Greg Spencerf20adcc2018-11-15 15:05:57 -0800135 # This has to be exported, because pub interprets setting it to the empty
136 # string in the same way as setting it to ".".
Greg Spencerf29ecba2017-12-05 14:46:39 -0800137 export PUB_CACHE="${PUB_CACHE:-"$FLUTTER_PUB_CACHE"}"
138fi
139
Todd Volkert8c5c7202020-07-28 01:07:42 -0700140generate_docs
Christopher Fujinod6e308c2020-08-19 18:16:05 -0700141# Skip publishing docs for PRs and release candidate branches
godofredocf8f69632020-10-13 17:06:49 -0700142if [[ -n "$LUCI_CI" && -z "$LUCI_PR" ]]; then
Christopher Fujinod6e308c2020-08-19 18:16:05 -0700143 (cd "$FLUTTER_ROOT/dev/docs"; create_offline_zip)
godofredocf8f69632020-10-13 17:06:49 -0700144 (cd "$FLUTTER_ROOT/dev/docs"; create_docset)
Christopher Fujinod6e308c2020-08-19 18:16:05 -0700145 (cd "$FLUTTER_ROOT/dev/docs"; move_offline_into_place)
146 deploy_docs
Todd Volkert8c5c7202020-07-28 01:07:42 -0700147fi