Created
May 15, 2020 18:44
-
-
Save christopherfujino/41c676aa84f2c6a39cf25eec3fcab341 to your computer and use it in GitHub Desktop.
bin/flutter -> bin/shared.sh diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/bin/flutter b/bin/shared.sh | |
index 87bd59711..a9de7f131 100755 | |
--- a/bin/flutter | |
+++ b/bin/shared.sh | |
@@ -16,25 +16,6 @@ set -e | |
unset CDPATH | |
-function follow_links() { | |
- cd -P "${1%/*}" | |
- local file="$PWD/${1##*/}" | |
- while [[ -h "$file" ]]; do | |
- # On Mac OS, readlink -f doesn't work. | |
- cd -P "${file%/*}" | |
- file="$(readlink "$file")" | |
- cd -P "${file%/*}" | |
- file="$PWD/${file##*/}" | |
- done | |
- echo "$PWD/${file##*/}" | |
-} | |
- | |
-# Convert a filesystem path to a format usable by Dart's URI parser. | |
-function path_uri() { | |
- # Reduce multiple leading slashes to a single slash. | |
- echo "$1" | sed -E -e "s,^/+,/," | |
-} | |
- | |
function _rmlock () { | |
[ -n "$FLUTTER_UPGRADE_LOCK" ] && rm -f "$FLUTTER_UPGRADE_LOCK" | |
} | |
@@ -137,56 +118,70 @@ function upgrade_flutter () { | |
exit $? | |
} | |
-PROG_NAME="$(path_uri "$(follow_links "$BASH_SOURCE")")" | |
-BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)" | |
-export FLUTTER_ROOT="$(cd "${BIN_DIR}/.." ; pwd -P)" | |
- | |
-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/flutter_tools.dart" | |
-DART_SDK_PATH="$FLUTTER_ROOT/bin/cache/dart-sdk" | |
- | |
-DART="$DART_SDK_PATH/bin/dart" | |
-PUB="$DART_SDK_PATH/bin/pub" | |
- | |
-# If running over git-bash, overrides the default UNIX | |
-# executables with win32 executables | |
-case "$(uname -s)" in | |
- MINGW32*) | |
- DART="$DART.exe" | |
- PUB="$PUB.bat" | |
- ;; | |
-esac | |
- | |
-# Test if running as superuser β but don't warn if running within Docker | |
-if [[ "$EUID" == "0" && ! -f /.dockerenv ]]; then | |
- echo " Woah! You appear to be trying to run flutter as root." | |
- echo " We strongly recommend running the flutter tool without superuser privileges." | |
- echo " /" | |
- echo "π" | |
-fi | |
- | |
-# Test if Git is available on the Host | |
-if ! hash git 2>/dev/null; then | |
- echo "Error: Unable to find git in your PATH." | |
- exit 1 | |
-fi | |
-# Test if the flutter directory is a git clone (otherwise git rev-parse HEAD would fail) | |
-if [[ ! -e "$FLUTTER_ROOT/.git" ]]; then | |
- echo "Error: The Flutter directory is not a clone of the GitHub project." | |
- echo " The flutter tool requires Git in order to operate properly;" | |
- echo " to set up Flutter, run the following command:" | |
- echo " git clone -b stable https://github.com/flutter/flutter.git" | |
- exit 1 | |
-fi | |
- | |
-# To debug the tool, you can uncomment the following lines to enable checked mode and set an observatory port: | |
-# FLUTTER_TOOL_ARGS="--enable-asserts $FLUTTER_TOOL_ARGS" | |
-# FLUTTER_TOOL_ARGS="$FLUTTER_TOOL_ARGS --observe=65432" | |
- | |
-(upgrade_flutter) 3< "$PROG_NAME" | |
- | |
-# FLUTTER_TOOL_ARGS isn't quoted below, because it is meant to be considered as | |
-# separate space-separated args. | |
-"$DART" --disable-dart-dev --packages="$FLUTTER_TOOLS_DIR/.packages" $FLUTTER_TOOL_ARGS "$SNAPSHOT_PATH" "$@" | |
+# This function is intended to be executed by entrypoints (e.g. `//bin/flutter` | |
+# and `//bin/dart`) | |
+function shared::execute() { | |
+ export FLUTTER_ROOT="$(cd "${BIN_DIR}/.." ; pwd -P)" | |
+ | |
+ 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/flutter_tools.dart" | |
+ DART_SDK_PATH="$FLUTTER_ROOT/bin/cache/dart-sdk" | |
+ | |
+ DART="$DART_SDK_PATH/bin/dart" | |
+ PUB="$DART_SDK_PATH/bin/pub" | |
+ | |
+ # If running over git-bash, overrides the default UNIX | |
+ # executables with win32 executables | |
+ case "$(uname -s)" in | |
+ MINGW32*) | |
+ DART="$DART.exe" | |
+ PUB="$PUB.bat" | |
+ ;; | |
+ esac | |
+ | |
+ # Test if running as superuser β but don't warn if running within Docker | |
+ if [[ "$EUID" == "0" && ! -f /.dockerenv ]]; then | |
+ echo " Woah! You appear to be trying to run flutter as root." | |
+ echo " We strongly recommend running the flutter tool without superuser privileges." | |
+ echo " /" | |
+ echo "π" | |
+ fi | |
+ | |
+ # Test if Git is available on the Host | |
+ if ! hash git 2>/dev/null; then | |
+ echo "Error: Unable to find git in your PATH." | |
+ exit 1 | |
+ fi | |
+ # Test if the flutter directory is a git clone (otherwise git rev-parse HEAD would fail) | |
+ if [[ ! -e "$FLUTTER_ROOT/.git" ]]; then | |
+ echo "Error: The Flutter directory is not a clone of the GitHub project." | |
+ echo " The flutter tool requires Git in order to operate properly;" | |
+ echo " to set up Flutter, run the following command:" | |
+ echo " git clone -b stable https://github.com/flutter/flutter.git" | |
+ exit 1 | |
+ fi | |
+ | |
+ # To debug the tool, you can uncomment the following lines to enable checked mode and set an observatory port: | |
+ # FLUTTER_TOOL_ARGS="--enable-asserts $FLUTTER_TOOL_ARGS" | |
+ # FLUTTER_TOOL_ARGS="$FLUTTER_TOOL_ARGS --observe=65432" | |
+ | |
+ (upgrade_flutter) 3< "$PROG_NAME" | |
+ | |
+ BIN_NAME="$(basename $PROG_NAME)" | |
+ case "$BIN_NAME" in | |
+ flutter*) | |
+ # FLUTTER_TOOL_ARGS and ARGS aren't quoted below, because it is meant to | |
+ # be considered as separate space-separated args. | |
+ "$DART" --disable-dart-dev --packages="$FLUTTER_TOOLS_DIR/.packages" $FLUTTER_TOOL_ARGS "$SNAPSHOT_PATH" "$@" | |
+ ;; | |
+ dart*) | |
+ "$DART" "$@" | |
+ ;; | |
+ *) | |
+ echo "Error! Executable name $BIN_NAME not recognized!" | |
+ exit 1 | |
+ ;; | |
+ esac | |
+} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment