From dbee5c01e9859d9fa56942ab57be53aaa8931f45 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 5 Nov 2015 00:20:03 -0800 Subject: [PATCH] Add a bash script for bootstrapping flutter_tools --- bin/cache/.gitignore | 2 ++ bin/cache/README.md | 3 +++ bin/flutter | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 bin/cache/.gitignore create mode 100644 bin/cache/README.md create mode 100755 bin/flutter diff --git a/bin/cache/.gitignore b/bin/cache/.gitignore new file mode 100644 index 00000000000..a46a10366c5 --- /dev/null +++ b/bin/cache/.gitignore @@ -0,0 +1,2 @@ +*.snapshot +*.stamp diff --git a/bin/cache/README.md b/bin/cache/README.md new file mode 100644 index 00000000000..c7f88be9370 --- /dev/null +++ b/bin/cache/README.md @@ -0,0 +1,3 @@ +# Binary cache + +This directory contains a cache of binary artifacts used by the Flutter tools. diff --git a/bin/flutter b/bin/flutter new file mode 100755 index 00000000000..6a4667fd60c --- /dev/null +++ b/bin/flutter @@ -0,0 +1,36 @@ +#!/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. + +FLUTTER_ROOT=$(dirname $(dirname "${BASH_SOURCE[0]}")) +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" +SCRIPT_PATH="$FLUTTER_TOOLS_DIR/bin/sky_tools.dart" + +# TODO(abarth): We shouldn't require dart to be on the user's path. +DART=dart + +if [ "$FLUTTER_TOOLS_DIR/pubspec.yaml" -nt "$FLUTTER_TOOLS_DIR/pubspec.lock" ]; then + (cd "$FLUTTER_TOOLS_DIR"; pub get) +fi + +REVISION=`(cd "$FLUTTER_ROOT"; git rev-parse HEAD)` + +if [ ! -f "$SNAPSHOT_PATH" ] || [ ! -f "$STAMP_PATH" ] || [ `cat "$STAMP_PATH"` != $REVISION ]; then + DART --snapshot="$SNAPSHOT_PATH" --package-root="$FLUTTER_TOOLS_DIR/packages" "$SCRIPT_PATH" + echo -n $REVISION > "$STAMP_PATH" +fi + +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 +fi + +DART --snapshot="$SNAPSHOT_PATH" --package-root="$FLUTTER_TOOLS_DIR/packages" "$SCRIPT_PATH" +DART "$SNAPSHOT_PATH" "$@"