Skip to content

Commit 2f1f494

Browse files
authored
Add --preview-dart-2 to 'flutter test' (flutter#14135)
1 parent 4b87a01 commit 2f1f494

File tree

4 files changed

+39
-8
lines changed

4 files changed

+39
-8
lines changed

packages/flutter_tools/lib/src/commands/test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class TestCommand extends FlutterCommand {
6868
negatable: false,
6969
help: 'Handle machine structured JSON command input\n'
7070
'and provide output and progress in machine friendly format.');
71+
argParser.addFlag('preview-dart-2',
72+
hide: !verboseHelp,
73+
help: 'Preview Dart 2.0 functionality.');
7174
}
7275

7376
@override
@@ -206,6 +209,7 @@ class TestCommand extends FlutterCommand {
206209
startPaused: startPaused,
207210
ipv6: argResults['ipv6'],
208211
machine: machine,
212+
previewDart2: argResults['preview-dart-2'],
209213
);
210214

211215
if (collector != null) {

packages/flutter_tools/lib/src/compile.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ Future<String> compile(
6262
bool aot : false,
6363
bool strongMode : false,
6464
List<String> extraFrontEndOptions,
65-
String incrementalCompilerByteStorePath}) async {
65+
String incrementalCompilerByteStorePath,
66+
String packagesPath}) async {
6667
final String frontendServer = artifacts.getArtifactPath(
6768
Artifact.frontendServerSnapshotForEngineDartSdk
6869
);
@@ -85,12 +86,12 @@ Future<String> compile(
8586
command.add('--strong');
8687
}
8788
if (incrementalCompilerByteStorePath != null) {
88-
command.addAll(<String>[
89-
'--incremental',
90-
'--byte-store',
91-
incrementalCompilerByteStorePath]);
92-
fs.directory(incrementalCompilerByteStorePath).createSync(recursive: true);
89+
command.add('--incremental');
9390
}
91+
if (packagesPath != null) {
92+
command.addAll(<String>['--packages', packagesPath]);
93+
}
94+
9495
if (extraFrontEndOptions != null)
9596
command.addAll(extraFrontEndOptions);
9697
command.add(mainPath);

packages/flutter_tools/lib/src/test/flutter_platform.dart

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import 'dart:async';
66
import 'dart:convert';
77

8+
import 'package:flutter_tools/src/artifacts.dart';
9+
import 'package:flutter_tools/src/compile.dart';
810
import 'package:meta/meta.dart';
911
import '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',

packages/flutter_tools/lib/src/test/runner.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Future<int> runTests(
2828
bool startPaused: false,
2929
bool ipv6: false,
3030
bool machine: false,
31+
bool previewDart2: false,
3132
TestWatcher watcher,
3233
}) async {
3334
// Compute the command-line arguments for package:test.
@@ -75,6 +76,7 @@ Future<int> runTests(
7576
machine: machine,
7677
startPaused: startPaused,
7778
serverType: serverType,
79+
previewDart2: previewDart2,
7880
);
7981

8082
// Make the global packages path absolute.

0 commit comments

Comments
 (0)