Add a bin/flutter-dev
script, for running the flutter
command-line tool from source (#153599)
Not so long ago I remember a very informal conversation that went something like this: > @matanlurey: I wish I could pass `--dev` or something to `flutter` to run from source. > > @christopherfujino: I get what you want, but I don't want to overload the tool with more dev-only things. I would consider a script like `flutter-dev` that does that thing, though. > > @matanlurey: Cool, I might send a PR! So uh, here it is 6-9 months later. Suggestions welcome.
This commit is contained in:
parent
b74fa8afc7
commit
f0a37e70e5
58
bin/flutter-dev
Executable file
58
bin/flutter-dev
Executable file
@ -0,0 +1,58 @@
|
||||
#!/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.
|
||||
|
||||
set -e
|
||||
|
||||
# This is a helper script for development purposes. It runs the Flutter tool
|
||||
# from source code directly, without using the prebuilt snapshot. This is
|
||||
# useful for development, as it allows you to make changes to the tool and see
|
||||
# the effects immediately, but is much slower than using the prebuilt snapshot.
|
||||
|
||||
# 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"
|
||||
|
||||
# Needed because if it is set, cd may print the path it changed to.
|
||||
unset CDPATH
|
||||
|
||||
# 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")"
|
||||
while [[ -h "$file" ]]; do
|
||||
cd -P "$(dirname -- "$file")"
|
||||
file="$(readlink -- "$file")"
|
||||
cd -P "$(dirname -- "$file")"
|
||||
file="$PWD/$(basename -- "$file")"
|
||||
done
|
||||
echo "$file"
|
||||
)
|
||||
|
||||
# Lookup the parent directory of the script (../), the Flutter SDK root.
|
||||
PROG_NAME="$(follow_links "${BASH_SOURCE[0]}")"
|
||||
BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
|
||||
SHARED_NAME="$BIN_DIR/internal/shared.sh"
|
||||
FLUTTER_ROOT="$(cd "$BIN_DIR/.." ; pwd -P)"
|
||||
|
||||
# To define `shared::execute()` function
|
||||
source "$SHARED_NAME"
|
||||
|
||||
# Run the Flutter tool directly without using the cached snapshot.
|
||||
shared::execute "$@"
|
@ -143,7 +143,7 @@ function upgrade_flutter () (
|
||||
touch "$FLUTTER_ROOT/bin/cache/.dartignore"
|
||||
"$FLUTTER_ROOT/bin/internal/update_dart_sdk.sh"
|
||||
|
||||
if [[ "$BIN_NAME" == 'dart' ]]; then
|
||||
if [[ "$BIN_NAME" == 'dart' || "$BIN_NAME" == 'flutter-dev' ]]; then
|
||||
# Don't try to build tool
|
||||
return
|
||||
fi
|
||||
@ -259,6 +259,11 @@ function shared::execute() {
|
||||
# considered as separate space-separated args.
|
||||
exec "$DART" --disable-dart-dev --packages="$FLUTTER_TOOLS_DIR/.dart_tool/package_config.json" $FLUTTER_TOOL_ARGS "$SNAPSHOT_PATH" "$@"
|
||||
;;
|
||||
flutter-dev*)
|
||||
# FLUTTER_TOOL_ARGS aren't quoted below, because it is meant to be
|
||||
# considered as separate space-separated args.
|
||||
exec "$DART" --packages="$FLUTTER_TOOLS_DIR/.dart_tool/package_config.json" $FLUTTER_TOOL_ARGS "$SCRIPT_PATH" "$@"
|
||||
;;
|
||||
dart*)
|
||||
exec "$DART" "$@"
|
||||
;;
|
||||
|
@ -2216,6 +2216,7 @@ Future<CommandResult> _runFlutterAnalyze(String workingDirectory, {
|
||||
const Set<String> kExecutableAllowlist = <String>{
|
||||
'bin/dart',
|
||||
'bin/flutter',
|
||||
'bin/flutter-dev',
|
||||
'bin/internal/update_dart_sdk.sh',
|
||||
|
||||
'dev/bots/accept_android_sdk_licenses.sh',
|
||||
|
@ -26,6 +26,11 @@ $ dart bin/flutter_tools.dart
|
||||
```
|
||||
followed by command-line arguments, as usual.
|
||||
|
||||
As a convenience, you can also use the `bin/flutter-dev` script:
|
||||
```shell
|
||||
# Assuming flutter/bin is on your PATH
|
||||
$ flutter-dev
|
||||
```
|
||||
|
||||
### Running the analyzer
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user