Commit 51dc83dd authored by Michael Goderbauer's avatar Michael Goderbauer Committed by GitHub

Launch Flutter Tools on Windows. (#7613)

This brings the Windows script up to par with the Linux/Mac script.

`flutter doctor` works.

There are two scripts (`bin/flutter` and `bin/internal/update_dart-sdk`), which are platform dependent (bash script on Linux/Max, PowerShell script on Windows) and we need to keep an eye on making sure that their logic stays in sync. Both scripts are rather simple and I am not expecting many changes to them. I also made sure that both versions follow the same structure to make it easier to keep them consistent.

Required for https://github.com/flutter/flutter/issues/138
parent 6a612caa
......@@ -3,6 +3,15 @@
# 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
# `flutter.ps1` script in the same directory to ensure that Flutter continues
# to work across all platforms!
#
# -------------------------------------------------------------------------- #
set -e
function follow_links() {
......@@ -35,6 +44,18 @@ SCRIPT_PATH="$FLUTTER_TOOLS_DIR/bin/flutter_tools.dart"
DART_SDK_PATH="$FLUTTER_ROOT/bin/cache/dart-sdk"
DART="$DART_SDK_PATH/bin/dart"
PUB="$DART_SDK_PATH/bin/pub"
# Test if Git is available on the Host
if ! hash git 2>/dev/null; then
echo "Error: Unable to find git in your PATH."
exit 1
fi
# Test if the flutter directory is a git clone (otherwise git rev-parse HEAD would fail)
if [ ! -d "$FLUTTER_ROOT/.git" ]; then
echo "Error: The Flutter directory is not a clone of the GitHub project."
exit 1
fi
# To debug the tool, you can uncomment the following line to enable checked mode and set an observatory port:
# FLUTTER_TOOL_ARGS="--observe=65432 --checked"
......@@ -51,8 +72,7 @@ DART="$DART_SDK_PATH/bin/dart"
"$FLUTTER_ROOT/bin/internal/update_dart_sdk.sh"
echo Building flutter tool...
FLUTTER_DIR="$FLUTTER_ROOT/packages/flutter"
(cd "$FLUTTER_TOOLS_DIR"; rm -f pubspec.lock; "../../bin/cache/dart-sdk/bin/pub" get --verbosity=error --no-packages-dir)
(cd "$FLUTTER_TOOLS_DIR"; rm -f pubspec.lock; "$PUB" get --verbosity=error --no-packages-dir)
"$DART" --snapshot="$SNAPSHOT_PATH" --packages="$FLUTTER_TOOLS_DIR/.packages" "$SCRIPT_PATH"
echo $REVISION > "$STAMP_PATH"
fi
......
@ECHO off
REM Copyright 2015 The Chromium 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.
SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%i IN ("%~dp0..") DO SET "flutter_root=%%~fi" REM Get the parent directory
SET flutter_tools_dir=%flutter_root%\packages\flutter_tools
SET flutter_dir=%flutter_root%\packages\flutter
SET snapshot_path=%flutter_root%\bin\cache\flutter_tools.snapshot
SET stamp_path=%flutter_root%\bin\cache\flutter_tools.stamp
SET script_path=%flutter_tools_dir%\bin\flutter_tools.dart
REM TODO: Don't require dart to be on the user's path
SET dart=dart
REM Set current working directory to the flutter directory
PUSHD %flutter_root%
REM IF doesn't have an "or". Instead, just use GOTO
FOR /f %%r IN ('git rev-parse HEAD') DO SET revision=%%r
IF NOT EXIST %snapshot_path% GOTO do_snapshot
IF NOT EXIST %stamp_path% GOTO do_snapshot
FOR /f "delims=" %%x in (%stamp_path%) do set stamp_value=%%x
IF "!stamp_value!" NEQ "!revision!" GOTO do_snapshot
REM Getting modified timestamps in a batch file is ... troublesome
REM More info: http://stackoverflow.com/questions/1687014/how-do-i-compare-timestamps-of-files-in-a-dos-batch-script
FOR %%f IN (%flutter_tools_dir%\pubspec.yaml) DO SET yamlt=%%~tf
FOR %%a IN (%flutter_tools_dir%\pubspec.lock) DO SET lockt=%%~ta
IF !lockt! LSS !yamlt! GOTO do_snapshot
GOTO :after_snapshot
:do_snapshot
CD "%flutter_tools_dir%"
ECHO Updating flutter tool...
CALL pub.bat get
CD "%flutter_dir%"
REM Allows us to check if sky_engine's REVISION is correct
CALL pub.bat get
CD "%flutter_root%"
CALL %dart% --snapshot="%snapshot_path%" --packages="%flutter_tools_dir%\.packages" "%script_path%"
<nul SET /p=%revision%> "%stamp_path%"
:after_snapshot
REM Go back to last working directory
POPD
CALL %dart% "%snapshot_path%" %*
IF /I "%ERRORLEVEL%" EQU "253" (
CALL %dart% --snapshot="%snapshot_path%" --packages="%flutter_tools_dir%\.packages" "%script_path%"
CALL %dart% "%snapshot_path%" %*
)
# Copyright 2015 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.
# How to use this script:
# - Allow the execution of PowerShell scripts (ByPass, etc.), for example:
# Set-ExecutionPolicy Unrestricted
# - Invoke any flutter command: Flutter.ps1 doctor
# - Force the path to Dart SDK: Flutter.ps1 -DartPath "c:\tools\dart\"
[CmdletBinding()]
param (
[Parameter(Mandatory=$False)]
[string]$DartPath,
[Parameter(Mandatory=$False)]
[switch]$Diag,
[parameter(mandatory=$False, position=1, ValueFromRemainingArguments=$true)]
$Remaining
)
# This function creates a snapshot of the latest version of flutter framework
function Do-Snapshot
{
Set-Location $flutterToolsDir
Write-Host "Info: Updating flutter tool..."
Invoke-Expression "pub.bat get $(&{If($Diag) {"--verbose"}})"
Set-Location $flutterDir
# Allows us to check if sky_engine's REVISION is correct
Write-Host "Info: Updating sky engine..."
Invoke-Expression "pub.bat get $(&{If($Diag) {"--verbose"}})"
Set-Location $flutterRoot
Invoke-Expression "$dartExe --snapshot=`"$snapshotPath`" `"$scriptPath`" --packages=`"$flutterToolsDir\.packages`""
$revision | Out-File $stampPath
}
# Save the current location
Push-Location
# Get the parent directory
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$flutterRoot = (get-item $scriptPath ).parent.FullName
$flutterToolsDir = $flutterRoot + '\packages\flutter_tools'
$flutterDir = $flutterRoot + '\packages\flutter'
$snapshotPath = $flutterRoot + '\bin\cache\flutter_tools.snapshot'
$stampPath = $flutterRoot + '\bin\cache\flutter_tools.stamp'
$scriptPath = $flutterToolsDir + '\bin\flutter_tools.dart'
$dartExe = [io.path]::combine($DartPath, 'dart.exe')
# Set current working directory to the flutter directory
Set-Location $flutterRoot
# Test if Git is available on the Host
if ((Get-Command "git.exe" -ErrorAction SilentlyContinue) -eq $null) {
Write-Host "Error: Unable to find git.exe in your PATH"
Pop-Location
exit
}
# Test if the flutter directory is a git clone (otherwise git rev-parse HEAD would fail)
if (-not (Test-Path '.git')) {
Write-Host "Error: The flutter directory is not a clone of the GH project"
Pop-Location
exit
}
# Test if pub.bat is available on the Host
if ((Get-Command "pub.bat" -ErrorAction SilentlyContinue) -eq $null) {
Write-Host "Error: Unable to find Dart SDK in your PATH"
Pop-Location
exit
}
# Check if the snapshot version is out-of-date.
$revision = Invoke-Expression "git rev-parse HEAD"
if ( (-not (Test-Path $snapshotPath)) -Or (-not (Test-Path $stampPath)) ) {
Write-Host "Info: Snapshot doesn't exist"
Do-Snapshot
}
$stampValue = Get-Content $stampPath | Where-Object {$_ -match '\S'}
if ($stampValue -ne $revision) {
Write-Host "Info: Timestamp differs from revision"
Do-Snapshot
}
$yamltLastWriteTime = (ls "$flutterToolsDir\pubspec.yaml").LastWriteTime
$locktLastWriteTime = (ls "$flutterToolsDir\pubspec.lock").LastWriteTime
if ($locktLastWriteTime -lt $yamltLastWriteTime) {
Write-Host "Info: Mismatch between yaml and lock files"
Do-Snapshot
}
# Go back to last working directory
Pop-Location
Invoke-Expression "$dartExe `"$snapshotPath`" $Remaining"
# The VM exits with code 253 if the snapshot version is out-of-date.
if ($LASTEXITCODE -eq 253) {
Write-Host "Info: VM exited with code 253, we need to snapshot it again."
Invoke-Expression "$dartExe --snapshot=`"$snapshotPath`" `"$scriptPath`" --packages=`"$flutterToolsDir\.packages`""
Invoke-Expression "$dartExe `"$snapshotPath`" $Remaining"
}
# 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
# `flutter` script in the same directory to ensure that Flutter continues to
# work across all platforms!
#
# -------------------------------------------------------------------------- #
$ErrorActionPreference = "Stop"
$progName = split-path -parent $MyInvocation.MyCommand.Definition
$flutterRoot = (get-item $progName ).parent.FullName
$env:FLUTTER_ROOT = $flutterRoot
$flutterToolsDir = "$flutterRoot\packages\flutter_tools"
$snapshotPath = "$flutterRoot\bin\cache\flutter_tools.snapshot"
$stampPath = "$flutterRoot\bin\cache\flutter_tools.stamp"
$scriptPath = "$flutterToolsDir\bin\flutter_tools.dart"
$dartSdkPath = "$flutterRoot\bin\cache\dart-sdk"
$dart = "$dartSdkPath\bin\dart.exe"
$pub = "$dartSdkPath\bin\pub.bat"
# Test if Git is available on the Host
if ((Get-Command "git.exe" -ErrorAction SilentlyContinue) -eq $null) {
Write-Host "Error: Unable to find git.exe in your PATH."
exit
}
# Test if the flutter directory is a git clone (otherwise git rev-parse HEAD would fail)
if (-not (Test-Path "$flutterRoot\.git")) {
Write-Host "Error: The Flutter directory is not a clone of the GitHub project."
exit
}
Push-Location
Set-Location $flutterRoot
$revision = Invoke-Expression "git rev-parse HEAD"
Pop-Location
if (!(Test-Path $snapshotPath) `
-or !(Test-Path $stampPath) `
-or ((Get-Content $stampPath) -ne $revision) `
-or !(Test-Path "$flutterToolsDir\pubspec.lock") `
-or ((ls "$flutterToolsDir\pubspec.lock").LastWriteTime -lt (ls "$flutterToolsDir\pubspec.yaml").LastWriteTime)) {
New-Item "$flutterRoot\bin\cache" -force -type directory | Out-Null
New-Item "$flutterRoot\bin\cache\.dartignore" -force -type file | Out-Null
Invoke-Expression "$flutterRoot\bin\internal\update_dart_sdk.ps1"
Write-Host "Building flutter tool..."
Set-Location $flutterToolsDir
if (Test-Path "$flutterToolsDir\pubspec.lock") { Remove-Item "$flutterToolsDir\pubspec.lock" }
Invoke-Expression "$pub get --verbosity=error --no-packages-dir"
Set-Location $flutterRoot
Invoke-Expression "$dart --snapshot=`"$snapshotPath`" `"$scriptPath`" --packages=`"$flutterToolsDir\.packages`""
$revision | Out-File $stampPath
}
Invoke-Expression "$dart `"$snapshotPath`" $args"
# The VM exits with code 253 if the snapshot version is out-of-date.
if ($LASTEXITCODE -eq 253) {
Invoke-Expression "$dart --snapshot=`"$snapshotPath`" `"$scriptPath`" --packages=`"$flutterToolsDir\.packages`""
Invoke-Expression "$dart `"$snapshotPath`" $args"
}
# 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"
$progName = split-path -parent $MyInvocation.MyCommand.Definition
$flutterRoot = (get-item $progName ).parent.parent.FullName
$dartSdkPath = "$flutterRoot\bin\cache\dart-sdk"
$dartSdkStampPath = "$flutterRoot\bin\cache\dart-sdk.stamp"
$dartSdkVersion = (Get-Content "$flutterRoot\bin\internal\dart-sdk.version")
if ((Test-Path $dartSdkStampPath) -and ($dartSdkVersion -eq (Get-Content $dartSdkStampPath))) {
return
}
Write-Host "Downloading Dart SDK $dartSdkVersion..."
$dartZipName = "dartsdk-windows-x64-release.zip"
$dartChannel = if ($dartSdkVersion.Contains("-dev.")) {"dev"} else {"stable"}
$dartSdkUrl = "https://storage.googleapis.com/dart-archive/channels/$dartChannel/raw/$dartSdkVersion/sdk/$dartZipName"
if (Test-Path $dartSdkPath) { Remove-Item $dartSdkPath -Recurse }
New-Item $dartSdkPath -force -type directory | Out-Null
$dartSdkZip = "$flutterRoot\bin\cache\dart-sdk.zip"
Start-BitsTransfer -Source $dartSdkUrl -Destination $dartSdkZip
Add-Type -assembly "system.io.compression.filesystem"
[io.compression.zipfile]::ExtractToDirectory($dartSdkZip, "$flutterRoot\bin\cache")
Remove-Item $dartSdkZip
$dartSdkVersion | out-file $dartSdkStampPath
......@@ -3,6 +3,15 @@
# 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.ps1` script in the same directory to ensure that Flutter
# continues to work across all platforms!
#
# -------------------------------------------------------------------------- #
set -e
FLUTTER_ROOT="$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")")"
......
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