From 1021a52f138b3de0a1bca86323a195ea643f3d2f Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Mon, 31 Aug 2020 11:23:06 -0700 Subject: [PATCH] [flutter_tools] exit script if powershell version detection fails (#64773) --- bin/internal/shared.bat | 8 +++++++- bin/internal/update_dart_sdk.ps1 | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/internal/shared.bat b/bin/internal/shared.bat index bceec2f18f2..d3f148b9657 100644 --- a/bin/internal/shared.bat +++ b/bin/internal/shared.bat @@ -92,7 +92,13 @@ 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:'=''!" - %powershell_executable% -ExecutionPolicy Bypass -Command "Unblock-File -Path '%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. + %powershell_executable% -ExecutionPolicy Bypass -Command "Unblock-File -Path '%update_dart_bin%'; & '%update_dart_bin%'; exit $LASTEXITCODE;" + IF "%ERRORLEVEL%" EQU "2" ( + EXIT 1 + ) IF "%ERRORLEVEL%" NEQ "0" ( ECHO Error: Unable to update Dart SDK. Retrying... timeout /t 5 /nobreak diff --git a/bin/internal/update_dart_sdk.ps1 b/bin/internal/update_dart_sdk.ps1 index d8aaed60b98..26bad4074f4 100644 --- a/bin/internal/update_dart_sdk.ps1 +++ b/bin/internal/update_dart_sdk.ps1 @@ -29,7 +29,9 @@ $psMajorVersionLocal = $PSVersionTable.PSVersion.Major if ($psMajorVersionLocal -lt $psMajorVersionRequired) { Write-Host "Flutter requires PowerShell $psMajorVersionRequired.0 or newer." Write-Host "See https://flutter.dev/docs/get-started/install/windows for more." - return + Write-Host "Current version is $psMajorVersionLocal." + # Use exit code 2 to signal that shared.bat should exit immediately instead of retrying. + exit 2 } if ((Test-Path $engineStamp) -and ($engineVersion -eq (Get-Content $engineStamp))) {