Skip to content

Commit d52f315

Browse files
Add new benchmark to track cost of dependencies to a User (flutter#23856)
1 parent 36b9983 commit d52f315

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

dev/devicelab/bin/tasks/technical_debt__cost.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,33 @@ Future<int> countDependencies() async {
7373
return count;
7474
}
7575

76+
Future<int> countConsumerDependencies() async {
77+
final List<String> lines = (await evalFlutter(
78+
'update-packages',
79+
options: <String>['--transitive-closure', '--consumer-only'],
80+
)).split('\n');
81+
final int count = lines.where((String line) => line.contains('->')).length;
82+
if (count < 2) // we'll always have flutter and flutter_test, at least...
83+
throw Exception('"flutter update-packages --transitive-closure" returned bogus output:\n${lines.join("\n")}');
84+
return count;
85+
}
86+
7687
const String _kCostBenchmarkKey = 'technical_debt_in_dollars';
7788
const String _kNumberOfDependenciesKey = 'dependencies_count';
89+
const String _kNumberOfConsumerDependenciesKey = 'consumer_dependencies_count';
7890

7991
Future<void> main() async {
8092
await task(() async {
8193
return TaskResult.success(
8294
<String, dynamic>{
8395
_kCostBenchmarkKey: await findCostsForRepo(),
8496
_kNumberOfDependenciesKey: await countDependencies(),
97+
_kNumberOfConsumerDependenciesKey: await countConsumerDependencies(),
8598
},
8699
benchmarkScoreKeys: <String>[
87100
_kCostBenchmarkKey,
88101
_kNumberOfDependenciesKey,
102+
_kNumberOfConsumerDependenciesKey,
89103
],
90104
);
91105
});

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ class UpdatePackagesCommand extends FlutterCommand {
6565
defaultsTo: false,
6666
negatable: false,
6767
)
68+
..addFlag(
69+
'consumer-only',
70+
help: 'Only prints the dependency graph that is the transitive closure'
71+
'that a consumer of the Flutter SDK will observe (When combined '
72+
'with transitive-closure)',
73+
defaultsTo: false,
74+
negatable: false,
75+
)
6876
..addFlag(
6977
'verify-only',
7078
help: 'verifies the package checksum without changing or updating deps',
@@ -107,6 +115,24 @@ class UpdatePackagesCommand extends FlutterCommand {
107115
final bool isPrintPaths = argResults['paths'];
108116
final bool isPrintTransitiveClosure = argResults['transitive-closure'];
109117
final bool isVerifyOnly = argResults['verify-only'];
118+
final bool isConsumerOnly = argResults['consumer-only'];
119+
120+
// "consumer" packages are those that constitute our public API (e.g. flutter, flutter_test, flutter_driver, flutter_localizations).
121+
if (isConsumerOnly) {
122+
if (!isPrintTransitiveClosure) {
123+
throwToolExit(
124+
'--consumer-only can only be used with the --transitive-closure flag'
125+
);
126+
}
127+
// Only retain flutter, flutter_test, flutter_driver, and flutter_localizations.
128+
const List<String> consumerPackages = <String>['flutter', 'flutter_test', 'flutter_driver', 'flutter_localizations'];
129+
// ensure we only get flutter/packages
130+
packages.retainWhere((Directory directory) {
131+
return consumerPackages.any((String package) {
132+
return directory.path.endsWith('packages${fs.path.separator}$package');
133+
});
134+
});
135+
}
110136

111137
// The dev/integration_tests/android_views integration test depends on an assets
112138
// package that is in the goldens repository. We need to make sure that the goldens

0 commit comments

Comments
 (0)