2017-02-14 18:21:33 +00:00
|
|
|
# Copyright 2017 The Chromium Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------------- NOTE ---------------------------------- #
|
|
|
|
#
|
|
|
|
# Please keep the logic in this file consistent with the logic in the
|
|
|
|
# `update_dart_sdk.sh` script in the same directory to ensure that Flutter
|
|
|
|
# continues to work across all platforms!
|
|
|
|
#
|
|
|
|
# -------------------------------------------------------------------------- #
|
|
|
|
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
|
2017-02-23 20:09:52 +00:00
|
|
|
$progName = Split-Path -parent $MyInvocation.MyCommand.Definition
|
2017-02-24 17:28:58 +00:00
|
|
|
$flutterRoot = (Get-Item $progName).parent.parent.FullName
|
2017-02-14 18:21:33 +00:00
|
|
|
|
2017-02-24 17:28:58 +00:00
|
|
|
$cachePath = "$flutterRoot\bin\cache"
|
|
|
|
$dartSdkPath = "$cachePath\dart-sdk"
|
|
|
|
$dartSdkStampPath = "$cachePath\dart-sdk.stamp"
|
2017-02-14 18:21:33 +00:00
|
|
|
$dartSdkVersion = (Get-Content "$flutterRoot\bin\internal\dart-sdk.version")
|
|
|
|
|
2017-02-24 17:28:58 +00:00
|
|
|
$oldDartSdkPrefix = "dart-sdk.old"
|
|
|
|
|
2017-02-14 18:21:33 +00:00
|
|
|
if ((Test-Path $dartSdkStampPath) -and ($dartSdkVersion -eq (Get-Content $dartSdkStampPath))) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
Write-Host "Downloading Dart SDK $dartSdkVersion..."
|
|
|
|
$dartZipName = "dartsdk-windows-x64-release.zip"
|
2017-06-13 15:28:16 +00:00
|
|
|
$dartChannel = if ($dartSdkVersion.Contains("-dev.")) {"dev"} else {if ($dartSdkVersion.Contains("hash/")) {"be"} else {"stable"}}
|
2017-02-14 18:21:33 +00:00
|
|
|
$dartSdkUrl = "https://storage.googleapis.com/dart-archive/channels/$dartChannel/raw/$dartSdkVersion/sdk/$dartZipName"
|
|
|
|
|
2017-02-24 17:28:58 +00:00
|
|
|
if (Test-Path $dartSdkPath) {
|
|
|
|
# Move old SDK to a new location instead of deleting it in case it is still in use (e.g. by IntelliJ).
|
|
|
|
$oldDartSdkSuffix = 1
|
|
|
|
while (Test-Path "$cachePath\$oldDartSdkPrefix$oldDartSdkSuffix") { $oldDartSdkSuffix++ }
|
|
|
|
Rename-Item $dartSdkPath "$oldDartSdkPrefix$oldDartSdkSuffix"
|
|
|
|
}
|
2017-02-14 18:21:33 +00:00
|
|
|
New-Item $dartSdkPath -force -type directory | Out-Null
|
2017-02-24 17:28:58 +00:00
|
|
|
$dartSdkZip = "$cachePath\dart-sdk.zip"
|
2017-07-19 19:05:30 +00:00
|
|
|
# TODO(goderbauer): remove (slow and backwards-incompatible) appveyor work around
|
|
|
|
if (Test-Path Env:\APPVEYOR) {
|
|
|
|
curl $dartSdkUrl -OutFile $dartSdkZip
|
|
|
|
} else {
|
|
|
|
Import-Module BitsTransfer
|
|
|
|
Start-BitsTransfer -Source $dartSdkUrl -Destination $dartSdkZip
|
|
|
|
}
|
2017-03-07 23:00:01 +00:00
|
|
|
|
|
|
|
Write-Host "Unzipping Dart SDK..."
|
2017-03-10 23:21:08 +00:00
|
|
|
If (Get-Command 7z -errorAction SilentlyContinue) {
|
|
|
|
# The built-in unzippers are painfully slow. Use 7-Zip, if available.
|
|
|
|
& 7z x $dartSdkZip -o"$cachePath" -bd | Out-Null
|
|
|
|
} ElseIf (Get-Command Expand-Archive -errorAction SilentlyContinue) {
|
|
|
|
# Use PowerShell's built-in unzipper, if available (requires PowerShell 5+).
|
2017-03-08 18:52:07 +00:00
|
|
|
Expand-Archive $dartSdkZip -DestinationPath $cachePath
|
2017-03-10 23:21:08 +00:00
|
|
|
} Else {
|
|
|
|
# As last resort: fall back to the Windows GUI.
|
2017-03-08 18:52:07 +00:00
|
|
|
$shell = New-Object -com shell.application
|
|
|
|
$zip = $shell.NameSpace($dartSdkZip)
|
|
|
|
foreach($item in $zip.items()) {
|
|
|
|
$shell.Namespace($cachePath).copyhere($item)
|
|
|
|
}
|
|
|
|
}
|
2017-03-07 23:00:01 +00:00
|
|
|
|
2017-02-14 18:21:33 +00:00
|
|
|
Remove-Item $dartSdkZip
|
2017-02-23 20:09:52 +00:00
|
|
|
$dartSdkVersion | Out-File $dartSdkStampPath -Encoding ASCII
|
2017-02-24 17:28:58 +00:00
|
|
|
|
|
|
|
# Try to delete all old SDKs.
|
|
|
|
Get-ChildItem -Path $cachePath | Where {$_.BaseName.StartsWith($oldDartSdkPrefix)} | Remove-Item -Recurse -ErrorAction SilentlyContinue
|