Use .pub-cache from Flutter root, if it exists. (#13358)
The purpose of this PR is to make it so that when the user runs 'flutter', if they have a .pub-cache directory in their flutter root, we use that instead of the default location for the pub cache. Otherwise, it should act as before. The eventual goal is to support a pre-populated flutter .zip/.tar.gz file that has everything the developer needs in one bundle. In order for that to actually work, we need to have the pub cache be self-contained, and not in the user's home dir. Another advantage of this is that if you have multiple flutter repos that you're switching between, then the versions in the pub cache will remain static when you switch between them. This is an attempt to re-land: #13248. Includes a fix for the test that makes it work on bots in the presence of PUB_CACHE being set, and no other changes.
This commit is contained in:
63
bin/flutter
63
bin/flutter
@@ -16,7 +16,7 @@ set -e
|
||||
|
||||
function follow_links() {
|
||||
cd -P "${1%/*}"
|
||||
file="$PWD/${1##*/}"
|
||||
local file="$PWD/${1##*/}"
|
||||
while [ -h "$file" ]; do
|
||||
# On Mac OS, readlink -f doesn't work.
|
||||
cd -P "${file%/*}"
|
||||
@@ -33,6 +33,39 @@ function path_uri() {
|
||||
echo "$1" | sed -E -e "s,^/+,/,"
|
||||
}
|
||||
|
||||
function upgrade_flutter () {
|
||||
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
|
||||
|
||||
local revision=`(cd "$FLUTTER_ROOT"; git rev-parse HEAD)`
|
||||
if [ ! -f "$SNAPSHOT_PATH" ] || [ ! -s "$STAMP_PATH" ] || [ `cat "$STAMP_PATH"` != "$revision" ] || [ "$FLUTTER_TOOLS_DIR/pubspec.yaml" -nt "$FLUTTER_TOOLS_DIR/pubspec.lock" ]; then
|
||||
mkdir -p "$FLUTTER_ROOT/bin/cache"
|
||||
touch "$FLUTTER_ROOT/bin/cache/.dartignore"
|
||||
"$FLUTTER_ROOT/bin/internal/update_dart_sdk.sh"
|
||||
|
||||
echo Building flutter tool...
|
||||
if [ "$TRAVIS" == "true" ] || [ "$BOT" == "true" ] || [ "$CONTINUOUS_INTEGRATION" == "true" ] || [ "$CHROME_HEADLESS" == "1" ] || [ "$APPVEYOR" == "true" ] || [ "$CI" == "true" ]; then
|
||||
PUB_ENVIRONMENT="$PUB_ENVIRONMENT:flutter_bot"
|
||||
fi
|
||||
export PUB_ENVIRONMENT="$PUB_ENVIRONMENT:flutter_install"
|
||||
|
||||
if [ -d "$FLUTTER_ROOT/.pub-cache" ]; then
|
||||
export PUB_CACHE="${PUB_CACHE:-"$FLUTTER_ROOT/.pub-cache"}"
|
||||
fi
|
||||
|
||||
while : ; do
|
||||
cd "$FLUTTER_TOOLS_DIR"
|
||||
"$PUB" upgrade --verbosity=error --no-packages-dir && break
|
||||
echo Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds...
|
||||
sleep 5
|
||||
done
|
||||
"$DART" --snapshot="$SNAPSHOT_PATH" --packages="$FLUTTER_TOOLS_DIR/.packages" "$SCRIPT_PATH"
|
||||
echo "$revision" > "$STAMP_PATH"
|
||||
fi
|
||||
}
|
||||
|
||||
PROG_NAME="$(path_uri "$(follow_links "$BASH_SOURCE")")"
|
||||
BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
|
||||
export FLUTTER_ROOT="$(cd "${BIN_DIR}/.." ; pwd -P)"
|
||||
@@ -70,33 +103,7 @@ FLUTTER_TOOL_ARGS="--assert-initializer $FLUTTER_TOOL_ARGS"
|
||||
# FLUTTER_TOOL_ARGS="--checked $FLUTTER_TOOL_ARGS"
|
||||
# FLUTTER_TOOL_ARGS="$FLUTTER_TOOL_ARGS --observe=65432"
|
||||
|
||||
(
|
||||
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" ] || [ ! -s "$STAMP_PATH" ] || [ `cat "$STAMP_PATH"` != "$REVISION" ] || [ "$FLUTTER_TOOLS_DIR/pubspec.yaml" -nt "$FLUTTER_TOOLS_DIR/pubspec.lock" ]; then
|
||||
mkdir -p "$FLUTTER_ROOT/bin/cache"
|
||||
touch "$FLUTTER_ROOT/bin/cache/.dartignore"
|
||||
"$FLUTTER_ROOT/bin/internal/update_dart_sdk.sh"
|
||||
|
||||
echo Building flutter tool...
|
||||
LOCAL_PUB_ENV="$PUB_ENVIRONMENT"
|
||||
if [ "$TRAVIS" == "true" ] || [ "$BOT" == "true" ] || [ "$CONTINUOUS_INTEGRATION" == "true" ] || [ "$CHROME_HEADLESS" == "1" ] || [ "$APPVEYOR" == "true" ] || [ "$CI" == "true" ]; then
|
||||
LOCAL_PUB_ENV="$LOCAL_PUB_ENV:flutter_bot"
|
||||
fi
|
||||
LOCAL_PUB_ENV="$LOCAL_PUB_ENV:flutter_install"
|
||||
while : ; do
|
||||
cd "$FLUTTER_TOOLS_DIR"
|
||||
PUB_ENVIRONMENT="$LOCAL_PUB_ENV" "$PUB" upgrade --verbosity=error --no-packages-dir && break
|
||||
echo Error: Unable to 'pub upgrade' flutter tool. Retrying in five seconds...
|
||||
sleep 5
|
||||
done
|
||||
"$DART" --snapshot="$SNAPSHOT_PATH" --packages="$FLUTTER_TOOLS_DIR/.packages" "$SCRIPT_PATH"
|
||||
echo $REVISION > "$STAMP_PATH"
|
||||
fi
|
||||
) 3< "$PROG_NAME"
|
||||
(upgrade_flutter) 3< "$PROG_NAME"
|
||||
|
||||
set +e
|
||||
"$DART" $FLUTTER_TOOL_ARGS "$SNAPSHOT_PATH" "$@"
|
||||
|
||||
Reference in New Issue
Block a user