flutter 2.35 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
function follow_links() {
9 10
  cd -P "${1%/*}"
  file="$PWD/${1##*/}"
11 12
  while [ -h "$file" ]; do
    # On Mac OS, readlink -f doesn't work.
13
    cd -P "${file%/*}"
14
    file="$(readlink "$file")"
15 16
    cd -P "${file%/*}"
    file="$PWD/${file##*/}"
17
  done
18
  echo "$PWD/${file##*/}"
19 20
}

21 22 23 24 25 26 27
# Convert a filesystem path to a format usable by Dart's URI parser.
function path_uri() {
  # Reduce multiple leading slashes to a single slash.
  echo $1 | sed -E -e "s,^/+,/,"
}

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

31 32 33
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"
34
SCRIPT_PATH="$FLUTTER_TOOLS_DIR/bin/flutter_tools.dart"
35
DART_SDK_PATH="$FLUTTER_ROOT/bin/cache/dart-sdk"
36

37
DART="$DART_SDK_PATH/bin/dart"
38

39 40 41 42 43 44 45
(
  if hash flock 2>/dev/null; then
    flock 3 # ensures that we don't simultaneously update Dart in multiple parallel instances
    # some platforms (e.g. Mac) don't have flock or any reliable alternative
  fi
  REVISION=`(cd "$FLUTTER_ROOT"; git rev-parse HEAD)`
  if [ ! -f "$SNAPSHOT_PATH" ] || [ ! -f "$STAMP_PATH" ] || [ `cat "$STAMP_PATH"` != "$REVISION" ] || [ "$FLUTTER_TOOLS_DIR/pubspec.yaml" -nt "$FLUTTER_TOOLS_DIR/pubspec.lock" ]; then
Dan Rubel's avatar
Dan Rubel committed
46 47 48
    mkdir -p "$FLUTTER_ROOT/bin/cache"
    touch "$FLUTTER_ROOT/bin/cache/.dartignore"
    "$FLUTTER_ROOT/bin/internal/update_dart_sdk.sh"
49 50 51

    echo Building flutter tool...
    FLUTTER_DIR="$FLUTTER_ROOT/packages/flutter"
52
    (cd "$FLUTTER_TOOLS_DIR"; rm -f pubspec.lock; "../../bin/cache/dart-sdk/bin/pub" get --verbosity=error --no-packages-dir)
53 54 55
    "$DART" --snapshot="$SNAPSHOT_PATH" --packages="$FLUTTER_TOOLS_DIR/.packages" "$SCRIPT_PATH"
    echo $REVISION > "$STAMP_PATH"
  fi
56
) 3< "$PROG_NAME"
57

58 59 60 61 62 63 64 65
set +e
"$DART" "$SNAPSHOT_PATH" "$@"

# 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
Ian Hickson's avatar
Ian Hickson committed
66
fi
67 68

set -e
69
"$DART" --snapshot="$SNAPSHOT_PATH" --packages="$FLUTTER_TOOLS_DIR/.packages" "$SCRIPT_PATH"
70
"$DART" "$SNAPSHOT_PATH" "$@"