Report usage of deferred-components to analytics. (#159307)

Towards https://github.com/flutter/flutter/issues/159212.

/cc @jtmcdole

---------

Co-authored-by: Andrew Kolos <andrewrkolos@gmail.com>
This commit is contained in:
Matan Lurey 2024-11-26 13:01:20 -08:00 committed by GitHub
parent fae695ed61
commit 4ff6698838
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 87 additions and 0 deletions

View File

@ -310,6 +310,14 @@ class AssembleCommand extends FlutterCommand {
"Try re-running 'flutter build ios' or the appropriate build command."
);
}
if (deferredTargets.isNotEmpty) {
// Record to analytics that DeferredComponents is being used.
globals.analytics.send(Event.flutterBuildInfo(
label: 'assemble-deferred-components',
buildType: 'android',
settings: deferredTargets.map((Target t) => t.name).join(','),
));
}
if (_flutterProject.manifest.deferredComponents != null
&& decodedDefines.contains('validate-deferred-components=true')
&& deferredTargets.isNotEmpty

View File

@ -143,6 +143,13 @@ class BuildAppBundleCommand extends BuildSubCommand {
// Do all setup verification that doesn't involve loading units. Checks that
// require generated loading units are done after gen_snapshot in assemble.
final List<DeferredComponent>? deferredComponents = FlutterProject.current().manifest.deferredComponents;
if (deferredComponents != null && boolArg('deferred-components')) {
// Record to analytics that DeferredComponents is being used.
globals.analytics.send(Event.flutterBuildInfo(
label: 'build-appbundle-deferred-components',
buildType: 'android',
));
}
if (deferredComponents != null && boolArg('deferred-components') && boolArg('validate-deferred-components') && !boolArg('debug')) {
final DeferredComponentsPrebuildValidator validator = DeferredComponentsPrebuildValidator(
project.directory,

View File

@ -94,6 +94,35 @@ void main() {
FeatureFlags: () => TestFeatureFlags(isMacOSEnabled: true),
});
testUsingContext('flutter assemble sends assemble-deferred-components', () async {
final AssembleCommand command = AssembleCommand(
buildSystem: TestBuildSystem.all(BuildResult(success: true)),
);
final CommandRunner<void> commandRunner = createTestCommandRunner(command);
await commandRunner.run(<String>[
'assemble',
'-o Output',
'-dTargetPlatform=android',
'-dBuildMode=release',
'android_aot_deferred_components_bundle_release_android-arm64',
]);
expect(
fakeAnalytics.sentEvents,
contains(
Event.flutterBuildInfo(
label: 'assemble-deferred-components',
buildType: 'android',
settings: 'android_aot_deferred_components_bundle_release_android-arm64',
),
),
);
}, overrides: <Type, Generator>{
Analytics: () => fakeAnalytics,
Cache: () => Cache.test(processManager: FakeProcessManager.any()),
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('flutter assemble sends usage values correctly with platform', () async {
final AssembleCommand command = AssembleCommand(
buildSystem: TestBuildSystem.all(BuildResult(success: true)));

View File

@ -148,6 +148,49 @@ void main() {
Analytics: () => fakeAnalytics,
ProcessInfo: () => processInfo,
});
testUsingContext('use of the deferred components feature sends a build info event indicating so', () async {
final String projectPath = await createProject(
tempDir,
arguments: <String>[
'--empty',
'--no-pub',
'--template=app',
],
);
// Add deferred manifest.
final File pubspec = globals.localFileSystem
.directory(projectPath)
.childFile('pubspec.yaml');
final String modifiedContents = pubspec
.readAsStringSync()
.replaceAll('flutter:', 'flutter:\n deferred-components:');
pubspec.writeAsStringSync(modifiedContents);
printOnFailure(pubspec.readAsStringSync());
final Directory oldCwd = globals.localFileSystem.currentDirectory;
try {
globals.localFileSystem.currentDirectory = globals.localFileSystem.directory(projectPath);
await runBuildAppBundleCommand(projectPath);
} finally {
globals.localFileSystem.currentDirectory = oldCwd;
}
expect(
fakeAnalytics.sentEvents,
contains(
Event.flutterBuildInfo(
label: 'build-appbundle-deferred-components',
buildType: 'android',
),
),
);
}, overrides: <Type, Generator>{
AndroidBuilder: () => FakeAndroidBuilder(),
Analytics: () => fakeAnalytics,
ProcessInfo: () => processInfo,
});
});
group('Gradle', () {