From 91dde9074a62a2cad696497a857b374b96e261c0 Mon Sep 17 00:00:00 2001 From: Michael Goderbauer Date: Tue, 28 Aug 2018 09:37:34 -0700 Subject: [PATCH] No more nasty errors during flutter upgrade/channel on Windows (#21085) Fixes https://github.com/flutter/flutter/issues/14578. --- bin/flutter | 12 ------------ bin/flutter.bat | 27 +++++++++++---------------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/bin/flutter b/bin/flutter index e7cf407ba8..767dbf93d6 100755 --- a/bin/flutter +++ b/bin/flutter @@ -172,18 +172,6 @@ fi (upgrade_flutter) 3< "$PROG_NAME" -set +e # FLUTTER_TOOL_ARGS isn't quoted below, because it is meant to be considered as # separate space-separated args. "$DART" $FLUTTER_TOOL_ARGS "$SNAPSHOT_PATH" "$@" - -# The VM exits with code 253 if the snapshot version is out-of-date. -# If it is, we need to snapshot it again. -EXIT_CODE=$? -if [[ $EXIT_CODE != 253 ]]; then - exit $EXIT_CODE -fi - -set -e -"$DART" --snapshot="$SNAPSHOT_PATH" --packages="$FLUTTER_TOOLS_DIR/.packages" "$SCRIPT_PATH" -"$DART" $FLUTTER_TOOL_ARGS "$SNAPSHOT_PATH" "$@" diff --git a/bin/flutter.bat b/bin/flutter.bat index 43af48be67..905b384f77 100644 --- a/bin/flutter.bat +++ b/bin/flutter.bat @@ -103,7 +103,7 @@ GOTO :after_subroutine 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:'=''!" - CALL PowerShell.exe -ExecutionPolicy Bypass -Command "Unblock-File -Path '%update_dart_bin%'; & '%update_dart_bin%'" + PowerShell.exe -ExecutionPolicy Bypass -Command "Unblock-File -Path '%update_dart_bin%'; & '%update_dart_bin%'" IF "%ERRORLEVEL%" NEQ "0" ( ECHO Error: Unable to update Dart SDK. Retrying... timeout /t 5 /nobreak @@ -153,7 +153,7 @@ GOTO :after_subroutine POPD - CALL "%dart%" --snapshot="%snapshot_path%" --packages="%flutter_tools_dir%\.packages" "%script_path%" + "%dart%" --snapshot="%snapshot_path%" --packages="%flutter_tools_dir%\.packages" "%script_path%" IF "%ERRORLEVEL%" NEQ "0" ( ECHO Error: Unable to create dart snapshot for flutter tool. SET exit_code=%ERRORLEVEL% @@ -166,20 +166,15 @@ GOTO :after_subroutine :after_subroutine -CALL "%dart%" %FLUTTER_TOOL_ARGS% "%snapshot_path%" %* -SET exit_code=%ERRORLEVEL% - -REM The VM exits with code 253 if the snapshot version is out-of-date. -IF "%exit_code%" EQU "253" ( - CALL "%dart%" --snapshot="%snapshot_path%" --packages="%flutter_tools_dir%\.packages" "%script_path%" - SET exit_code=%ERRORLEVEL% - IF "%exit_code%" EQU "253" ( - ECHO Error: Unable to create dart snapshot for flutter tool. - EXIT /B %exit_code% - ) - CALL "%dart%" %FLUTTER_TOOL_ARGS% "%snapshot_path%" %* - SET exit_code=%ERRORLEVEL% -) +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 occure 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%" %FLUTTER_TOOL_ARGS% "%snapshot_path%" %* & exit /B !ERRORLEVEL! :final_exit EXIT /B %exit_code%