Skip to content

Commit 22b8692

Browse files
authored
[flutter_tools] Register trackWidgetCreation in AppleBuildOptionsBundle (flutter#196078)
Registers `BuildInfoOptions.trackWidgetCreation` in `AppleBuildOptionsBundle` so Apple build subcommands (`build ios`, `build ipa`, and `build macos`) register `--[no-]track-widget-creation` (defaulting to on). Note that `--profile` AOT builds for `build ios` and `build ipa` will also now compile with `--track-creation-locations` by default (unless `--no-track-widget-creation` is passed), matching `build macos`, `build apk`, `build appbundle`, and `flutter run --profile`. This regression was originally introduced in flutter#56094 (first shipped in Flutter 1.20.0). Prior to flutter#56094, `xcodeproj.dart` omitted `TRACK_WIDGET_CREATION` from `Generated.xcconfig` when `buildInfo.trackWidgetCreation` was `false`, and `KernelSnapshot` enabled widget creation tracking whenever `TrackWidgetCreation` was not `'false'`. flutter#56094 switched `xcodeproj.dart` to `buildInfo.toEnvironmentConfig()`, which unconditionally writes `TRACK_WIDGET_CREATION=${trackWidgetCreation}`. In flutter#101123 (fixing flutter#94681), `BuildInfo.debug` was updated to set `trackWidgetCreation: true`, which fixed `Generated.xcconfig` for projects built directly from Xcode after `flutter create` or `flutter pub get` (while `flutter run` already registered `--track-widget-creation`). However, `BuildIOSCommand` constructs its `BuildInfo` via `FlutterCommand.getBuildInfo()` and never registered `--track-widget-creation` (an omission later carried forward into `AppleBuildOptionsBundle` in flutter#192818), so running `flutter build ios --debug` overwrote `Generated.xcconfig` with `TRACK_WIDGET_CREATION=false` and caused the first hot reload after `flutter attach` to fail with `Lookup failed: _location`. Previous output: ``` +13: ios build debug config-only writes TRACK_WIDGET_CREATION=true to Generated.xcconfig by default Expected: contains 'TRACK_WIDGET_CREATION=true' Actual: '// This is a generated file; do not edit or check into version control.\n' 'FLUTTER_ROOT=/usr/local/google/home/bkonyi/.gemini/jetski/worktrees/flutter/issue-195792\n' 'FLUTTER_APPLICATION_PATH=/\n' 'FLUTTER_FRAMEWORK_SWIFT_PACKAGE_PATH=/ios/Flutter/ephemeral/Packages/.packages/FlutterFramework\n' 'COCOAPODS_PARALLEL_CODE_SIGN=true\n' 'FLUTTER_TARGET=lib/main.dart\n' 'FLUTTER_BUILD_DIR=build\n' 'FLUTTER_BUILD_NAME=1.0.0\n' 'FLUTTER_BUILD_NUMBER=1\n' 'EXCLUDED_ARCHS[sdk=iphonesimulator*]=i386\n' 'EXCLUDED_ARCHS[sdk=iphoneos*]=armv7\n' 'DART_DEFINES=RkxVVFRFUl9WRVJTSU9OPTAuMC4w,RkxVVFRFUl9DSEFOTkVMPW1hc3Rlcg==,RkxVVFRFUl9HSVRfVVJMPWh0dHBzOi8vZ2l0aHViLmNvbS9mbHV0dGVyL2ZsdXR0ZXIuZ2l0,RkxVVFRFUl9GUkFNRVdPUktfUkVWSVNJT049MTExMTE=,RkxVVFRFUl9FTkdJTkVfUkVWSVNJT049YWJjZGU=,RkxVVFRFUl9EQVJUX1ZFUlNJT049MTI=\n' 'DART_OBFUSCATION=false\n' 'TRACK_WIDGET_CREATION=false\n' 'TREE_SHAKE_ICONS=false\n' 'PACKAGE_CONFIG=/.dart_tool/package_config.json\n' '' Which: does not contain 'TRACK_WIDGET_CREATION=true' ``` Current output: ``` 00:00 +0: loading /usr/local/google/home/bkonyi/.gemini/jetski/worktrees/flutter/issue-195792/packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart 00:00 +0: (setUpAll) 00:00 +0: ios build debug config-only writes TRACK_WIDGET_CREATION=true to Generated.xcconfig by default 00:00 +1: (tearDownAll) 00:00 +1: All tests passed! ``` Fixes flutter#195792
1 parent 945b567 commit 22b8692

4 files changed

Lines changed: 57 additions & 4 deletions

File tree

‎packages/flutter_tools/lib/src/commands/build_macos.dart‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ class BuildMacosCommand extends BuildSubCommand {
3535
DartCompileOptionsBundle(),
3636
AppleBuildOptionsBundle(),
3737
]);
38-
argParser.addDescriptors(const <OptionDescriptor<Object?>>[
39-
BuildInfoOptions.trackWidgetCreation,
40-
AppleBuildOptionsBundle.configOnly,
41-
], verboseHelp: verboseHelp);
38+
argParser.addDescriptor(AppleBuildOptionsBundle.configOnly, verboseHelp: verboseHelp);
4239
}
4340

4441
/// Holds Apple-specific dependencies.

‎packages/flutter_tools/lib/src/runner/options/common_options.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ class AppleBuildOptionsBundle extends OptionBundle {
717717
BuildInfoOptions.performanceMeasurementFile,
718718
BuildInfoOptions.analyzeSize,
719719
BuildInfoOptions.codeSizeDirectory,
720+
BuildInfoOptions.trackWidgetCreation,
720721
];
721722
}
722723

‎packages/flutter_tools/test/commands.shard/hermetic/build_ios_test.dart‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,60 @@ void main() {
676676
},
677677
);
678678

679+
testUsingContext(
680+
'ios build debug config-only writes TRACK_WIDGET_CREATION=true to Generated.xcconfig by default',
681+
() async {
682+
createMinimalMockProjectFiles();
683+
684+
final BuildCommand command = createBuildCommand();
685+
686+
await createTestCommandRunner(command)
687+
.run(const <String>['build', 'ios', '--debug', '--config-only', '--no-pub']);
688+
689+
final File configFile = fileSystem.file('ios/Flutter/Generated.xcconfig');
690+
expect(configFile, exists);
691+
final String configContent = configFile.readAsStringSync();
692+
expect(configContent, contains('TRACK_WIDGET_CREATION=true'));
693+
},
694+
overrides: <Type, Generator>{
695+
FileSystem: () => fileSystem,
696+
ProcessManager: () => processManager,
697+
Pub: ThrowingPub.new,
698+
Platform: () => macosPlatform,
699+
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
700+
},
701+
);
702+
703+
testUsingContext(
704+
'ios build debug config-only respects --no-track-widget-creation flag',
705+
() async {
706+
createMinimalMockProjectFiles();
707+
708+
final BuildCommand command = createBuildCommand();
709+
710+
await createTestCommandRunner(command).run(const <String>[
711+
'build',
712+
'ios',
713+
'--debug',
714+
'--config-only',
715+
'--no-pub',
716+
'--no-track-widget-creation',
717+
]);
718+
719+
final File configFile = fileSystem.file('ios/Flutter/Generated.xcconfig');
720+
expect(configFile, exists);
721+
final String configContent = configFile.readAsStringSync();
722+
expect(configContent, contains('TRACK_WIDGET_CREATION=false'));
723+
},
724+
overrides: <Type, Generator>{
725+
FileSystem: () => fileSystem,
726+
ProcessManager: () => processManager,
727+
Pub: ThrowingPub.new,
728+
Platform: () => macosPlatform,
729+
XcodeProjectInterpreter: () => FakeXcodeProjectInterpreterWithBuildSettings(),
730+
},
731+
);
732+
679733
testUsingContext(
680734
'ios build invokes xcode build with verbosity',
681735
() async {

‎packages/flutter_tools/test/general.shard/runner/options/option_descriptor_test.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@ void main() {
673673
BuildInfoOptions.performanceMeasurementFile,
674674
BuildInfoOptions.analyzeSize,
675675
BuildInfoOptions.codeSizeDirectory,
676+
BuildInfoOptions.trackWidgetCreation,
676677
];
677678

678679
for (final descriptor in allOptions) {

0 commit comments

Comments
 (0)