Switch flutter_tools to use frontend_server for web compilation#50365
Switch flutter_tools to use frontend_server for web compilation#50365jonahwilliams merged 27 commits intoflutter:masterfrom
Conversation
|
Sorry @zanderso |
| @@ -0,0 +1,249 @@ | |||
| // Copyright 2014 The Flutter Authors. All rights reserved. | |||
There was a problem hiding this comment.
Can't think of one, but maybe this file's name should include 'web' somewhere.
| import 'dart:async'; | ||
|
|
||
| import 'package:build_daemon/constants.dart' as daemon; | ||
| import 'package:build_daemon/client.dart'; |
| .createSync(); | ||
| final FlutterProject flutterProject = FlutterProject.fromDirectory(projectDirectory); | ||
| final bool hasWebPlugins = findPlugins(flutterProject) | ||
| .any((Plugin p) => p.platforms.containsKey(WebPlugin.kConfigKey)); |
There was a problem hiding this comment.
nit: 2 space indent on continued line
| await for (final BuildResults results in client.buildResults) { | ||
| final BuildResult result = results.results.firstWhere((BuildResult result) { | ||
| return result.target == 'web'; | ||
| }); |
There was a problem hiding this comment.
If firstWhere doesn't have an orElse:, it will throw a StateError when it can't find something that matches. Since this code is in an await for, I'd prefer it failing in a more controlled way.
| break; | ||
| } | ||
| } | ||
| if (success && testOutputDir != null) { |
There was a problem hiding this comment.
nit: Flip the sense and unindent the larger part.
Alternately, split the test copying code out into a helper function.
| final DebugConnection debugConnection = useDebugExtension | ||
| ? await (_cachedExtensionFuture ??= dwds.extensionDebugConnections.stream.first) | ||
| : await dwds.debugConnection(appConnection); | ||
| if (!firstConnection.isCompleted) { |
| /// Only calls [AppConnection.runMain] on the subsequent connections. | ||
| Future<ConnectionResult> connect(bool useDebugExtension) { | ||
| final Completer<ConnectionResult> firstConnection = Completer<ConnectionResult>(); | ||
| _connectedApps = dwds.connectedApps.listen((AppConnection appConnection) async { |
There was a problem hiding this comment.
listen should generally have an onError
| Future<ConnectionResult> connect(bool useDebugExtension) { | ||
| final Completer<ConnectionResult> firstConnection = Completer<ConnectionResult>(); | ||
| _connectedApps = dwds.connectedApps.listen((AppConnection appConnection) async { | ||
| final DebugConnection debugConnection = useDebugExtension |
There was a problem hiding this comment.
If this listen callback throws an exception it will be an unhandled exception.
There was a problem hiding this comment.
Updated to forward the error through the completer
There was a problem hiding this comment.
onError handles errors on the stream, but won't run if the listen callback throws.
| final String entrypoint = globals.fs.path.basename(mainPath); | ||
| webAssetServer.writeFile('/manifest.json', '{"info":"manifest not generated in run mode."}'); | ||
| webAssetServer.writeFile('/flutter_service_worker.js', '// Service worker not loaded in run mode.'); | ||
| webAssetServer.writeFile( |
| } | ||
| return path; | ||
| } | ||
|
|
| // when(mockWebFs.recompile()).thenAnswer((Invocation _) { | ||
| // return Future<bool>.value(false); | ||
| // }); | ||
| // when(mockWebFs.uri).thenReturn('http://localhost:8765/app/'); |
There was a problem hiding this comment.
Will the above commented out code be useful in the future?
| }); | ||
| if (result.status == BuildStatus.failed) { | ||
| success = false; | ||
| break; |
There was a problem hiding this comment.
Why is break needed? Does the build not stop after this? If so, should it be explicitly stopped?
There was a problem hiding this comment.
In this particular case, we only want the first success
| ); | ||
| } | ||
| return _DwdsResidentWebRunner( | ||
| return _ExperimentalResidentWebRunner( |
There was a problem hiding this comment.
Remove "Experimental" from the name?
| try { | ||
| if (fullRestart || !debuggingOptions.buildInfo.isDebug) { | ||
| if (!deviceIsDebuggable) { | ||
| globals.printStatus('Recompile complete. Page requires refresh.'); |
There was a problem hiding this comment.
nit: it's unclear what the use is supposed to do when the page requires a refresh. Perhaps tell them what to do? E.g. "Please refresh the page using browser's reload button"
There was a problem hiding this comment.
Lets leave this for now since it matches the current behavior
| 'ignoreCache': !debuggingOptions.buildInfo.isDebug, | ||
| }); | ||
| } else { | ||
| } else { |
| File _resolveDartFile(String path) { | ||
| // If this is a dart file, it must be on the local file system and is | ||
| // likely coming from a source map request. Attempt to look in the | ||
| // local filesystem for it, and return a 404 if it is not found. The tool |
There was a problem hiding this comment.
Should the comment about 404 move somewhere else? This function cannot return 404.
There was a problem hiding this comment.
Updated comment
| if (!firstConnection.isCompleted) { | ||
| firstConnection.complete(ConnectionResult(appConnection, debugConnection)); | ||
| } else { | ||
| appConnection.runMain(); |
There was a problem hiding this comment.
nit: it's a bit strange to see a method called connect kick off the main.
There was a problem hiding this comment.
Its how we do --start-paused on the web. If we didn't want to pause we need to tell the "isolate" to start
| expect(didSkipDwds, true); | ||
| })); | ||
| // expect(didSkipDwds, true); | ||
| // })); |
| // verify(mockWebFs.connect(true)).called(1); | ||
| // // And ensure the debug services was started. | ||
| // expect(testLogger.statusText, contains('Debug service listening on')); | ||
| // })); |
|
|
||
| await result; | ||
| verify(mockWebFs.stop()).called(1); | ||
| // verify(mockWebFs.stop()).called(1); |
|
This currently doesn't work on windows, investigating... |
|
Update to fix on windows, we no longer need to chop off |
|
Ahh and the package update broke a bunch of stuff ....great |
|
I added another layer of try-catch |
Description
Updates the implementation of the web runner to use the frontend server (previously, experimental incremental compiler config). This should improve compile times, as well as reduce some of the occurrences of crashes due to us embedding build_runner incorrectly.
Fixes #41951
Closes
Fixes #49838
Fixes #49479
Fixes #49002
Fixes #48481
Fixes #47115
Fixes #46877
Fixes #44698
Fixes #44552
Fixes #43639
Fixes #41544
Fixes #40481
Fixes #38797
Fixes #45798
Might help
#49103
#47732
#44459