55import 'dart:async' ;
66import 'dart:convert' ;
77
8+ import 'package:flutter_tools/src/artifacts.dart' ;
9+ import 'package:flutter_tools/src/compile.dart' ;
810import 'package:meta/meta.dart' ;
911import 'package:stream_channel/stream_channel.dart' ;
1012
@@ -56,6 +58,7 @@ void installHook({
5658 bool enableObservatory: false ,
5759 bool machine: false ,
5860 bool startPaused: false ,
61+ bool previewDart2: false ,
5962 int observatoryPort,
6063 InternetAddressType serverType: InternetAddressType .IP_V4 ,
6164}) {
@@ -71,6 +74,7 @@ void installHook({
7174 startPaused: startPaused,
7275 explicitObservatoryPort: observatoryPort,
7376 host: _kHosts[serverType],
77+ previewDart2: previewDart2,
7478 ),
7579 );
7680}
@@ -88,6 +92,7 @@ class _FlutterPlatform extends PlatformPlugin {
8892 this .startPaused,
8993 this .explicitObservatoryPort,
9094 this .host,
95+ this .previewDart2,
9196 }) : assert (shellPath != null );
9297
9398 final String shellPath;
@@ -97,6 +102,7 @@ class _FlutterPlatform extends PlatformPlugin {
97102 final bool startPaused;
98103 final int explicitObservatoryPort;
99104 final InternetAddress host;
105+ final bool previewDart2;
100106
101107 // Each time loadChannel() is called, we spin up a local WebSocket server,
102108 // then spin up the engine in a subprocess. We pass the engine a Dart file
@@ -191,14 +197,28 @@ class _FlutterPlatform extends PlatformPlugin {
191197 ));
192198
193199 // Start the engine subprocess.
194- printTrace ('test $ourTestCount : starting shell process' );
200+ printTrace ('test $ourTestCount : starting shell process${previewDart2 ? " in preview-dart-2 mode" :"" }' );
201+
202+ final String mainDart = previewDart2
203+ ? await compile (
204+ sdkRoot: artifacts.getArtifactPath (Artifact .flutterPatchedSdkPath),
205+ incrementalCompilerByteStorePath: '' /* not null is enough */ ,
206+ mainPath: listenerFile.path,
207+ packagesPath: PackageMap .globalPackagesPath
208+ )
209+ : listenerFile.path;
210+
211+ // bundlePath needs to point to a folder with `platform.dill` file.
212+ final String bundlePath = previewDart2 ? artifacts.getArtifactPath (Artifact .flutterPatchedSdkPath) : null ;
213+
195214 final Process process = await _startProcess (
196215 shellPath,
197- listenerFile.path ,
216+ mainDart ,
198217 packages: PackageMap .globalPackagesPath,
199218 enableObservatory: enableObservatory,
200219 startPaused: startPaused,
201220 observatoryPort: explicitObservatoryPort,
221+ bundlePath: bundlePath,
202222 );
203223 subprocessActive = true ;
204224 finalizers.add (() async {
@@ -466,6 +486,7 @@ void main() {
466486 String executable,
467487 String testPath, {
468488 String packages,
489+ String bundlePath,
469490 bool enableObservatory: false ,
470491 bool startPaused: false ,
471492 int observatoryPort,
@@ -492,6 +513,9 @@ void main() {
492513 }
493514 if (host.type == InternetAddressType .IP_V6 )
494515 command.add ('--ipv6' );
516+ if (bundlePath != null ) {
517+ command.add ('--flutter-assets-dir=$bundlePath ' );
518+ }
495519 command.addAll (< String > [
496520 '--enable-dart-profiling' ,
497521 '--non-interactive' ,
0 commit comments