Skip to content

Commit 59ca523

Browse files
Support web-server/profile/release mode with incremental compiler support for web (flutter#45713)
1 parent 598f2ab commit 59ca523

File tree

2 files changed

+72
-10
lines changed

2 files changed

+72
-10
lines changed

packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart

+11-10
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class DwdsWebRunnerFactory extends WebRunnerFactory {
4848
@required DebuggingOptions debuggingOptions,
4949
@required List<String> dartDefines,
5050
}) {
51-
if (featureFlags.isWebIncrementalCompilerEnabled) {
51+
if (featureFlags.isWebIncrementalCompilerEnabled && debuggingOptions.buildInfo.isDebug) {
5252
return _ExperimentalResidentWebRunner(
5353
device,
5454
target: target,
@@ -448,10 +448,10 @@ class _ExperimentalResidentWebRunner extends ResidentWebRunner {
448448

449449
try {
450450
if (fullRestart) {
451-
await _wipConnection.sendCommand('Page.reload');
451+
await _wipConnection?.sendCommand('Page.reload');
452452
} else {
453-
await _wipConnection.debugger
454-
.sendCommand('Runtime.evaluate', params: <String, Object>{
453+
await _wipConnection?.debugger
454+
?.sendCommand('Runtime.evaluate', params: <String, Object>{
455455
'expression': 'window.\$hotReloadHook([$modules])',
456456
'awaitPromise': true,
457457
'returnByValue': true,
@@ -523,12 +523,13 @@ class _ExperimentalResidentWebRunner extends ResidentWebRunner {
523523
Completer<DebugConnectionInfo> connectionInfoCompleter,
524524
Completer<void> appStartedCompleter,
525525
}) async {
526-
final Chrome chrome = await ChromeLauncher.connectedInstance;
527-
final ChromeTab chromeTab =
528-
await chrome.chromeConnection.getTab((ChromeTab chromeTab) {
529-
return chromeTab.url.contains(debuggingOptions.hostname);
530-
});
531-
_wipConnection = await chromeTab.connect();
526+
if (device.device is ChromeDevice) {
527+
final Chrome chrome = await ChromeLauncher.connectedInstance;
528+
final ChromeTab chromeTab = await chrome.chromeConnection.getTab((ChromeTab chromeTab) {
529+
return chromeTab.url.contains(debuggingOptions.hostname);
530+
});
531+
_wipConnection = await chromeTab.connect();
532+
}
532533
appStartedCompleter?.complete();
533534
connectionInfoCompleter?.complete();
534535
if (stayResident) {

packages/flutter_tools/test/general.shard/resident_web_runner_test.dart

+61
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void main() {
4949
MockChromeTab mockChromeTab;
5050
MockWipConnection mockWipConnection;
5151
MockWipDebugger mockWipDebugger;
52+
MockWebServerDevice mockWebServerDevice;
5253
bool didSkipDwds;
5354

5455
setUp(() {
@@ -66,6 +67,7 @@ void main() {
6667
mockChromeTab = MockChromeTab();
6768
mockWipConnection = MockWipConnection();
6869
mockWipDebugger = MockWipDebugger();
70+
mockWebServerDevice = MockWebServerDevice();
6971
when(mockFlutterDevice.device).thenReturn(mockChromeDevice);
7072
testbed = Testbed(
7173
setup: () {
@@ -429,6 +431,49 @@ void main() {
429431
FeatureFlags: () => TestFeatureFlags(isWebIncrementalCompilerEnabled: true),
430432
}));
431433

434+
test('Can hot restart after attaching - experimental with web-server device', () => testbed.run(() async {
435+
_setupMocks();
436+
when(mockFlutterDevice.device).thenReturn(mockWebServerDevice);
437+
when(mockWebDevFS.update(
438+
mainPath: anyNamed('mainPath'),
439+
target: anyNamed('target'),
440+
bundle: anyNamed('bundle'),
441+
firstBuildTime: anyNamed('firstBuildTime'),
442+
bundleFirstUpload: anyNamed('bundleFirstUpload'),
443+
generator: anyNamed('generator'),
444+
fullRestart: anyNamed('fullRestart'),
445+
dillOutputPath: anyNamed('dillOutputPath'),
446+
trackWidgetCreation: anyNamed('trackWidgetCreation'),
447+
projectRootPath: anyNamed('projectRootPath'),
448+
pathToReload: anyNamed('pathToReload'),
449+
invalidatedFiles: anyNamed('invalidatedFiles'),
450+
)).thenAnswer((Invocation invocation) async {
451+
return UpdateFSReport(success: true)
452+
..invalidatedModules = <String>['example'];
453+
});
454+
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
455+
unawaited(residentWebRunner.run(
456+
connectionInfoCompleter: connectionInfoCompleter,
457+
));
458+
await connectionInfoCompleter.future;
459+
final OperationResult result = await residentWebRunner.restart(fullRestart: true);
460+
461+
expect(testLogger.statusText, contains('Restarted application in'));
462+
expect(result.code, 0);
463+
verify(mockResidentCompiler.accept()).called(2);
464+
// ensure that analytics are sent.
465+
verify(Usage.instance.sendEvent('hot', 'restart', parameters: <String, String>{
466+
'cd27': 'web-javascript',
467+
'cd28': null,
468+
'cd29': 'false',
469+
'cd30': 'true',
470+
})).called(1);
471+
verifyNever(Usage.instance.sendTiming('hot', 'web-incremental-restart', any));
472+
}, overrides: <Type, Generator>{
473+
Usage: () => MockFlutterUsage(),
474+
FeatureFlags: () => TestFeatureFlags(isWebIncrementalCompilerEnabled: true),
475+
}));
476+
432477
test('Can hot restart after attaching', () => testbed.run(() async {
433478
_setupMocks();
434479
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
@@ -460,6 +505,21 @@ void main() {
460505
Usage: () => MockFlutterUsage(),
461506
}));
462507

508+
test('Selects Dwds runner in profile mode with incremental compiler enabled', () => testbed.run(() async {
509+
final ResidentWebRunner residentWebRunner = DwdsWebRunnerFactory().createWebRunner(
510+
mockFlutterDevice,
511+
flutterProject: FlutterProject.current(),
512+
debuggingOptions: DebuggingOptions.enabled(BuildInfo.profile),
513+
ipv6: true,
514+
stayResident: true,
515+
dartDefines: const <String>[],
516+
) as ResidentWebRunner;
517+
518+
expect(residentWebRunner.runtimeType.toString(), '_DwdsResidentWebRunner');
519+
}, overrides: <Type, Generator>{
520+
FeatureFlags: () => TestFeatureFlags(isWebIncrementalCompilerEnabled: true),
521+
}));
522+
463523
test('Fails on compilation errors in hot restart', () => testbed.run(() async {
464524
_setupMocks();
465525
final Completer<DebugConnectionInfo> connectionInfoCompleter = Completer<DebugConnectionInfo>();
@@ -1022,3 +1082,4 @@ class MockChromeTab extends Mock implements ChromeTab {}
10221082
class MockWipConnection extends Mock implements WipConnection {}
10231083
class MockWipDebugger extends Mock implements WipDebugger {}
10241084
class MockLogger extends Mock implements Logger {}
1085+
class MockWebServerDevice extends Mock implements WebServerDevice {}

0 commit comments

Comments
 (0)