Skip to content

Commit 18095cd

Browse files
loic-sharmaBuchimi
authored andcommitted
[Windows] Add a flutter-dev script to run the flutter CLI from source (flutter#153892)
Follow-up to flutter#153599, adds support for the objectively better OS �
1 parent f490a03 commit 18095cd

File tree

4 files changed

+78
-4
lines changed

4 files changed

+78
-4
lines changed

bin/flutter

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
# ---------------------------------- NOTE ---------------------------------- #
77
#
88
# Please keep the logic in this file consistent with the logic in the
9-
# `flutter.bat` script in the same directory to ensure that Flutter continues
10-
# to work across all platforms!
9+
# `flutter.bat` script in the same directory to ensure that Flutter
10+
# continues to work across all platforms!
1111
#
1212
# -------------------------------------------------------------------------- #
1313

bin/flutter-dev

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
# Use of this source code is governed by a BSD-style license that can be
44
# found in the LICENSE file.
55

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

816
# This is a helper script for development purposes. It runs the Flutter tool
@@ -50,6 +58,12 @@ PROG_NAME="$(follow_links "${BASH_SOURCE[0]}")"
5058
BIN_DIR="$(cd "${PROG_NAME%/*}" ; pwd -P)"
5159
SHARED_NAME="$BIN_DIR/internal/shared.sh"
5260
FLUTTER_ROOT="$(cd "$BIN_DIR/.." ; pwd -P)"
61+
OS="$(uname -s)"
62+
63+
# If we're on Windows, invoke the batch script instead to get proper locking.
64+
if [[ $OS =~ MINGW.* || $OS =~ CYGWIN.* || $OS =~ MSYS.* ]]; then
65+
exec "${BIN_DIR}/flutter-dev.bat" "$@"
66+
fi
5367

5468
# To define `shared::execute()` function
5569
source "$SHARED_NAME"

bin/flutter-dev.bat

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
@ECHO off
2+
REM Copyright 2014 The Flutter Authors. All rights reserved.
3+
REM Use of this source code is governed by a BSD-style license that can be
4+
REM found in the LICENSE file.
5+
6+
REM ---------------------------------- NOTE ----------------------------------
7+
REM
8+
REM Please keep the logic in this file consistent with the logic in the
9+
REM `flutter-dev` script in the same directory to ensure that Flutter & Dart
10+
REM continue to work across all platforms!
11+
REM
12+
REM --------------------------------------------------------------------------
13+
14+
SETLOCAL
15+
16+
REM This is a helper script for development purposes. It runs the Flutter tool
17+
REM from source code directly, without using the prebuilt snapshot. This is
18+
REM useful for development, as it allows you to make changes to the tool and see
19+
REM the effects immediately, but is much slower than using the prebuilt snapshot.
20+
21+
REM To debug the tool, you can uncomment the following line to enable debug mode:
22+
REM SET FLUTTER_TOOL_ARGS="--enable-asserts %FLUTTER_TOOL_ARGS%"
23+
24+
FOR %%i IN ("%~dp0..") DO SET FLUTTER_ROOT=%%~fi
25+
26+
REM If available, add location of bundled mingit to PATH
27+
SET mingit_path=%FLUTTER_ROOT%\bin\mingit\cmd
28+
IF EXIST "%mingit_path%" SET PATH=%PATH%;%mingit_path%
29+
30+
REM We test if Git is available on the Host as we run git in shared.bat
31+
REM Test if the flutter directory is a git clone, otherwise git rev-parse HEAD would fail
32+
IF NOT EXIST "%flutter_root%\.git" (
33+
ECHO Error: The Flutter directory is not a clone of the GitHub project.
34+
ECHO The flutter tool requires Git in order to operate properly;
35+
ECHO to set up Flutter, run the following command:
36+
ECHO git clone -b stable https://github.com/flutter/flutter.git
37+
EXIT 1
38+
)
39+
40+
REM Include shared scripts in shared.bat
41+
SET shared_bin=%FLUTTER_ROOT%\bin\internal\shared.bat
42+
CALL "%shared_bin%"
43+
44+
SET flutter_tools_dir=%FLUTTER_ROOT%\packages\flutter_tools
45+
SET cache_dir=%FLUTTER_ROOT%\bin\cache
46+
SET script_path=%flutter_tools_dir%\bin\flutter_tools.dart
47+
SET dart_sdk_path=%cache_dir%\dart-sdk
48+
SET dart=%dart_sdk_path%\bin\dart.exe
49+
50+
SET exit_with_errorlevel=%FLUTTER_ROOT%/bin/internal/exit_with_errorlevel.bat
51+
52+
REM Chaining the call to 'dart' and 'exit' with an ampersand ensures that
53+
REM Windows reads both commands into memory once before executing them. This
54+
REM avoids nasty errors that may otherwise occur when the dart command (e.g. as
55+
REM part of 'flutter upgrade') modifies this batch script while it is executing.
56+
REM
57+
REM Do not use the CALL command in the next line to execute Dart. CALL causes
58+
REM Windows to re-read the line from disk after the CALL command has finished
59+
REM regardless of the ampersand chain.
60+
"%dart%" run --resident --packages="%flutter_tools_dir%\.dart_tool\package_config.json" %FLUTTER_TOOL_ARGS% "%script_path%" %* & "%exit_with_errorlevel%"

bin/flutter.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ REM found in the LICENSE file.
66
REM ---------------------------------- NOTE ----------------------------------
77
REM
88
REM Please keep the logic in this file consistent with the logic in the
9-
REM `flutter` script in the same directory to ensure that Flutter & Dart continue to
10-
REM work across all platforms!
9+
REM `flutter` script in the same directory to ensure that Flutter & Dart
10+
REM continue to work across all platforms!
1111
REM
1212
REM --------------------------------------------------------------------------
1313

0 commit comments

Comments
 (0)