From 80a14af58261c3fda93bb907b16674b0c21a810d Mon Sep 17 00:00:00 2001 From: Bogdan Lukin Date: Fri, 8 May 2020 08:58:43 +0700 Subject: [PATCH] [flutter_tools] ensure track-widget-creation can be changed on devcompiler (#56564) Workaround for cached web builds with --[no-]track-widget-creation flags. Similar PR: #23299 --- dev/devicelab/manifest.yaml | 14 ++++++-------- .../src/build_runner/resident_web_runner.dart | 2 +- packages/flutter_tools/lib/src/bundle.dart | 7 +++++++ .../flutter_tools/lib/src/resident_runner.dart | 17 ++++++++++++----- .../general.shard/resident_web_runner_test.dart | 6 +++--- 5 files changed, 29 insertions(+), 17 deletions(-) diff --git a/dev/devicelab/manifest.yaml b/dev/devicelab/manifest.yaml index 99d8694e3f..bf865dbcfe 100644 --- a/dev/devicelab/manifest.yaml +++ b/dev/devicelab/manifest.yaml @@ -814,14 +814,12 @@ tasks: stage: devicelab required_agent_capabilities: ["linux-vm"] - # TODO(jonahwilliams): This should stay off until - # https://github.com/flutter/flutter/issues/56212 is fixed. - # web_enable_twc: - # description: > - # Verifies that track-widget-creation can be enabled and disabled. - # stage: devicelab - # required_agent_capabilities: ["linux-vm"] - # flaky: true + web_enable_twc: + description: > + Verifies that track-widget-creation can be enabled and disabled. + stage: devicelab + required_agent_capabilities: ["linux-vm"] + flaky: true # run_without_leak_linux: # description: > diff --git a/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart b/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart index a2370bd0b9..b3cb71d210 100644 --- a/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart +++ b/packages/flutter_tools/lib/src/build_runner/resident_web_runner.dart @@ -640,7 +640,7 @@ class _ResidentWebRunner extends ResidentWebRunner { pathToReload: getReloadPath(fullRestart: fullRestart), invalidatedFiles: invalidationResult.uris, packageConfig: invalidationResult.packageConfig, - trackWidgetCreation: true, + trackWidgetCreation: debuggingOptions.buildInfo.trackWidgetCreation, ); devFSStatus.stop(); globals.printTrace('Synced ${getSizeAsMB(report.syncedBytes)}.'); diff --git a/packages/flutter_tools/lib/src/bundle.dart b/packages/flutter_tools/lib/src/bundle.dart index 0621d9e350..16772931d7 100644 --- a/packages/flutter_tools/lib/src/bundle.dart +++ b/packages/flutter_tools/lib/src/bundle.dart @@ -34,6 +34,13 @@ String getDefaultApplicationKernelPath({ @required bool trackWidgetCreation }) { ); } +String getDefaultCachedKernelPath({ @required bool trackWidgetCreation }) { + return getKernelPathForTransformerOptions( + globals.fs.path.join(getBuildDirectory(), 'cache.dill'), + trackWidgetCreation: trackWidgetCreation, + ); +} + String getKernelPathForTransformerOptions( String path, { @required bool trackWidgetCreation, diff --git a/packages/flutter_tools/lib/src/resident_runner.dart b/packages/flutter_tools/lib/src/resident_runner.dart index e9408566ca..a226c4cb88 100644 --- a/packages/flutter_tools/lib/src/resident_runner.dart +++ b/packages/flutter_tools/lib/src/resident_runner.dart @@ -21,6 +21,7 @@ import 'base/signals.dart'; import 'base/terminal.dart'; import 'base/utils.dart'; import 'build_info.dart'; +import 'bundle.dart'; import 'codegen.dart'; import 'compile.dart'; import 'convert.dart'; @@ -98,7 +99,9 @@ class FlutterDevice { compilerMessageConsumer: (String message, {bool emphasis, TerminalColor color, }) => globals.printTrace(message), - initializeFromDill: globals.fs.path.join(getBuildDirectory(), 'cache.dill'), + initializeFromDill: getDefaultCachedKernelPath( + trackWidgetCreation: buildInfo.trackWidgetCreation, + ), targetModel: TargetModel.dartdevc, experimentalFlags: experimentalFlags, platformDill: globals.fs.file(globals.artifacts @@ -123,7 +126,9 @@ class FlutterDevice { targetModel: targetModel, experimentalFlags: experimentalFlags, dartDefines: buildInfo.dartDefines, - initializeFromDill: globals.fs.path.join(getBuildDirectory(), 'cache.dill'), + initializeFromDill: getDefaultCachedKernelPath( + trackWidgetCreation: buildInfo.trackWidgetCreation, + ), packagesPath: globalPackagesPath, ); } @@ -723,6 +728,7 @@ abstract class ResidentRunner { bool get supportsServiceProtocol => isRunningDebug || isRunningProfile; bool get supportsCanvasKit => false; bool get supportsWriteSkSL => supportsServiceProtocol; + bool get trackWidgetCreation => debuggingOptions.buildInfo.trackWidgetCreation; // Returns the Uri of the first connected device for mobile, // and only connected device for web. @@ -1156,10 +1162,11 @@ abstract class ResidentRunner { Future preExit() async { // If _dillOutputPath is null, we created a temporary directory for the dill. if (_dillOutputPath == null && artifactDirectory.existsSync()) { - final File outputDill = artifactDirectory.childFile('app.dill'); + final File outputDill = globals.fs.file(dillOutputPath); if (outputDill.existsSync()) { - artifactDirectory.childFile('app.dill') - .copySync(globals.fs.path.join(getBuildDirectory(), 'cache.dill')); + outputDill.copySync(getDefaultCachedKernelPath( + trackWidgetCreation: trackWidgetCreation, + )); } artifactDirectory.deleteSync(recursive: true); } diff --git a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart index 70760629d5..7a30f97f4b 100644 --- a/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_web_runner_test.dart @@ -141,7 +141,7 @@ void main() { projectRootPath: anyNamed('projectRootPath'), pathToReload: anyNamed('pathToReload'), invalidatedFiles: anyNamed('invalidatedFiles'), - trackWidgetCreation: true, + trackWidgetCreation: anyNamed('trackWidgetCreation'), packageConfig: anyNamed('packageConfig'), )).thenAnswer((Invocation _) async { return UpdateFSReport(success: true, syncedBytes: 0)..invalidatedModules = []; @@ -583,7 +583,7 @@ void main() { pathToReload: anyNamed('pathToReload'), invalidatedFiles: anyNamed('invalidatedFiles'), packageConfig: anyNamed('packageConfig'), - trackWidgetCreation: true, + trackWidgetCreation: anyNamed('trackWidgetCreation'), )).thenAnswer((Invocation _) async { return UpdateFSReport(success: false, syncedBytes: 0)..invalidatedModules = []; }); @@ -646,7 +646,7 @@ void main() { pathToReload: anyNamed('pathToReload'), invalidatedFiles: anyNamed('invalidatedFiles'), packageConfig: anyNamed('packageConfig'), - trackWidgetCreation: true, + trackWidgetCreation: anyNamed('trackWidgetCreation'), )).thenAnswer((Invocation _) async { return UpdateFSReport(success: false, syncedBytes: 0)..invalidatedModules = []; });