Unverified Commit 45e212e7 authored by moko256's avatar moko256 Committed by GitHub

[Windows] Remove the usage of `SETLOCAL ENABLEDELAYEDEXPANSION` from bat scripts. (#106861)

parent d32aa8b2
......@@ -11,7 +11,7 @@ REM work across all platforms!
REM
REM --------------------------------------------------------------------------
SETLOCAL ENABLEDELAYEDEXPANSION
SETLOCAL
FOR %%i IN ("%~dp0..") DO SET FLUTTER_ROOT=%%~fi
......@@ -23,6 +23,8 @@ SET cache_dir=%FLUTTER_ROOT%\bin\cache
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
......@@ -31,4 +33,4 @@ 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%" %* & exit /B !ERRORLEVEL!
"%dart%" %* & "%exit_with_errorlevel%"
......@@ -11,7 +11,7 @@ REM work across all platforms!
REM
REM --------------------------------------------------------------------------
SETLOCAL ENABLEDELAYEDEXPANSION
SETLOCAL
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%"
......@@ -43,6 +43,8 @@ SET snapshot_path=%cache_dir%\flutter_tools.snapshot
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
......@@ -51,4 +53,4 @@ 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%" --disable-dart-dev --packages="%flutter_tools_dir%\.dart_tool\package_config.json" %FLUTTER_TOOL_ARGS% "%snapshot_path%" %* & exit /B !ERRORLEVEL!
"%dart%" --disable-dart-dev --packages="%flutter_tools_dir%\.dart_tool\package_config.json" %FLUTTER_TOOL_ARGS% "%snapshot_path%" %* & "%exit_with_errorlevel%"
@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 A script to exit caller script with the last status code.
REM This can be used with ampersand without `SETLOCAL ENABLEDELAYEDEXPANSION`.
REM
REM To use this script like `exit`, do not use with the CALL command.
REM Without CALL, this script can exit caller script, but with CALL,
REM this script returns back to caller and does not exit caller.
exit /B %ERRORLEVEL%
......@@ -11,7 +11,7 @@ REM work across all platforms!
REM
REM --------------------------------------------------------------------------
SETLOCAL ENABLEDELAYEDEXPANSION
SETLOCAL
SET flutter_tools_dir=%FLUTTER_ROOT%\packages\flutter_tools
SET cache_dir=%FLUTTER_ROOT%\bin\cache
......@@ -84,11 +84,11 @@ GOTO :after_subroutine
IF NOT EXIST "%engine_stamp%" GOTO do_sdk_update_and_snapshot
SET /P dart_required_version=<"%engine_version_path%"
SET /P dart_installed_version=<"%engine_stamp%"
IF !dart_required_version! NEQ !dart_installed_version! GOTO do_sdk_update_and_snapshot
IF %dart_required_version% NEQ %dart_installed_version% GOTO do_sdk_update_and_snapshot
IF NOT EXIST "%snapshot_path%" GOTO do_snapshot
IF NOT EXIST "%stamp_path%" GOTO do_snapshot
SET /P stamp_value=<"%stamp_path%"
IF !stamp_value! NEQ !compilekey! GOTO do_snapshot
IF %stamp_value% NEQ %compilekey% GOTO do_snapshot
SET pubspec_yaml_path=%flutter_tools_dir%\pubspec.yaml
SET pubspec_lock_path=%flutter_tools_dir%\pubspec.lock
FOR /F %%i IN ('DIR /B /O:D "%pubspec_yaml_path%" "%pubspec_lock_path%"') DO SET newer_file=%%i
......@@ -104,7 +104,7 @@ GOTO :after_subroutine
ECHO Checking Dart SDK version... 1>&2
SET update_dart_bin=%FLUTTER_ROOT%\bin\internal\update_dart_sdk.ps1
REM Escape apostrophes from the executable path
SET "update_dart_bin=!update_dart_bin:'=''!"
SET "update_dart_bin=%update_dart_bin:'=''%"
REM PowerShell command must have exit code set in order to prevent all non-zero exit codes from being translated
REM into 1. The exit code 2 is used to detect the case where the major version is incorrect and there should be
REM no subsequent retries.
......
// 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.
// @dart = 2.8
import 'dart:io';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import '../../src/common.dart';
import '../../src/context.dart';
void main() {
setUpAll(() {
Cache.disableLocking();
});
testUsingContext('flutter command can receive `!`, avoiding expansion by cmd.exe', () async {
final String flutterBin = globals.fs.path.join(getFlutterRoot(), 'bin', 'flutter.bat');
final ProcessResult exec = await Process.run(
flutterBin,
<String>[
'!',
],
workingDirectory: Cache.flutterRoot,
);
// If ENABLEDELAYEDEXPANSION is enabled, the argument `!` is removed,
// and flutter runs without any arguments.
expect(exec.exitCode, 64);
expect(exec.stderr, contains('Could not find a command named "!"'));
},
skip: !Platform.isWindows, // [intended] relies on Windows's cmd.exe
);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment