-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Switch flutter_tools to use frontend_server for web compilation #50365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Sorry @zanderso |
| @@ -0,0 +1,249 @@ | |||
| // Copyright 2014 The Flutter Authors. All rights reserved. | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't think of one, but maybe this file's name should include 'web' somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| import 'dart:async'; | ||
|
|
||
| import 'package:build_daemon/constants.dart' as daemon; | ||
| import 'package:build_daemon/client.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alphabetize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| .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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: 2 space indent on continued line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| break; | ||
| } | ||
| } | ||
| if (success && testOutputDir != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Flip the sense and unindent the larger part.
Alternately, split the test copying code out into a helper function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| final DebugConnection debugConnection = useDebugExtension | ||
| ? await (_cachedExtensionFuture ??= dwds.extensionDebugConnections.stream.first) | ||
| : await dwds.debugConnection(appConnection); | ||
| if (!firstConnection.isCompleted) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: think positive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| /// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
listen should generally have an onError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this listen callback throws an exception it will be an unhandled exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to forward the error through the completer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 space indent, paren style.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| } | ||
| return path; | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra newline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| // 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will the above commented out code be useful in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
| }); | ||
| if (result.status == BuildStatus.failed) { | ||
| success = false; | ||
| break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this particular case, we only want the first success
| ); | ||
| } | ||
| return _DwdsResidentWebRunner( | ||
| return _ExperimentalResidentWebRunner( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove "Experimental" from the name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| try { | ||
| if (fullRestart || !debuggingOptions.buildInfo.isDebug) { | ||
| if (!deviceIsDebuggable) { | ||
| globals.printStatus('Recompile complete. Page requires refresh.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets leave this for now since it matches the current behavior
| 'ignoreCache': !debuggingOptions.buildInfo.isDebug, | ||
| }); | ||
| } else { | ||
| } else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
undo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the comment about 404 move somewhere else? This function cannot return 404.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated comment
| if (!firstConnection.isCompleted) { | ||
| firstConnection.complete(ConnectionResult(appConnection, debugConnection)); | ||
| } else { | ||
| appConnection.runMain(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: it's a bit strange to see a method called connect kick off the main.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); | ||
| // })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
| // verify(mockWebFs.connect(true)).called(1); | ||
| // // And ensure the debug services was started. | ||
| // expect(testLogger.statusText, contains('Debug service listening on')); | ||
| // })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
|
|
||
| await result; | ||
| verify(mockWebFs.stop()).called(1); | ||
| // verify(mockWebFs.stop()).called(1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
|
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 |
zanderso
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm w/ small comment
|
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