update_dart_sdk.sh 3.12 KB
Newer Older
1
#!/usr/bin/env bash
2 3 4 5
# Copyright 2016 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 8 9 10 11 12 13 14

# ---------------------------------- NOTE ---------------------------------- #
#
# Please keep the logic in this file consistent with the logic in the
# `update_dart_sdk.ps1` script in the same directory to ensure that Flutter
# continues to work across all platforms!
#
# -------------------------------------------------------------------------- #

15 16
set -e

17
FLUTTER_ROOT="$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")")"
18

19
DART_SDK_PATH="$FLUTTER_ROOT/bin/cache/dart-sdk"
20
DART_SDK_PATH_OLD="$DART_SDK_PATH.old"
21 22
ENGINE_STAMP="$FLUTTER_ROOT/bin/cache/engine-dart-sdk.stamp"
ENGINE_VERSION=`cat "$FLUTTER_ROOT/bin/internal/engine.version"`
23

24
if [ ! -f "$ENGINE_STAMP" ] || [ "$ENGINE_VERSION" != `cat "$ENGINE_STAMP"` ]; then
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
  command -v curl > /dev/null 2>&1 || {
    echo
    echo 'Missing "curl" tool. Unable to download Dart SDK.'
    case "$(uname -s)" in
      Darwin)
        echo 'Consider running "brew install curl".'
        ;;
      Linux)
        echo 'Consider running "sudo apt-get install curl".'
        ;;
      *)
        echo "Please install curl."
        ;;
    esac
    echo
    exit 1
  }
42
  echo "Downloading Dart SDK from Flutter engine $ENGINE_VERSION..."
43 44 45

  case "$(uname -s)" in
    Darwin)
46
      DART_ZIP_NAME="dart-sdk-darwin-x64.zip"
47
      IS_USER_EXECUTABLE="-perm +100"
48 49
      ;;
    Linux)
50
      DART_ZIP_NAME="dart-sdk-linux-x64.zip"
51
      IS_USER_EXECUTABLE="-perm /u+x"
52 53 54 55 56 57 58
      ;;
    *)
      echo "Unknown operating system. Cannot install Dart SDK."
      exit 1
      ;;
  esac

59
  DART_SDK_BASE_URL="${FLUTTER_STORAGE_BASE_URL:-https://storage.googleapis.com}"
60
  DART_SDK_URL="$DART_SDK_BASE_URL/flutter_infra/flutter/$ENGINE_VERSION/$DART_ZIP_NAME"
61

62 63 64 65 66 67 68
  # if the sdk path exists, copy it to a temporary location
  if [ -d "$DART_SDK_PATH" ]; then
    rm -rf "$DART_SDK_PATH_OLD"
    mv "$DART_SDK_PATH" "$DART_SDK_PATH_OLD"
  fi

  # install the new sdk
69
  rm -rf -- "$DART_SDK_PATH"
70
  mkdir -m 755 -p -- "$DART_SDK_PATH"
71
  DART_SDK_ZIP="$FLUTTER_ROOT/bin/cache/$DART_ZIP_NAME"
72

73 74
  curl --continue-at - --location --output "$DART_SDK_ZIP" "$DART_SDK_URL" 2>&1 || {
    echo
75 76
    echo "Failed to retrieve the Dart SDK from: $DART_SDK_URL"
    echo "If you're located in China, please see this page:"
77
    echo "  https://flutter.dev/community/china"
78 79 80 81
    echo
    rm -f -- "$DART_SDK_ZIP"
    exit 1
  }
82 83
  unzip -o -q "$DART_SDK_ZIP" -d "$FLUTTER_ROOT/bin/cache" || {
    echo
84 85 86
    echo "It appears that the downloaded file is corrupt; please try again."
    echo "If this problem persists, please report the problem at:"
    echo "  https://github.com/flutter/flutter/issues/new?template=ACTIVATION.md"
87 88 89 90
    echo
    rm -f -- "$DART_SDK_ZIP"
    exit 1
  }
91
  rm -f -- "$DART_SDK_ZIP"
92 93
  find "$DART_SDK_PATH" -type d -exec chmod 755 {} \;
  find "$DART_SDK_PATH" -type f $IS_USER_EXECUTABLE -exec chmod a+x,a+r {} \;
94
  echo "$ENGINE_VERSION" > "$ENGINE_STAMP"
95 96 97 98 99

  # delete any temporary sdk path
  if [ -d "$DART_SDK_PATH_OLD" ]; then
    rm -rf "$DART_SDK_PATH_OLD"
  fi
100
fi