From a50b465c99477c3cdc2068cfbdd0455bf42b6501 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Fri, 19 Jan 2018 06:17:28 -0800 Subject: [PATCH] Add --preview-dart-2 to 'flutter test' (#14135) --- .../flutter_tools/lib/src/commands/test.dart | 4 +++ packages/flutter_tools/lib/src/compile.dart | 13 +++++---- .../lib/src/test/flutter_platform.dart | 28 +++++++++++++++++-- .../flutter_tools/lib/src/test/runner.dart | 2 ++ 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/packages/flutter_tools/lib/src/commands/test.dart b/packages/flutter_tools/lib/src/commands/test.dart index cc47249edc0..d53ebe56e93 100644 --- a/packages/flutter_tools/lib/src/commands/test.dart +++ b/packages/flutter_tools/lib/src/commands/test.dart @@ -68,6 +68,9 @@ class TestCommand extends FlutterCommand { negatable: false, help: 'Handle machine structured JSON command input\n' 'and provide output and progress in machine friendly format.'); + argParser.addFlag('preview-dart-2', + hide: !verboseHelp, + help: 'Preview Dart 2.0 functionality.'); } @override @@ -206,6 +209,7 @@ class TestCommand extends FlutterCommand { startPaused: startPaused, ipv6: argResults['ipv6'], machine: machine, + previewDart2: argResults['preview-dart-2'], ); if (collector != null) { diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart index 74b7af32ef0..6380c6bab1a 100644 --- a/packages/flutter_tools/lib/src/compile.dart +++ b/packages/flutter_tools/lib/src/compile.dart @@ -62,7 +62,8 @@ Future compile( bool aot : false, bool strongMode : false, List extraFrontEndOptions, - String incrementalCompilerByteStorePath}) async { + String incrementalCompilerByteStorePath, + String packagesPath}) async { final String frontendServer = artifacts.getArtifactPath( Artifact.frontendServerSnapshotForEngineDartSdk ); @@ -85,12 +86,12 @@ Future compile( command.add('--strong'); } if (incrementalCompilerByteStorePath != null) { - command.addAll([ - '--incremental', - '--byte-store', - incrementalCompilerByteStorePath]); - fs.directory(incrementalCompilerByteStorePath).createSync(recursive: true); + command.add('--incremental'); } + if (packagesPath != null) { + command.addAll(['--packages', packagesPath]); + } + if (extraFrontEndOptions != null) command.addAll(extraFrontEndOptions); command.add(mainPath); diff --git a/packages/flutter_tools/lib/src/test/flutter_platform.dart b/packages/flutter_tools/lib/src/test/flutter_platform.dart index 86f5bf13757..4a533144189 100644 --- a/packages/flutter_tools/lib/src/test/flutter_platform.dart +++ b/packages/flutter_tools/lib/src/test/flutter_platform.dart @@ -5,6 +5,8 @@ import 'dart:async'; import 'dart:convert'; +import 'package:flutter_tools/src/artifacts.dart'; +import 'package:flutter_tools/src/compile.dart'; import 'package:meta/meta.dart'; import 'package:stream_channel/stream_channel.dart'; @@ -56,6 +58,7 @@ void installHook({ bool enableObservatory: false, bool machine: false, bool startPaused: false, + bool previewDart2: false, int observatoryPort, InternetAddressType serverType: InternetAddressType.IP_V4, }) { @@ -71,6 +74,7 @@ void installHook({ startPaused: startPaused, explicitObservatoryPort: observatoryPort, host: _kHosts[serverType], + previewDart2: previewDart2, ), ); } @@ -88,6 +92,7 @@ class _FlutterPlatform extends PlatformPlugin { this.startPaused, this.explicitObservatoryPort, this.host, + this.previewDart2, }) : assert(shellPath != null); final String shellPath; @@ -97,6 +102,7 @@ class _FlutterPlatform extends PlatformPlugin { final bool startPaused; final int explicitObservatoryPort; final InternetAddress host; + final bool previewDart2; // Each time loadChannel() is called, we spin up a local WebSocket server, // then spin up the engine in a subprocess. We pass the engine a Dart file @@ -191,14 +197,28 @@ class _FlutterPlatform extends PlatformPlugin { )); // Start the engine subprocess. - printTrace('test $ourTestCount: starting shell process'); + printTrace('test $ourTestCount: starting shell process${previewDart2? " in preview-dart-2 mode":""}'); + + final String mainDart = previewDart2 + ? await compile( + sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath), + incrementalCompilerByteStorePath: '' /* not null is enough */, + mainPath: listenerFile.path, + packagesPath: PackageMap.globalPackagesPath + ) + : listenerFile.path; + + // bundlePath needs to point to a folder with `platform.dill` file. + final String bundlePath = previewDart2 ? artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath) : null; + final Process process = await _startProcess( shellPath, - listenerFile.path, + mainDart, packages: PackageMap.globalPackagesPath, enableObservatory: enableObservatory, startPaused: startPaused, observatoryPort: explicitObservatoryPort, + bundlePath: bundlePath, ); subprocessActive = true; finalizers.add(() async { @@ -466,6 +486,7 @@ void main() { String executable, String testPath, { String packages, + String bundlePath, bool enableObservatory: false, bool startPaused: false, int observatoryPort, @@ -492,6 +513,9 @@ void main() { } if (host.type == InternetAddressType.IP_V6) command.add('--ipv6'); + if (bundlePath != null) { + command.add('--flutter-assets-dir=$bundlePath'); + } command.addAll([ '--enable-dart-profiling', '--non-interactive', diff --git a/packages/flutter_tools/lib/src/test/runner.dart b/packages/flutter_tools/lib/src/test/runner.dart index d2753f5ad02..29f5c645286 100644 --- a/packages/flutter_tools/lib/src/test/runner.dart +++ b/packages/flutter_tools/lib/src/test/runner.dart @@ -28,6 +28,7 @@ Future runTests( bool startPaused: false, bool ipv6: false, bool machine: false, + bool previewDart2: false, TestWatcher watcher, }) async { // Compute the command-line arguments for package:test. @@ -75,6 +76,7 @@ Future runTests( machine: machine, startPaused: startPaused, serverType: serverType, + previewDart2: previewDart2, ); // Make the global packages path absolute.