flutter_flutter/bin/flutter-dev.bat
Loïc PÉRON c087fb36be
windows: allow pwsh.bat wrapper (#171778)
After git clone flutter/flutter, flutter commands require the use of
powershell to run ps1 scripts. On my corporate workstation, I need to
use a pwsh.bat wrapper to run ps1 scripts.

This PR uses `pwsh` instead of `pwsh.exe` to find and use a bat wrapper
from the path if present.

Closes https://github.com/flutter/flutter/issues/171777.

## Pre-launch Checklist

- [X] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [X] I read the [Tree Hygiene] wiki page, which explains my
responsibilities.
- [X] I read and followed the [Flutter Style Guide], including [Features
we expect every widget to implement].
- [X] I signed the [CLA].
- [X] I listed at least one issue that this PR fixes in the description
above.
- [ ] I updated/added relevant documentation (doc comments with `///`).
- [ ] I added new tests to check the change I am making, or this PR is
[test-exempt].
- [ ] I followed the [breaking change policy] and added [Data Driven
Fixes] where supported.
- [ ] All existing and new tests are passing.
2025-07-25 21:36:21 +00:00

80 lines
3.3 KiB
Batchfile

@ECHO off
REM Copyright 2014 The Flutter Authors. All rights reserved.
REM Use of this source code is governed by a BSD-style license that can be
REM found in the LICENSE file.
REM ---------------------------------- NOTE ----------------------------------
REM
REM Please keep the logic in this file consistent with the logic in the
REM `flutter-dev` script in the same directory to ensure that Flutter & Dart
REM continue to work across all platforms!
REM
REM --------------------------------------------------------------------------
SETLOCAL
REM This is a helper script for development purposes. It runs the Flutter tool
REM from source code directly, without using the prebuilt snapshot. This is
REM useful for development, as it allows you to make changes to the tool and see
REM the effects immediately, but is much slower than using the prebuilt snapshot.
REM To debug the tool, you can uncomment the following line to enable debug mode:
REM SET FLUTTER_TOOL_ARGS="--enable-asserts %FLUTTER_TOOL_ARGS%"
FOR %%i IN ("%~dp0..") DO SET FLUTTER_ROOT=%%~fi
REM If available, add location of bundled mingit to PATH
SET mingit_path=%FLUTTER_ROOT%\bin\mingit\cmd
IF EXIST "%mingit_path%" SET PATH=%PATH%;%mingit_path%
REM Test if Git is available on the host
WHERE /Q git
IF "%ERRORLEVEL%" NEQ "0" (
ECHO Error: Unable to find git in your PATH.
EXIT /B 1
)
REM Detect which PowerShell executable is available on the host
REM PowerShell version <= 5: PowerShell.exe
REM PowerShell version >= 6: pwsh.exe
WHERE /Q pwsh && (
SET "powershell_executable=call pwsh"
) || WHERE /Q PowerShell.exe && (
SET powershell_executable=PowerShell.exe
) || (
ECHO Error: PowerShell executable not found. 1>&2
ECHO Either pwsh.exe or PowerShell.exe must be in your PATH. 1>&2
EXIT /B 1
)
REM Test if the flutter directory is a git clone, otherwise git rev-parse HEAD would fail
IF NOT EXIST "%flutter_root%\.git" (
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
)
REM Include shared scripts in shared.bat
SET shared_bin=%FLUTTER_ROOT%\bin\internal\shared.bat
CALL "%shared_bin%"
SET flutter_tools_dir=%FLUTTER_ROOT%\packages\flutter_tools
SET cache_dir=%FLUTTER_ROOT%\bin\cache
SET script_path=%flutter_tools_dir%\bin\flutter_tools.dart
SET dart_sdk_path=%cache_dir%\dart-sdk
SET dart=%dart_sdk_path%\bin\dart.exe
SET exit_with_errorlevel=%FLUTTER_ROOT%/bin/internal/exit_with_errorlevel.bat
REM Chaining the call to 'dart' and 'exit' with an ampersand ensures that
REM Windows reads both commands into memory once before executing them. This
REM avoids nasty errors that may otherwise occur when the dart command (e.g. as
REM part of 'flutter upgrade') modifies this batch script while it is executing.
REM
REM Do not use the CALL command in the next line to execute Dart. CALL causes
REM Windows to re-read the line from disk after the CALL command has finished
REM regardless of the ampersand chain.
"%dart%" run --resident --packages="%flutter_tools_dir%\.dart_tool\package_config.json" %FLUTTER_TOOL_ARGS% "%script_path%" %* & "%exit_with_errorlevel%"