diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000000..31fda4bf1c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,25 @@ +# Auto detect text files and perform LF normalization +* text=auto + +# Always perform LF normalization on these files +*.dart text +*.gradle text +*.html text +*.java text +*.json text +*.md text +*.py text +*.sh text +*.txt text +*.xml text +*.yaml text + +# Make sure that these Windows files always have CRLF line endings in checkout +*.bat text eol=crlf +*.ps1 text eol=crlf + +# Never perform LF normalization on these files +*.ico binary +*.jar binary +*.png binary +*.zip binary diff --git a/bin/internal/update_dart_sdk.ps1 b/bin/internal/update_dart_sdk.ps1 index 7864bfce64..8481911c35 100644 --- a/bin/internal/update_dart_sdk.ps1 +++ b/bin/internal/update_dart_sdk.ps1 @@ -1,40 +1,40 @@ -# 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 +# 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 diff --git a/dev/bots/VERSION_WIN_SDK b/dev/bots/VERSION_WIN_SDK index 66b7f5b7ea..0ca540a64f 100644 --- a/dev/bots/VERSION_WIN_SDK +++ b/dev/bots/VERSION_WIN_SDK @@ -1 +1 @@ -e5715e2cc0d5644a241a4b3281bfada92bc145c2 +e5715e2cc0d5644a241a4b3281bfada92bc145c2 diff --git a/dev/bots/test.dart b/dev/bots/test.dart index ca445f1539..964d5b04c3 100644 --- a/dev/bots/test.dart +++ b/dev/bots/test.dart @@ -1,167 +1,167 @@ -import 'dart:io'; -import 'dart:async'; - -import 'package:path/path.dart' as p; - -String flutterRoot = p.dirname(p.dirname(p.dirname(p.fromUri(Platform.script)))); -String flutter = p.join(flutterRoot, 'bin', Platform.isWindows ? 'flutter.bat' : 'flutter'); -String dart = p.join(flutterRoot, 'bin', 'cache', 'dart-sdk', 'bin', Platform.isWindows ? 'dart.exe' : 'dart'); -String flutterTestArgs = Platform.environment['FLUTTER_TEST_ARGS']; - -/// When you call this, you can set FLUTTER_TEST_ARGS to pass custom -/// arguments to flutter test. For example, you might want to call this -/// script using FLUTTER_TEST_ARGS=--local-engine=host_debug_unopt to -/// use your own build of the engine. -Future main() async { - // Analyze all the Dart code in the repo. - await _runFlutterAnalyze(flutterRoot, - options: ['--flutter-repo'], - ); - - // Verify that the tests actually return failure on failure and success on success. - String automatedTests = p.join(flutterRoot, 'dev', 'automated_tests'); - await _runFlutterTest(automatedTests, - script: p.join('test_smoke_test', 'fail_test.dart'), - expectFailure: true, - printOutput: false, - ); - await _runFlutterTest(automatedTests, - script: p.join('test_smoke_test', 'pass_test.dart'), - printOutput: false, - ); - await _runFlutterTest(automatedTests, - script: p.join('test_smoke_test', 'crash1_test.dart'), - expectFailure: true, - printOutput: false, - ); - await _runFlutterTest(automatedTests, - script: p.join('test_smoke_test', 'crash2_test.dart'), - expectFailure: true, - printOutput: false, - ); - await _runFlutterTest(automatedTests, - script: p.join('test_smoke_test', 'syntax_error_test.broken_dart'), - expectFailure: true, - printOutput: false, - ); - await _runFlutterTest(automatedTests, - script: p.join('test_smoke_test', 'missing_import_test.broken_dart'), - expectFailure: true, - printOutput: false, - ); - await _runCmd(flutter, ['drive', '--use-existing-app', '-t', p.join('test_driver', 'failure.dart')], - workingDirectory: p.join(flutterRoot, 'packages', 'flutter_driver'), - expectFailure: true, - printOutput: false, - skip: Platform.isWindows, // TODO(goderbauer): run on Windows when 'drive' command works - ); - - List coverageFlags = []; - if (Platform.environment['TRAVIS'] != null && Platform.environment['TRAVIS_PULL_REQUEST'] == 'false') - coverageFlags.add('--coverage'); - - // Run tests. - await _runFlutterTest(p.join(flutterRoot, 'packages', 'flutter'), - options: coverageFlags, - ); - await _runAllDartTests(p.join(flutterRoot, 'packages', 'flutter_driver')); - await _runFlutterTest(p.join(flutterRoot, 'packages', 'flutter_test')); - await _runFlutterTest(p.join(flutterRoot, 'packages', 'flutter_markdown')); - await _runAllDartTests(p.join(flutterRoot, 'packages', 'flutter_tools'), - environment: { 'FLUTTER_ROOT': flutterRoot }, - ); - - await _runAllDartTests(p.join(flutterRoot, 'dev', 'devicelab')); - await _runFlutterTest(p.join(flutterRoot, 'dev', 'manual_tests')); - await _runFlutterTest(p.join(flutterRoot, 'examples', 'hello_world')); - await _runFlutterTest(p.join(flutterRoot, 'examples', 'layers')); - await _runFlutterTest(p.join(flutterRoot, 'examples', 'stocks')); - await _runFlutterTest(p.join(flutterRoot, 'examples', 'flutter_gallery')); - - await _runCmd(dart, [p.join(flutterRoot, 'dev', 'tools', 'mega_gallery.dart')], - workingDirectory: flutterRoot, - ); - await _runFlutterAnalyze(p.join(flutterRoot, 'dev', 'benchmarks', 'mega_gallery'), - options: ['--watch', '--benchmark'], - ); - - print('\x1B[32mDONE: All tests successful.\x1B[0m'); -} - -Future _runCmd(String executable, List arguments, { - String workingDirectory, - Map environment, - bool expectFailure: false, - bool printOutput: true, - bool skip: false, -}) async { - String cmd = '${p.relative(executable)} ${arguments.join(' ')}'; - String relativeWorkingDir = p.relative(workingDirectory); - if (skip) { - _printProgress('SKIPPING', relativeWorkingDir, cmd); - return null; - } - _printProgress('RUNNING', relativeWorkingDir, cmd); - - Process process = await Process.start(executable, arguments, - workingDirectory: workingDirectory, - environment: environment, - ); - - if (printOutput) { - stdout.addStream(process.stdout); - stderr.addStream(process.stderr); - } - - int exitCode = await process.exitCode; - if ((exitCode == 0) == expectFailure) { - print( - '\x1B[31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1B[0m\n' - '\x1B[1mERROR:\x1B[31m Last command exited with $exitCode (expected: ${expectFailure ? 'non-zero' : 'zero'}).\x1B[0m\n' - '\x1B[31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1B[0m' - ); - exit(1); - } -} - -Future _runFlutterTest(String workingDirectory, { - String script, - bool expectFailure: false, - bool printOutput: true, - List options: const [], - bool skip: false, -}) { - List args = ['test']..addAll(options); - if (flutterTestArgs != null) - args.add(flutterTestArgs); - if (script != null) - args.add(script); - return _runCmd(flutter, args, - workingDirectory: workingDirectory, - expectFailure: expectFailure, - printOutput: printOutput, - skip: skip || Platform.isWindows, // TODO(goderbauer): run on Windows when sky_shell is available - ); -} - -Future _runAllDartTests(String workingDirectory, { - Map environment, -}) { - List args = ['--checked', p.join('test', 'all.dart')]; - return _runCmd(dart, args, - workingDirectory: workingDirectory, - environment: environment, - ); -} - -Future _runFlutterAnalyze(String workingDirectory, { - List options: const [] -}) { - return _runCmd(flutter, ['analyze']..addAll(options), - workingDirectory: workingDirectory, - ); -} - -void _printProgress(String action, String workingDir, String cmd) { - print('>>> $action in \x1B[36m$workingDir\x1B[0m: \x1B[33m$cmd\x1B[0m'); -} +import 'dart:io'; +import 'dart:async'; + +import 'package:path/path.dart' as p; + +String flutterRoot = p.dirname(p.dirname(p.dirname(p.fromUri(Platform.script)))); +String flutter = p.join(flutterRoot, 'bin', Platform.isWindows ? 'flutter.bat' : 'flutter'); +String dart = p.join(flutterRoot, 'bin', 'cache', 'dart-sdk', 'bin', Platform.isWindows ? 'dart.exe' : 'dart'); +String flutterTestArgs = Platform.environment['FLUTTER_TEST_ARGS']; + +/// When you call this, you can set FLUTTER_TEST_ARGS to pass custom +/// arguments to flutter test. For example, you might want to call this +/// script using FLUTTER_TEST_ARGS=--local-engine=host_debug_unopt to +/// use your own build of the engine. +Future main() async { + // Analyze all the Dart code in the repo. + await _runFlutterAnalyze(flutterRoot, + options: ['--flutter-repo'], + ); + + // Verify that the tests actually return failure on failure and success on success. + String automatedTests = p.join(flutterRoot, 'dev', 'automated_tests'); + await _runFlutterTest(automatedTests, + script: p.join('test_smoke_test', 'fail_test.dart'), + expectFailure: true, + printOutput: false, + ); + await _runFlutterTest(automatedTests, + script: p.join('test_smoke_test', 'pass_test.dart'), + printOutput: false, + ); + await _runFlutterTest(automatedTests, + script: p.join('test_smoke_test', 'crash1_test.dart'), + expectFailure: true, + printOutput: false, + ); + await _runFlutterTest(automatedTests, + script: p.join('test_smoke_test', 'crash2_test.dart'), + expectFailure: true, + printOutput: false, + ); + await _runFlutterTest(automatedTests, + script: p.join('test_smoke_test', 'syntax_error_test.broken_dart'), + expectFailure: true, + printOutput: false, + ); + await _runFlutterTest(automatedTests, + script: p.join('test_smoke_test', 'missing_import_test.broken_dart'), + expectFailure: true, + printOutput: false, + ); + await _runCmd(flutter, ['drive', '--use-existing-app', '-t', p.join('test_driver', 'failure.dart')], + workingDirectory: p.join(flutterRoot, 'packages', 'flutter_driver'), + expectFailure: true, + printOutput: false, + skip: Platform.isWindows, // TODO(goderbauer): run on Windows when 'drive' command works + ); + + List coverageFlags = []; + if (Platform.environment['TRAVIS'] != null && Platform.environment['TRAVIS_PULL_REQUEST'] == 'false') + coverageFlags.add('--coverage'); + + // Run tests. + await _runFlutterTest(p.join(flutterRoot, 'packages', 'flutter'), + options: coverageFlags, + ); + await _runAllDartTests(p.join(flutterRoot, 'packages', 'flutter_driver')); + await _runFlutterTest(p.join(flutterRoot, 'packages', 'flutter_test')); + await _runFlutterTest(p.join(flutterRoot, 'packages', 'flutter_markdown')); + await _runAllDartTests(p.join(flutterRoot, 'packages', 'flutter_tools'), + environment: { 'FLUTTER_ROOT': flutterRoot }, + ); + + await _runAllDartTests(p.join(flutterRoot, 'dev', 'devicelab')); + await _runFlutterTest(p.join(flutterRoot, 'dev', 'manual_tests')); + await _runFlutterTest(p.join(flutterRoot, 'examples', 'hello_world')); + await _runFlutterTest(p.join(flutterRoot, 'examples', 'layers')); + await _runFlutterTest(p.join(flutterRoot, 'examples', 'stocks')); + await _runFlutterTest(p.join(flutterRoot, 'examples', 'flutter_gallery')); + + await _runCmd(dart, [p.join(flutterRoot, 'dev', 'tools', 'mega_gallery.dart')], + workingDirectory: flutterRoot, + ); + await _runFlutterAnalyze(p.join(flutterRoot, 'dev', 'benchmarks', 'mega_gallery'), + options: ['--watch', '--benchmark'], + ); + + print('\x1B[32mDONE: All tests successful.\x1B[0m'); +} + +Future _runCmd(String executable, List arguments, { + String workingDirectory, + Map environment, + bool expectFailure: false, + bool printOutput: true, + bool skip: false, +}) async { + String cmd = '${p.relative(executable)} ${arguments.join(' ')}'; + String relativeWorkingDir = p.relative(workingDirectory); + if (skip) { + _printProgress('SKIPPING', relativeWorkingDir, cmd); + return null; + } + _printProgress('RUNNING', relativeWorkingDir, cmd); + + Process process = await Process.start(executable, arguments, + workingDirectory: workingDirectory, + environment: environment, + ); + + if (printOutput) { + stdout.addStream(process.stdout); + stderr.addStream(process.stderr); + } + + int exitCode = await process.exitCode; + if ((exitCode == 0) == expectFailure) { + print( + '\x1B[31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1B[0m\n' + '\x1B[1mERROR:\x1B[31m Last command exited with $exitCode (expected: ${expectFailure ? 'non-zero' : 'zero'}).\x1B[0m\n' + '\x1B[31m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\x1B[0m' + ); + exit(1); + } +} + +Future _runFlutterTest(String workingDirectory, { + String script, + bool expectFailure: false, + bool printOutput: true, + List options: const [], + bool skip: false, +}) { + List args = ['test']..addAll(options); + if (flutterTestArgs != null) + args.add(flutterTestArgs); + if (script != null) + args.add(script); + return _runCmd(flutter, args, + workingDirectory: workingDirectory, + expectFailure: expectFailure, + printOutput: printOutput, + skip: skip || Platform.isWindows, // TODO(goderbauer): run on Windows when sky_shell is available + ); +} + +Future _runAllDartTests(String workingDirectory, { + Map environment, +}) { + List args = ['--checked', p.join('test', 'all.dart')]; + return _runCmd(dart, args, + workingDirectory: workingDirectory, + environment: environment, + ); +} + +Future _runFlutterAnalyze(String workingDirectory, { + List options: const [] +}) { + return _runCmd(flutter, ['analyze']..addAll(options), + workingDirectory: workingDirectory, + ); +} + +void _printProgress(String action, String workingDir, String cmd) { + print('>>> $action in \x1B[36m$workingDir\x1B[0m: \x1B[33m$cmd\x1B[0m'); +}