From 22f376418fa739865b8516a38117695539651198 Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Tue, 21 Aug 2018 14:02:33 -0700 Subject: [PATCH] Track number of package dependencies in Flutter (#20831) * Track number of package dependencies in Flutter Relands #20774. * Use evalFlutter instead of startProcess. That way we don't need `flutter` on the PATH. --- .../bin/tasks/technical_debt__cost.dart | 50 +++++++++++++------ dev/devicelab/lib/framework/utils.dart | 8 +-- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/dev/devicelab/bin/tasks/technical_debt__cost.dart b/dev/devicelab/bin/tasks/technical_debt__cost.dart index 8f076cd6ba..e4bdbeb58c 100644 --- a/dev/devicelab/bin/tasks/technical_debt__cost.dart +++ b/dev/devicelab/bin/tasks/technical_debt__cost.dart @@ -47,24 +47,46 @@ 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 List lines = (await evalFlutter( + 'update-packages', + options: ['--transitive-closure'], + )).split('\n'); + 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, + ], ); }); } diff --git a/dev/devicelab/lib/framework/utils.dart b/dev/devicelab/lib/framework/utils.dart index 65b0923504..fd85a9b99f 100644 --- a/dev/devicelab/lib/framework/utils.dart +++ b/dev/devicelab/lib/framework/utils.dart @@ -265,7 +265,7 @@ Future exec( String executable, List arguments, { Map environment, - bool canFail = false, + bool canFail = false, // as in, whether failures are ok. False means that they are fatal. }) async { final Process process = await startProcess(executable, arguments, environment: environment); @@ -300,7 +300,7 @@ Future eval( String executable, List arguments, { Map environment, - bool canFail = false, + bool canFail = false, // as in, whether failures are ok. False means that they are fatal. }) async { final Process process = await startProcess(executable, arguments, environment: environment); @@ -332,7 +332,7 @@ Future eval( Future flutter(String command, { List options = const [], - bool canFail = false, + bool canFail = false, // as in, whether failures are ok. False means that they are fatal. Map environment, }) { final List args = [command]..addAll(options); @@ -343,7 +343,7 @@ Future flutter(String command, { /// Runs a `flutter` command and returns the standard output as a string. Future evalFlutter(String command, { List options = const [], - bool canFail = false, + bool canFail = false, // as in, whether failures are ok. False means that they are fatal. Map environment, }) { final List args = [command]..addAll(options);