1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env bash
# Copyright 2014 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# ---------------------------------- 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!
#
# -------------------------------------------------------------------------- #
set -e
FLUTTER_ROOT="$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")")"
DART_SDK_PATH="$FLUTTER_ROOT/bin/cache/dart-sdk"
DART_SDK_PATH_OLD="$DART_SDK_PATH.old"
ENGINE_STAMP="$FLUTTER_ROOT/bin/cache/engine-dart-sdk.stamp"
ENGINE_VERSION=`cat "$FLUTTER_ROOT/bin/internal/engine.version"`
if [ ! -f "$ENGINE_STAMP" ] || [ "$ENGINE_VERSION" != `cat "$ENGINE_STAMP"` ]; then
command -v curl > /dev/null 2>&1 || {
>&2 echo
>&2 echo 'Missing "curl" tool. Unable to download Dart SDK.'
case "$(uname -s)" in
Darwin)
>&2 echo 'Consider running "brew install curl".'
;;
Linux)
>&2 echo 'Consider running "sudo apt-get install curl".'
;;
*)
>&2 echo "Please install curl."
;;
esac
echo
exit 1
}
command -v unzip > /dev/null 2>&1 || {
>&2 echo
>&2 echo 'Missing "unzip" tool. Unable to extract Dart SDK.'
case "$(uname -s)" in
Darwin)
echo 'Consider running "brew install unzip".'
;;
Linux)
echo 'Consider running "sudo apt-get install unzip".'
;;
*)
echo "Please install unzip."
;;
esac
echo
exit 1
}
>&2 echo "Downloading Dart SDK from Flutter engine $ENGINE_VERSION..."
# On x64 stdout is "uname -m: x86_64"
# On arm64 stdout is "uname -m: aarch64, arm64_v8a"
case "$(uname -m)" in
x86_64)
ARCH="x64"
;;
*)
ARCH="arm64"
;;
esac
case "$(uname -s)" in
Darwin)
DART_ZIP_NAME="dart-sdk-darwin-${ARCH}.zip"
IS_USER_EXECUTABLE="-perm +100"
;;
Linux)
DART_ZIP_NAME="dart-sdk-linux-${ARCH}.zip"
IS_USER_EXECUTABLE="-perm /u+x"
;;
MINGW*)
DART_ZIP_NAME="dart-sdk-windows-x64.zip"
IS_USER_EXECUTABLE="-perm /u+x"
;;
*)
echo "Unknown operating system. Cannot install Dart SDK."
exit 1
;;
esac
# Use the default find if possible.
if [ -e /usr/bin/find ]; then
FIND=/usr/bin/find
else
FIND=find
fi
DART_SDK_BASE_URL="${FLUTTER_STORAGE_BASE_URL:-https://storage.googleapis.com}"
DART_SDK_URL="$DART_SDK_BASE_URL/flutter_infra_release/flutter/$ENGINE_VERSION/$DART_ZIP_NAME"
# 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
rm -rf -- "$DART_SDK_PATH"
mkdir -m 755 -p -- "$DART_SDK_PATH"
DART_SDK_ZIP="$FLUTTER_ROOT/bin/cache/$DART_ZIP_NAME"
# Conditionally set verbose flag for LUCI
verbose_curl=""
if [[ -n "$LUCI_CI" ]]; then
verbose_curl="--verbose"
fi
curl ${verbose_curl} --retry 3 --continue-at - --location --output "$DART_SDK_ZIP" "$DART_SDK_URL" 2>&1 || {
curlExitCode=$?
# Handle range errors specially: retry again with disabled ranges (`--continue-at -` argument)
# When this could happen:
# - missing support of ranges in proxy servers
# - curl with broken handling of completed downloads
# This is not a proper fix, but doesn't require any user input
# - mirror of flutter storage without support of ranges
#
# 33 HTTP range error. The range "command" didn't work.
# https://man7.org/linux/man-pages/man1/curl.1.html#EXIT_CODES
if [ $curlExitCode != 33 ]; then
return $curlExitCode
fi
curl ${verbose_curl} --retry 3 --location --output "$DART_SDK_ZIP" "$DART_SDK_URL" 2>&1
} || {
>&2 echo
>&2 echo "Failed to retrieve the Dart SDK from: $DART_SDK_URL"
>&2 echo "If you're located in China, please see this page:"
>&2 echo " https://flutter.dev/community/china"
>&2 echo
rm -f -- "$DART_SDK_ZIP"
exit 1
}
unzip -o -q "$DART_SDK_ZIP" -d "$FLUTTER_ROOT/bin/cache" || {
>&2 echo
>&2 echo "It appears that the downloaded file is corrupt; please try again."
>&2 echo "If this problem persists, please report the problem at:"
>&2 echo " https://github.com/flutter/flutter/issues/new?template=1_activation.md"
>&2 echo
rm -f -- "$DART_SDK_ZIP"
exit 1
}
rm -f -- "$DART_SDK_ZIP"
$FIND "$DART_SDK_PATH" -type d -exec chmod 755 {} \;
$FIND "$DART_SDK_PATH" -type f $IS_USER_EXECUTABLE -exec chmod a+x,a+r {} \;
echo "$ENGINE_VERSION" > "$ENGINE_STAMP"
# delete any temporary sdk path
if [ -d "$DART_SDK_PATH_OLD" ]; then
rm -rf "$DART_SDK_PATH_OLD"
fi
fi