Skip to content

Commit 4ff6698

Browse files
Report usage of deferred-components to analytics. (#159307)
Towards flutter/flutter#159212. /cc @jtmcdole --------- Co-authored-by: Andrew Kolos <andrewrkolos@gmail.com>
1 parent fae695e commit 4ff6698

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

packages/flutter_tools/lib/src/commands/assemble.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,14 @@ class AssembleCommand extends FlutterCommand {
310310
"Try re-running 'flutter build ios' or the appropriate build command."
311311
);
312312
}
313+
if (deferredTargets.isNotEmpty) {
314+
// Record to analytics that DeferredComponents is being used.
315+
globals.analytics.send(Event.flutterBuildInfo(
316+
label: 'assemble-deferred-components',
317+
buildType: 'android',
318+
settings: deferredTargets.map((Target t) => t.name).join(','),
319+
));
320+
}
313321
if (_flutterProject.manifest.deferredComponents != null
314322
&& decodedDefines.contains('validate-deferred-components=true')
315323
&& deferredTargets.isNotEmpty

packages/flutter_tools/lib/src/commands/build_appbundle.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@ class BuildAppBundleCommand extends BuildSubCommand {
143143
// Do all setup verification that doesn't involve loading units. Checks that
144144
// require generated loading units are done after gen_snapshot in assemble.
145145
final List<DeferredComponent>? deferredComponents = FlutterProject.current().manifest.deferredComponents;
146+
if (deferredComponents != null && boolArg('deferred-components')) {
147+
// Record to analytics that DeferredComponents is being used.
148+
globals.analytics.send(Event.flutterBuildInfo(
149+
label: 'build-appbundle-deferred-components',
150+
buildType: 'android',
151+
));
152+
}
146153
if (deferredComponents != null && boolArg('deferred-components') && boolArg('validate-deferred-components') && !boolArg('debug')) {
147154
final DeferredComponentsPrebuildValidator validator = DeferredComponentsPrebuildValidator(
148155
project.directory,

packages/flutter_tools/test/commands.shard/hermetic/assemble_test.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,35 @@ void main() {
9494
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
9595
});
9696

97+
testUsingContext('flutter assemble sends assemble-deferred-components', () async {
98+
final AssembleCommand command = AssembleCommand(
99+
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
100+
);
101+
final CommandRunner<void> commandRunner = createTestCommandRunner(command);
102+
await commandRunner.run(<String>[
103+
'assemble',
104+
'-o Output',
105+
'-dTargetPlatform=android',
106+
'-dBuildMode=release',
107+
'android_aot_deferred_components_bundle_release_android-arm64',
108+
]);
109+
expect(
110+
fakeAnalytics.sentEvents,
111+
contains(
112+
Event.flutterBuildInfo(
113+
label: 'assemble-deferred-components',
114+
buildType: 'android',
115+
settings: 'android_aot_deferred_components_bundle_release_android-arm64',
116+
),
117+
),
118+
);
119+
}, overrides: <Type, Generator>{
120+
Analytics: () => fakeAnalytics,
121+
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
122+
FileSystem: () => MemoryFileSystem.test(),
123+
ProcessManager: () => FakeProcessManager.any(),
124+
});
125+
97126
testUsingContext('flutter assemble sends usage values correctly with platform', () async {
98127
final AssembleCommand command = AssembleCommand(
99128
buildSystem: TestBuildSystem.all(BuildResult(success: true)));

packages/flutter_tools/test/commands.shard/permeable/build_appbundle_test.dart

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,49 @@ void main() {
148148
Analytics: () => fakeAnalytics,
149149
ProcessInfo: () => processInfo,
150150
});
151+
152+
testUsingContext('use of the deferred components feature sends a build info event indicating so', () async {
153+
final String projectPath = await createProject(
154+
tempDir,
155+
arguments: <String>[
156+
'--empty',
157+
'--no-pub',
158+
'--template=app',
159+
],
160+
);
161+
162+
// Add deferred manifest.
163+
final File pubspec = globals.localFileSystem
164+
.directory(projectPath)
165+
.childFile('pubspec.yaml');
166+
final String modifiedContents = pubspec
167+
.readAsStringSync()
168+
.replaceAll('flutter:', 'flutter:\n deferred-components:');
169+
pubspec.writeAsStringSync(modifiedContents);
170+
printOnFailure(pubspec.readAsStringSync());
171+
172+
final Directory oldCwd = globals.localFileSystem.currentDirectory;
173+
try {
174+
globals.localFileSystem.currentDirectory = globals.localFileSystem.directory(projectPath);
175+
await runBuildAppBundleCommand(projectPath);
176+
} finally {
177+
globals.localFileSystem.currentDirectory = oldCwd;
178+
}
179+
180+
expect(
181+
fakeAnalytics.sentEvents,
182+
contains(
183+
Event.flutterBuildInfo(
184+
label: 'build-appbundle-deferred-components',
185+
buildType: 'android',
186+
),
187+
),
188+
);
189+
}, overrides: <Type, Generator>{
190+
AndroidBuilder: () => FakeAndroidBuilder(),
191+
Analytics: () => fakeAnalytics,
192+
ProcessInfo: () => processInfo,
193+
});
151194
});
152195

153196
group('Gradle', () {

0 commit comments

Comments
 (0)