diff --git a/packages/flutter_tools/lib/src/build_info.dart b/packages/flutter_tools/lib/src/build_info.dart index e2b731eb67..e77caf2875 100644 --- a/packages/flutter_tools/lib/src/build_info.dart +++ b/packages/flutter_tools/lib/src/build_info.dart @@ -164,7 +164,7 @@ class BuildInfo { /// and skips the check and potential invalidation of files. final bool assumeInitializeFromDillUpToDate; - static const BuildInfo debug = BuildInfo(BuildMode.debug, null, treeShakeIcons: false); + static const BuildInfo debug = BuildInfo(BuildMode.debug, null, trackWidgetCreation: true, treeShakeIcons: false); static const BuildInfo profile = BuildInfo(BuildMode.profile, null, treeShakeIcons: kIconTreeShakerEnabledDefault); static const BuildInfo jitRelease = BuildInfo(BuildMode.jitRelease, null, treeShakeIcons: kIconTreeShakerEnabledDefault); static const BuildInfo release = BuildInfo(BuildMode.release, null, treeShakeIcons: kIconTreeShakerEnabledDefault); diff --git a/packages/flutter_tools/test/general.shard/build_info_test.dart b/packages/flutter_tools/test/general.shard/build_info_test.dart index 246637a243..5ad63db904 100644 --- a/packages/flutter_tools/test/general.shard/build_info_test.dart +++ b/packages/flutter_tools/test/general.shard/build_info_test.dart @@ -107,6 +107,17 @@ void main() { expect(() => getIOSArchForName('bogus'), throwsException); }); + testWithoutContext('named BuildInfo has correct defaults', () { + expect(BuildInfo.debug.mode, BuildMode.debug); + expect(BuildInfo.debug.trackWidgetCreation, true); + + expect(BuildInfo.profile.mode, BuildMode.profile); + expect(BuildInfo.profile.trackWidgetCreation, false); + + expect(BuildInfo.release.mode, BuildMode.release); + expect(BuildInfo.release.trackWidgetCreation, false); + }); + testWithoutContext('toBuildSystemEnvironment encoding of standard values', () { const BuildInfo buildInfo = BuildInfo(BuildMode.debug, '', treeShakeIcons: true, diff --git a/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart b/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart index 57e83a75e6..c1579812d9 100644 --- a/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/xcodeproj_test.dart @@ -956,7 +956,7 @@ Build settings for action build and target plugin2: }); testUsingOsxContext('sets TRACK_WIDGET_CREATION=true when trackWidgetCreation is true', () async { - const BuildInfo buildInfo = BuildInfo(BuildMode.debug, null, trackWidgetCreation: true, treeShakeIcons: false); + const BuildInfo buildInfo = BuildInfo.debug; final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project')); await updateGeneratedXcodeProperties( project: project, @@ -977,7 +977,7 @@ Build settings for action build and target plugin2: }); testUsingOsxContext('does not set TRACK_WIDGET_CREATION when trackWidgetCreation is false', () async { - const BuildInfo buildInfo = BuildInfo.debug; + const BuildInfo buildInfo = BuildInfo(BuildMode.debug, null, treeShakeIcons: false); final FlutterProject project = FlutterProject.fromDirectoryTest(fs.directory('path/to/project')); await updateGeneratedXcodeProperties( project: project, diff --git a/packages/flutter_tools/test/general.shard/resident_runner_test.dart b/packages/flutter_tools/test/general.shard/resident_runner_test.dart index e94ee0207a..e13cfde705 100644 --- a/packages/flutter_tools/test/general.shard/resident_runner_test.dart +++ b/packages/flutter_tools/test/general.shard/resident_runner_test.dart @@ -1570,7 +1570,13 @@ flutter: flutterDevice, ], stayResident: false, - debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), + debuggingOptions: DebuggingOptions.enabled( + const BuildInfo( + BuildMode.debug, + null, + treeShakeIcons: false, + ) + ), target: 'main.dart', devtoolsHandler: createNoOpHandler, ); @@ -1641,6 +1647,29 @@ flutter: 'build', 'cache.dill')).readAsString(), 'ABC'); })); + testUsingContext('HotRunner copies compiled app.dill to cache during startup with track-widget-creation', () => testbed.run(() async { + fakeVmServiceHost = FakeVmServiceHost(requests: [ + listViews, + listViews, + ], wsAddress: testUri); + globals.fs.file(globals.fs.path.join('lib', 'main.dart')).createSync(recursive: true); + residentRunner = HotRunner( + [ + flutterDevice, + ], + stayResident: false, + debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), + target: 'main.dart', + devtoolsHandler: createNoOpHandler, + ); + residentRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); + + await residentRunner.run(enableDevTools: true); + + expect(await globals.fs.file(globals.fs.path.join( + 'build', 'cache.dill.track.dill')).readAsString(), 'ABC'); + })); + testUsingContext('HotRunner does not copy app.dill if a dillOutputPath is given', () => testbed.run(() async { fakeVmServiceHost = FakeVmServiceHost(requests: [ listViews, 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 70738a89af..87a9fd14a2 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 @@ -256,7 +256,10 @@ void main() { }); testUsingContext('WebRunner copies compiled app.dill to cache during startup', () async { - final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice); + final DebuggingOptions debuggingOptions = DebuggingOptions.enabled( + const BuildInfo(BuildMode.debug, null, treeShakeIcons: false), + ); + final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice, debuggingOptions: debuggingOptions); fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList()); _setupMocks(); @@ -273,6 +276,24 @@ void main() { ProcessManager: () => processManager, }); + testUsingContext('WebRunner copies compiled app.dill to cache during startup with track-widget-creation', () async { + final ResidentRunner residentWebRunner = setUpResidentRunner(flutterDevice); + fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList()); + _setupMocks(); + + residentWebRunner.artifactDirectory.childFile('app.dill').writeAsStringSync('ABC'); + final Completer connectionInfoCompleter = Completer(); + unawaited(residentWebRunner.run( + connectionInfoCompleter: connectionInfoCompleter, + )); + await connectionInfoCompleter.future; + + expect(await fileSystem.file(fileSystem.path.join('build', 'cache.dill.track.dill')).readAsString(), 'ABC'); + }, overrides: { + FileSystem: () => fileSystem, + ProcessManager: () => processManager, + }); + // Regression test for https://github.com/flutter/flutter/issues/60613 testUsingContext('ResidentWebRunner calls appFailedToStart if initial compilation fails', () async { fakeVmServiceHost = FakeVmServiceHost(requests: kAttachExpectations.toList()); @@ -1048,11 +1069,12 @@ void main() { ResidentRunner setUpResidentRunner(FlutterDevice flutterDevice, { Logger logger, SystemClock systemClock, + DebuggingOptions debuggingOptions, }) { return ResidentWebRunner( flutterDevice, flutterProject: FlutterProject.fromDirectoryTest(globals.fs.currentDirectory), - debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug), + debuggingOptions: debuggingOptions ?? DebuggingOptions.enabled(BuildInfo.debug), ipv6: true, urlTunneller: null, usage: globals.flutterUsage, diff --git a/packages/flutter_tools/test/general.shard/tester/flutter_tester_test.dart b/packages/flutter_tools/test/general.shard/tester/flutter_tester_test.dart index 24ad0e5fad..7f988f31f5 100644 --- a/packages/flutter_tools/test/general.shard/tester/flutter_tester_test.dart +++ b/packages/flutter_tools/test/general.shard/tester/flutter_tester_test.dart @@ -159,6 +159,39 @@ Hello! ''', )); + final LaunchResult result = await device.startApp(app, + mainPath: mainPath, + debuggingOptions: DebuggingOptions.enabled(const BuildInfo(BuildMode.debug, null, treeShakeIcons: false)), + ); + + expect(result.started, isTrue); + expect(result.observatoryUri, observatoryUri); + expect(logLines.last, 'Hello!'); + expect(fakeProcessManager.hasRemainingExpectations, isFalse); + }, overrides: startOverrides); + + testUsingContext('performs a build and starts in debug mode with track-widget-creation', () async { + final FlutterTesterApp app = FlutterTesterApp.fromCurrentDirectory(fileSystem); + final Uri observatoryUri = Uri.parse('http://127.0.0.1:6666/'); + final Completer completer = Completer(); + fakeProcessManager.addCommand(FakeCommand( + command: const [ + 'Artifact.flutterTester', + '--run-forever', + '--non-interactive', + '--enable-dart-profiling', + '--packages=.dart_tool/package_config.json', + '--flutter-assets-dir=/.tmp_rand0/flutter_tester.rand0', + '/.tmp_rand0/flutter_tester.rand0/flutter-tester-app.dill.track.dill', + ], + completer: completer, + stdout: + ''' +The Dart VM service is listening on $observatoryUri +Hello! +''', + )); + final LaunchResult result = await device.startApp(app, mainPath: mainPath, debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),