From 03d6f18f4a900e0e7f94060b54042365b00ad069 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Fri, 17 Aug 2018 13:19:06 -0700 Subject: [PATCH] Track number of package dependencies in Flutter (#20722) --- .../bin/tasks/technical_debt__cost.dart | 55 ++++++++++++++----- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/dev/devicelab/bin/tasks/technical_debt__cost.dart b/dev/devicelab/bin/tasks/technical_debt__cost.dart index 6d902c4554..a52be0a4e4 100644 --- a/dev/devicelab/bin/tasks/technical_debt__cost.dart +++ b/dev/devicelab/bin/tasks/technical_debt__cost.dart @@ -43,24 +43,51 @@ Future findCostsForFile(File file) async { return total; } -const String _kBenchmarkKey = 'technical_debt_in_dollars'; +Future findCostsForRepo() async { + final Process git = await startProcess( + 'git', + ['ls-files', '--full-name', flutterDirectory.path], + workingDirectory: flutterDirectory.path, + ); + double total = 0.0; + await for (String entry in git.stdout.transform(utf8.decoder).transform(const LineSplitter())) + total += await findCostsForFile(new File(path.join(flutterDirectory.path, entry))); + final int gitExitCode = await git.exitCode; + if (gitExitCode != 0) + throw new Exception('git exit with unexpected error code $gitExitCode'); + return total; +} + +Future countDependencies() async { + final Process subprocess = await startProcess( + 'flutter', + ['update-packages', '--transitive-closure'], + workingDirectory: flutterDirectory.path, + ); + final List lines = await subprocess.stdout.transform(utf8.decoder).transform(const LineSplitter()).toList(); + final int subprocessExitCode = await subprocess.exitCode; + if (subprocessExitCode != 0) + throw new Exception('flutter exit with unexpected error code $subprocessExitCode'); + final int count = lines.where((String line) => line.contains('->')).length; + if (count < 2) // we'll always have flutter and flutter_test, at least... + throw new Exception('"flutter update-packages --transitive-closure" returned bogus output:\n${lines.join("\n")}'); + return count; +} + +const String _kCostBenchmarkKey = 'technical_debt_in_dollars'; +const String _kNumberOfDependenciesKey = 'dependencies_count'; Future main() async { await task(() async { - final Process git = await startProcess( - 'git', - ['ls-files', '--full-name', flutterDirectory.path], - workingDirectory: flutterDirectory.path, - ); - double total = 0.0; - await for (String entry in git.stdout.transform(utf8.decoder).transform(const LineSplitter())) - total += await findCostsForFile(new File(path.join(flutterDirectory.path, entry))); - final int gitExitCode = await git.exitCode; - if (gitExitCode != 0) - throw new Exception('git exit with unexpected error code $gitExitCode'); return new TaskResult.success( - {_kBenchmarkKey: total}, - benchmarkScoreKeys: [_kBenchmarkKey], + { + _kCostBenchmarkKey: await findCostsForRepo(), + _kNumberOfDependenciesKey: await countDependencies(), + }, + benchmarkScoreKeys: [ + _kCostBenchmarkKey, + _kNumberOfDependenciesKey, + ], ); }); }