Skip to content

Ensure compatibility with older PowerShell versions and better error handling - #8652

Merged
goderbauer merged 2 commits into
flutter:masterfrom
goderbauer:moreComp
Mar 8, 2017
Merged

goderbauer merged 2 commits into
flutter:masterfrom
goderbauer:moreComp

Conversation

@goderbauer

Copy link
Copy Markdown
Member

This should make our scripts compatible with PowerShell 2 or newer. PowerShell 2 was released in October 2009 and shipped with Windows 7 as default. (I suspect the scripts are now also compatible with PowerShell 1, but that's unconfirmed). This fixes #8606.

The PR also introduces better error handling when Flutter fail to download the Dart SDK to fix #8627.

This should make our scripts compatible with PowerShell 2 or newer. PowerShell 2 was released in October 2009 and shipped with Windows 7 as default.
Comment thread bin/flutter.bat
SET exit_code=%ERRORLEVEL%
IF %exit_code% NEQ 0 (
ECHO Error: Unable to update Dart SDK.
REM Do not use /B here, we want to exit out of the script, not just the subroutine

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you put this comment here but not elsewhere?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only place where it matters: we are inside a subroutine and we want to exit the entire script. In the other places where I removed the /B, it didn't actually change any logic because we weren't in a subroutine (I just removed it to be consistent: in case of error, exit the script).

Expand-Archive $dartSdkZip -DestinationPath $cachePath
if (Get-Command Expand-Archive -errorAction SilentlyContinue) {
# Expand-Archive requires PowerShell 5 or newer
Expand-Archive $dartSdkZip -DestinationPath $cachePath

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we prefer Expand-Archive on newer powershells?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand-Archive is the recommended (and only official) way to expand archives in a PowerShell script. The alternative I provide here for older PowerShells is kinda hacky, as it calls out to the Windows GUI to do the unzipping (it will actually pop up a new GUI window displaying the unzipping status).

@Hixie

Hixie commented Mar 8, 2017

Copy link
Copy Markdown
Contributor

LGTM

@goderbauer

Copy link
Copy Markdown
Member Author

Travis is failing with infrastructure problems unrelated to this PR (this PR doesn't touch any code that executes on Travis).

@goderbauer
goderbauer merged commit e2dccc5 into flutter:master Mar 8, 2017
@goderbauer
goderbauer deleted the moreComp branch March 8, 2017 18:52
@goderbauer goderbauer added the platform-windows Building on or for Windows specifically label Oct 17, 2017
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

platform-windows Building on or for Windows specifically

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flutter doctor on Windows stuck in endless loop when connection is lost. Errors in powershell script update_dart_sdk

3 participants