update_dart_sdk.sh 2.5 KB
Newer Older
1 2 3 4 5
#!/bin/bash
# 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
DART_SDK_STAMP_PATH="$FLUTTER_ROOT/bin/cache/dart-sdk.stamp"
Dan Rubel's avatar
Dan Rubel committed
22
DART_SDK_VERSION=`cat "$FLUTTER_ROOT/bin/internal/dart-sdk.version"`
23 24

if [ ! -f "$DART_SDK_STAMP_PATH" ] || [ "$DART_SDK_VERSION" != `cat "$DART_SDK_STAMP_PATH"` ]; then
25
  echo "Downloading Dart SDK $DART_SDK_VERSION..."
26 27 28 29 30 31 32 33 34 35 36 37 38 39

  case "$(uname -s)" in
    Darwin)
      DART_ZIP_NAME="dartsdk-macos-x64-release.zip"
      ;;
    Linux)
      DART_ZIP_NAME="dartsdk-linux-x64-release.zip"
      ;;
    *)
      echo "Unknown operating system. Cannot install Dart SDK."
      exit 1
      ;;
  esac

40 41 42 43 44
  DART_CHANNEL="stable"

  if [[ $DART_SDK_VERSION == *"-dev."* ]]
  then
    DART_CHANNEL="dev"
45 46 47
  elif [[ $DART_SDK_VERSION == "hash/"* ]]
  then
    DART_CHANNEL="be"
48 49
  fi

50 51
  DART_SDK_BASE_URL="${FLUTTER_STORAGE_BASE_URL:-https://storage.googleapis.com}"
  DART_SDK_URL="$DART_SDK_BASE_URL/dart-archive/channels/$DART_CHANNEL/raw/$DART_SDK_VERSION/sdk/$DART_ZIP_NAME"
52

53 54 55 56 57 58 59
  # 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
60 61
  rm -rf -- "$DART_SDK_PATH"
  mkdir -p -- "$DART_SDK_PATH"
62 63
  DART_SDK_ZIP="$FLUTTER_ROOT/bin/cache/dart-sdk.zip"

64
  curl --continue-at - --location --output "$DART_SDK_ZIP" "$DART_SDK_URL" 2>&1
65 66 67 68 69 70 71 72 73
  unzip -o -q "$DART_SDK_ZIP" -d "$FLUTTER_ROOT/bin/cache" || {
    echo
    echo "It appears that the downloaded file is corrupt; please try the operation again later."
    echo "If this problem persists, please report the problem at"
    echo "https://github.com/flutter/flutter/issues/new"
    echo
    rm -f -- "$DART_SDK_ZIP"
    exit 1
  }
74 75
  rm -f -- "$DART_SDK_ZIP"
  echo "$DART_SDK_VERSION" > "$DART_SDK_STAMP_PATH"
76 77 78 79 80

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