Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions packages/flutter_tools/lib/src/commands/assemble.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'package:args/args.dart';
import 'package:meta/meta.dart';
import 'package:unified_analytics/unified_analytics.dart';

import '../artifacts.dart';
import '../base/common.dart';
Expand Down Expand Up @@ -126,6 +127,8 @@ class AssembleCommand extends FlutterCommand {

final BuildSystem _buildSystem;

late final FlutterProject _flutterProject = FlutterProject.current();

@override
String get description => 'Assemble and build Flutter resources.';

Expand All @@ -136,18 +139,18 @@ class AssembleCommand extends FlutterCommand {
String get category => FlutterCommandCategory.project;

@override
Future<CustomDimensions> get usageValues async {
final FlutterProject flutterProject = FlutterProject.current();
try {
return CustomDimensions(
commandBuildBundleTargetPlatform: _environment.defines[kTargetPlatform],
commandBuildBundleIsModule: flutterProject.isModule,
);
} on Exception {
// We've failed to send usage.
}
return const CustomDimensions();
}
Future<CustomDimensions> get usageValues async => CustomDimensions(
commandBuildBundleTargetPlatform: _environment.defines[kTargetPlatform],
commandBuildBundleIsModule: _flutterProject.isModule,
);

@override
Future<Event> unifiedAnalyticsUsageValues(String commandPath) async => Event.commandUsageValues(
workflow: commandPath,
commandHasTerminal: hasTerminal,
buildBundleTargetPlatform: _environment.defines[kTargetPlatform],
buildBundleIsModule: _flutterProject.isModule,
);

@override
Future<Set<DevelopmentArtifact>> get requiredArtifacts async {
Expand Down Expand Up @@ -208,22 +211,21 @@ class AssembleCommand extends FlutterCommand {

/// The environmental configuration for a build invocation.
Environment _createEnvironment() {
final FlutterProject flutterProject = FlutterProject.current();
String? output = stringArg('output');
if (output == null) {
throwToolExit('--output directory is required for assemble.');
}
// If path is relative, make it absolute from flutter project.
if (globals.fs.path.isRelative(output)) {
output = globals.fs.path.join(flutterProject.directory.path, output);
output = globals.fs.path.join(_flutterProject.directory.path, output);
}
final Artifacts artifacts = globals.artifacts!;
final Environment result = Environment(
outputDir: globals.fs.directory(output),
buildDir: flutterProject.directory
buildDir: _flutterProject.directory
.childDirectory('.dart_tool')
.childDirectory('flutter_build'),
projectDir: flutterProject.directory,
projectDir: _flutterProject.directory,
defines: _parseDefines(stringsArg('define')),
inputs: _parseDefines(stringsArg('input')),
cacheDir: globals.cache.getRoot(),
Expand Down Expand Up @@ -265,7 +267,7 @@ class AssembleCommand extends FlutterCommand {
}

results[kDeferredComponents] = 'false';
if (FlutterProject.current().manifest.deferredComponents != null && isDeferredComponentsTargets() && !isDebug()) {
if (_flutterProject.manifest.deferredComponents != null && isDeferredComponentsTargets() && !isDebug()) {
results[kDeferredComponents] = 'true';
}
if (argumentResults.wasParsed(FlutterOptions.kExtraFrontEndOptions)) {
Expand Down Expand Up @@ -296,7 +298,7 @@ class AssembleCommand extends FlutterCommand {
"Try re-running 'flutter build ios' or the appropriate build command."
);
}
if (FlutterProject.current().manifest.deferredComponents != null
if (_flutterProject.manifest.deferredComponents != null
&& decodedDefines.contains('validate-deferred-components=true')
&& deferredTargets.isNotEmpty
&& !isDebug()) {
Expand Down
28 changes: 25 additions & 3 deletions packages/flutter_tools/lib/src/commands/build_aar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:unified_analytics/unified_analytics.dart';

import '../android/android_builder.dart';
import '../android/android_sdk.dart';
import '../android/gradle_utils.dart';
Expand Down Expand Up @@ -75,14 +77,15 @@ class BuildAarCommand extends BuildSubCommand {
DevelopmentArtifact.androidGenSnapshot,
};

late final FlutterProject project = _getProject();

@override
Future<CustomDimensions> get usageValues async {
final FlutterProject flutterProject = _getProject();

String projectType;
if (flutterProject.manifest.isModule) {
if (project.manifest.isModule) {
projectType = 'module';
} else if (flutterProject.manifest.isPlugin) {
} else if (project.manifest.isPlugin) {
projectType = 'plugin';
} else {
projectType = 'app';
Expand All @@ -94,6 +97,25 @@ class BuildAarCommand extends BuildSubCommand {
);
}

@override
Future<Event> unifiedAnalyticsUsageValues(String commandPath) async {
final String projectType;
if (project.manifest.isModule) {
projectType = 'module';
} else if (project.manifest.isPlugin) {
projectType = 'plugin';
} else {
projectType = 'app';
}

return Event.commandUsageValues(
workflow: commandPath,
commandHasTerminal: hasTerminal,
buildAarProjectType: projectType,
buildAarTargetPlatform: stringsArg('target-platform').join(','),
);
}

@override
final String description = 'Build a repository containing an AAR and a POM file.\n\n'
'By default, AARs are built for `release`, `debug` and `profile`.\n'
Expand Down
26 changes: 26 additions & 0 deletions packages/flutter_tools/lib/src/commands/build_apk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:unified_analytics/unified_analytics.dart';

import '../android/android_builder.dart';
import '../android/build_validation.dart';
import '../android/gradle_utils.dart';
Expand Down Expand Up @@ -98,6 +100,30 @@ class BuildApkCommand extends BuildSubCommand {
);
}

@override
Future<Event> unifiedAnalyticsUsageValues(String commandPath) async {
final String buildMode;

if (boolArg('release')) {
buildMode = 'release';
} else if (boolArg('debug')) {
buildMode = 'debug';
} else if (boolArg('profile')) {
buildMode = 'profile';
} else {
// The build defaults to release.
buildMode = 'release';
}

return Event.commandUsageValues(
workflow: commandPath,
commandHasTerminal: hasTerminal,
buildApkTargetPlatform: stringsArg('target-platform').join(','),
buildApkBuildMode: buildMode,
buildApkSplitPerAbi: boolArg('split-per-abi'),
);
}

@override
Future<FlutterCommandResult> runCommand() async {
if (globals.androidSdk == null) {
Expand Down
25 changes: 25 additions & 0 deletions packages/flutter_tools/lib/src/commands/build_appbundle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:unified_analytics/unified_analytics.dart';

import '../android/android_builder.dart';
import '../android/build_validation.dart';
import '../android/deferred_components_prebuild_validator.dart';
Expand Down Expand Up @@ -105,6 +107,29 @@ class BuildAppBundleCommand extends BuildSubCommand {
);
}

@override
Future<Event> unifiedAnalyticsUsageValues(String commandPath) async {
final String buildMode;

if (boolArg('release')) {
buildMode = 'release';
} else if (boolArg('debug')) {
buildMode = 'debug';
} else if (boolArg('profile')) {
buildMode = 'profile';
} else {
// The build defaults to release.
buildMode = 'release';
}

return Event.commandUsageValues(
workflow: commandPath,
commandHasTerminal: hasTerminal,
buildAppBundleTargetPlatform: stringsArg('target-platform').join(','),
buildAppBundleBuildMode: buildMode,
);
}

@override
Future<FlutterCommandResult> runCommand() async {
if (globals.androidSdk == null) {
Expand Down
14 changes: 14 additions & 0 deletions packages/flutter_tools/lib/src/commands/build_bundle.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:unified_analytics/unified_analytics.dart';

import '../base/common.dart';
import '../build_info.dart';
import '../bundle.dart';
Expand Down Expand Up @@ -83,6 +85,18 @@ class BuildBundleCommand extends BuildSubCommand {
);
}

@override
Future<Event> unifiedAnalyticsUsageValues(String commandPath) async {
final String projectDir = globals.fs.file(targetFile).parent.parent.path;
final FlutterProject flutterProject = FlutterProject.fromDirectory(globals.fs.directory(projectDir));
return Event.commandUsageValues(
workflow: commandPath,
commandHasTerminal: hasTerminal,
buildBundleTargetPlatform: stringArg('target-platform'),
buildBundleIsModule: flutterProject.isModule,
);
}

@override
Future<void> validateCommand() async {
if (boolArg('tree-shake-icons')) {
Expand Down
10 changes: 10 additions & 0 deletions packages/flutter_tools/lib/src/commands/create.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'package:meta/meta.dart';
import 'package:unified_analytics/unified_analytics.dart';

import '../android/gradle_utils.dart' as gradle;
import '../base/common.dart';
Expand Down Expand Up @@ -91,6 +92,15 @@ class CreateCommand extends CreateBase {
);
}

@override
Future<Event> unifiedAnalyticsUsageValues(String commandPath) async => Event.commandUsageValues(
workflow: commandPath,
commandHasTerminal: hasTerminal,
createProjectType: stringArg('template'),
createAndroidLanguage: stringArg('android-language'),
createIosLanguage: stringArg('ios-language'),
);

// Lazy-initialize the net utilities with values from the context.
late final Net _net = Net(
httpClientFactory: context.get<HttpClientFactory>(),
Expand Down
54 changes: 52 additions & 2 deletions packages/flutter_tools/lib/src/commands/packages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import 'package:args/args.dart';
import 'package:unified_analytics/unified_analytics.dart';

import '../base/common.dart';
import '../base/os.dart';
Expand Down Expand Up @@ -372,6 +373,24 @@ class PackagesGetCommand extends FlutterCommand {
return FlutterCommandResult.success();
}

late final Future<List<Plugin>> _pluginsFound = (() async {
final FlutterProject? rootProject = _rootProject;
if (rootProject == null) {
return <Plugin>[];
}

return findPlugins(rootProject, throwOnError: false);
})();

late final String? _androidEmbeddingVersion = (() {
final FlutterProject? rootProject = _rootProject;
if (rootProject == null) {
return null;
}

return rootProject.android.getEmbeddingVersion().toString().split('.').last;
})();

/// The pub packages usage values are incorrect since these are calculated/sent
/// before pub get completes. This needs to be performed after dependency resolution.
@override
Expand All @@ -388,7 +407,7 @@ class PackagesGetCommand extends FlutterCommand {
if (hasPlugins) {
// Do not fail pub get if package config files are invalid before pub has
// had a chance to run.
final List<Plugin> plugins = await findPlugins(rootProject, throwOnError: false);
final List<Plugin> plugins = await _pluginsFound;
numberPlugins = plugins.length;
} else {
numberPlugins = 0;
Expand All @@ -397,7 +416,38 @@ class PackagesGetCommand extends FlutterCommand {
return CustomDimensions(
commandPackagesNumberPlugins: numberPlugins,
commandPackagesProjectModule: rootProject.isModule,
commandPackagesAndroidEmbeddingVersion: rootProject.android.getEmbeddingVersion().toString().split('.').last,
commandPackagesAndroidEmbeddingVersion: _androidEmbeddingVersion,
);
}

/// The pub packages usage values are incorrect since these are calculated/sent
/// before pub get completes. This needs to be performed after dependency resolution.
@override
Future<Event> unifiedAnalyticsUsageValues(String commandPath) async {
final FlutterProject? rootProject = _rootProject;
if (rootProject == null) {
return Event.commandUsageValues(workflow: commandPath, commandHasTerminal: hasTerminal);
}

final int numberPlugins;
// Do not send plugin analytics if pub has not run before.
final bool hasPlugins = rootProject.flutterPluginsDependenciesFile.existsSync()
&& rootProject.packageConfigFile.existsSync();
if (hasPlugins) {
// Do not fail pub get if package config files are invalid before pub has
// had a chance to run.
final List<Plugin> plugins = await _pluginsFound;
numberPlugins = plugins.length;
} else {
numberPlugins = 0;
}

return Event.commandUsageValues(
workflow: commandPath,
commandHasTerminal: hasTerminal,
packagesNumberPlugins: numberPlugins,
packagesProjectModule: rootProject.isModule,
packagesAndroidEmbeddingVersion: _androidEmbeddingVersion,
);
}
}
Loading