flutter 2.2 KB
Newer Older
1 2 3 4 5
#!/bin/bash
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

6 7
set -e

8 9 10 11 12 13 14 15 16 17 18 19 20
function follow_links() {
  file="$1"
  while [ -h "$file" ]; do
    # On Mac OS, readlink -f doesn't work.
    file="$(readlink "$file")"
  done
  echo "$file"
}

PROG_NAME="$(follow_links "$BASH_SOURCE")"
BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
export FLUTTER_ROOT="$(cd "${BIN_DIR}/.." ; pwd -P)"

21 22 23
FLUTTER_TOOLS_DIR="$FLUTTER_ROOT/packages/flutter_tools"
SNAPSHOT_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.snapshot"
STAMP_PATH="$FLUTTER_ROOT/bin/cache/flutter_tools.stamp"
24
SCRIPT_PATH="$FLUTTER_TOOLS_DIR/bin/flutter_tools.dart"
25
DART_SDK_PATH="$FLUTTER_ROOT/bin/cache/dart-sdk"
26

27
DART="$DART_SDK_PATH/bin/dart"
28 29

REVISION=`(cd "$FLUTTER_ROOT"; git rev-parse HEAD)`
30
if [ ! -f "$SNAPSHOT_PATH" ] || [ ! -f "$STAMP_PATH" ] || [ `cat "$STAMP_PATH"` != "$REVISION" ] || [ "$FLUTTER_TOOLS_DIR/pubspec.yaml" -nt "$FLUTTER_TOOLS_DIR/pubspec.lock" ]; then
31
  "$FLUTTER_ROOT/bin/cache/update_dart_sdk.sh"
32
  "$FLUTTER_ROOT/bin/cache/update_engine.sh"
33 34 35

  echo Building flutter tool...
  FLUTTER_DIR="$FLUTTER_ROOT/packages/flutter"
36
  (cd "$FLUTTER_TOOLS_DIR"; "../../bin/cache/dart-sdk/bin/pub" get --verbosity=warning)
37
  "$DART" --snapshot="$SNAPSHOT_PATH" --packages="$FLUTTER_TOOLS_DIR/.packages" "$SCRIPT_PATH"
38
  echo $REVISION > "$STAMP_PATH"
39 40
fi

41 42 43 44 45 46 47 48
# Add our internalized version of the Dart SDK to the path ahead of any other
# versions that might be installed on this machine.
#
# TODO(abarth): We should teach flutter_tools to our version of the Dart SDK
#               explicitly instead of relying upon the PATH.
#
export PATH="$DART_SDK_PATH/bin:$PATH"

49 50
set +e

51 52
if [ $FLUTTER_DEV ]; then
  echo -e "(FLUTTER_DEV set - ignoring $SNAPSHOT_PATH)\n"
53
  "$DART" --packages="$FLUTTER_TOOLS_DIR/.packages" "$SCRIPT_PATH" "$@"
54 55 56
else
  "$DART" "$SNAPSHOT_PATH" "$@"
fi
57 58 59 60 61 62 63 64

# The VM exits with code 253 if the snapshot version is out-of-date.
# If it is, we need to snapshot it again.
EXIT_CODE=$?
if [ $EXIT_CODE != 253 ]; then
  exit $EXIT_CODE
fi

65 66
set -e

67
"$DART" --snapshot="$SNAPSHOT_PATH" --package="$FLUTTER_TOOLS_DIR/.packages" "$SCRIPT_PATH"
68
"$DART" "$SNAPSHOT_PATH" "$@"