flutter 2.29 KB
Newer Older
1
#!/usr/bin/env bash
Ian Hickson's avatar
Ian Hickson committed
2
# Copyright 2014 The Flutter Authors. All rights reserved.
3 4 5
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

6 7 8
# ---------------------------------- NOTE ---------------------------------- #
#
# Please keep the logic in this file consistent with the logic in the
9 10
# `flutter.bat` script in the same directory to ensure that Flutter continues
# to work across all platforms!
11 12 13
#
# -------------------------------------------------------------------------- #

14 15
set -e

16 17 18 19 20
# To debug the tool, you can uncomment the following lines to enable debug
# mode and set an observatory port:
# FLUTTER_TOOL_ARGS="--enable-asserts $FLUTTER_TOOL_ARGS"
# FLUTTER_TOOL_ARGS="$FLUTTER_TOOL_ARGS --observe=65432"

21
# Needed because if it is set, cd may print the path it changed to.
22 23
unset CDPATH

24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
# On Mac OS, readlink -f doesn't work, so follow_links traverses the path one
# link at a time, and then cds into the link destination and find out where it
# ends up.
#
# The returned filesystem path must be a format usable by Dart's URI parser,
# since the Dart command line tool treats its argument as a file URI, not a
# filename. For instance, multiple consecutive slashes should be reduced to a
# single slash, since double-slashes indicate a URI "authority", and these are
# supposed to be filenames. There is an edge case where this will return
# multiple slashes: when the input resolves to the root directory. However, if
# that were the case, we wouldn't be running this shell, so we don't do anything
# about it.
#
# The function is enclosed in a subshell to avoid changing the working directory
# of the caller.
function follow_links() (
  cd -P "$(dirname -- "$1")"
  file="$PWD/$(basename -- "$1")"
42
  while [[ -h "$file" ]]; do
43 44 45 46
    cd -P "$(dirname -- "$file")"
    file="$(readlink -- "$file")"
    cd -P "$(dirname -- "$file")"
    file="$PWD/$(basename -- "$file")"
47
  done
48 49
  echo "$file"
)
50

51
PROG_NAME="$(follow_links "${BASH_SOURCE[0]}")"
52
BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
53 54
OS="$(uname -s)"

55
# If we're on Windows, invoke the batch script instead to get proper locking.
56
if [[ $OS =~ MINGW.* || $OS =~ CYGWIN.* || $OS =~ MSYS.* ]]; then
57 58
  exec "${BIN_DIR}/flutter.bat" "$@"
fi
59

60
# To define `shared::execute()` function
61
source "$BIN_DIR/internal/shared.sh"
62

63
shared::execute "$@"