Unverified Commit 64fd68ed authored by stuartmorgan's avatar stuartmorgan Committed by GitHub

Don't generate plugin registry in ResidentWebRunner (#91281)

* Don't generate plugin registry in ResidentWebRunner

generateDartPluginRegistry was being set to true unconditionally in
ResidentRunner, bypassing the primary check in
DartPluginRegistrantTarget, and the targetPlatform was not set in that
codepath, bypassing the second after the changes in
https://github.com/flutter/flutter/pull/87991. This caused web hot
restarts to be slower due to doing unnecessary work.

This ensures that generateDartPluginRegistry is false in the
ResidentWebRunner to skip that unnecessary step.

Fixes https://github.com/flutter/flutter/issues/91262

* Formatting
Co-authored-by: 's avatarZachary Anderson <zanderso@users.noreply.github.com>
Co-authored-by: 's avatarZachary Anderson <zanderso@users.noreply.github.com>
parent 947ffa1f
...@@ -66,6 +66,8 @@ class DartPluginRegistrantTarget extends Target { ...@@ -66,6 +66,8 @@ class DartPluginRegistrantTarget extends Target {
// TODO(stuartmorgan): Investigate removing this check entirely; ideally the // TODO(stuartmorgan): Investigate removing this check entirely; ideally the
// source generation step shouldn't be platform dependent, and the generated // source generation step shouldn't be platform dependent, and the generated
// code should just do the right thing on every platform. // code should just do the right thing on every platform.
// Failing that, consider throwing if `targetPlatform` isn't set and finding
// all violations, as it's not consistently set here.
return targetPlatform == TargetPlatform.fuchsia_arm64 || return targetPlatform == TargetPlatform.fuchsia_arm64 ||
targetPlatform == TargetPlatform.fuchsia_x64 || targetPlatform == TargetPlatform.fuchsia_x64 ||
targetPlatform == TargetPlatform.web_javascript; targetPlatform == TargetPlatform.web_javascript;
......
...@@ -145,6 +145,10 @@ class ResidentWebRunner extends ResidentRunner { ...@@ -145,6 +145,10 @@ class ResidentWebRunner extends ResidentRunner {
@override @override
bool get supportsWriteSkSL => false; bool get supportsWriteSkSL => false;
@override
// Web uses a different plugin registry.
bool get generateDartPluginRegistry => false;
bool get _enableDwds => debuggingEnabled; bool get _enableDwds => debuggingEnabled;
ConnectionResult _connectionResult; ConnectionResult _connectionResult;
......
...@@ -1101,6 +1101,10 @@ abstract class ResidentRunner extends ResidentHandlers { ...@@ -1101,6 +1101,10 @@ abstract class ResidentRunner extends ResidentHandlers {
bool get trackWidgetCreation => debuggingOptions.buildInfo.trackWidgetCreation; bool get trackWidgetCreation => debuggingOptions.buildInfo.trackWidgetCreation;
/// True if the shared Dart plugin registry (which is different than the one
/// used for web) should be generated during source generation.
bool get generateDartPluginRegistry => true;
// Returns the Uri of the first connected device for mobile, // Returns the Uri of the first connected device for mobile,
// and only connected device for web. // and only connected device for web.
// //
...@@ -1152,7 +1156,7 @@ abstract class ResidentRunner extends ResidentHandlers { ...@@ -1152,7 +1156,7 @@ abstract class ResidentRunner extends ResidentHandlers {
processManager: globals.processManager, processManager: globals.processManager,
platform: globals.platform, platform: globals.platform,
projectDir: globals.fs.currentDirectory, projectDir: globals.fs.currentDirectory,
generateDartPluginRegistry: true, generateDartPluginRegistry: generateDartPluginRegistry,
); );
final CompositeTarget compositeTarget = CompositeTarget(<Target>[ final CompositeTarget compositeTarget = CompositeTarget(<Target>[
......
...@@ -941,6 +941,47 @@ void main() { ...@@ -941,6 +941,47 @@ void main() {
ProcessManager: () => processManager, ProcessManager: () => processManager,
}); });
// While this file should be ignored on web, generating it here will cause a
// perf regression in hot restart.
testUsingContext('Does not generate generated_main.dart', () async {
// Create necessary files for [DartPluginRegistrantTarget]
final File packageConfig = globals.fs.directory('.dart_tool')
.childFile('package_config.json');
packageConfig.createSync(recursive: true);
packageConfig.writeAsStringSync('''
{
"configVersion": 2,
"packages": [
{
"name": "path_provider_linux",
"rootUri": "../../../path_provider_linux",
"packageUri": "lib/",
"languageVersion": "2.12"
}
]
}
''');
// Start with a generated_main.dart file.
globals.fs.directory('.dart_tool')
.childDirectory('flutter_build')
.childFile('generated_main.dart')
.createSync(recursive: true);
final FlutterProject project = FlutterProject.fromDirectoryTest(fileSystem.currentDirectory);
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice);
await residentWebRunner.runSourceGenerators();
// generated_main.dart should be untouched, indicating that its
// generation didn't run. If it had run, the file would have been removed as
// there are no plugins in the project.
expect(project.dartPluginRegistrant.existsSync(), true);
expect(project.dartPluginRegistrant.readAsStringSync(), '');
}, overrides: <Type, Generator>{
FileSystem: () => fileSystem,
ProcessManager: () => processManager,
});
testUsingContext('Successfully turns WebSocketException into ToolExit', () async { testUsingContext('Successfully turns WebSocketException into ToolExit', () async {
final BufferLogger logger = BufferLogger.test(); final BufferLogger logger = BufferLogger.test();
final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice, logger: logger); final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice, logger: logger);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment