From 43c307b3f41a126f328367fbbd50fe08deadd7d7 Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Thu, 22 Apr 2021 09:38:18 -0700 Subject: [PATCH] Revert "[devicelab] remove globals and dependency tracking from technical debt (#80946)" (#80958) This reverts commit dc71d713d9d726022e1c73cedd7f8ef28c698a93. --- .../bin/tasks/technical_debt__cost.dart | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/dev/devicelab/bin/tasks/technical_debt__cost.dart b/dev/devicelab/bin/tasks/technical_debt__cost.dart index e82ef9fd605..0a182adeece 100644 --- a/dev/devicelab/bin/tasks/technical_debt__cost.dart +++ b/dev/devicelab/bin/tasks/technical_debt__cost.dart @@ -82,6 +82,43 @@ Future findCostsForRepo() async { return total; } +Future findGlobalsForTool() async { + final Process git = await startProcess( + 'git', + ['ls-files', '--full-name', path.join(flutterDirectory.path, 'packages', 'flutter_tools')], + workingDirectory: flutterDirectory.path, + ); + int total = 0; + await for (final String entry in git.stdout.transform(utf8.decoder).transform(const LineSplitter())) + total += await findGlobalsForFile(File(path.join(flutterDirectory.path, entry))); + final int gitExitCode = await git.exitCode; + if (gitExitCode != 0) + throw 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 Exception('"flutter update-packages --transitive-closure" returned bogus output:\n${lines.join("\n")}'); + return count; +} + +Future countConsumerDependencies() async { + final List lines = (await evalFlutter( + 'update-packages', + options: ['--transitive-closure', '--consumer-only'], + )).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 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'; const String _kNumberOfConsumerDependenciesKey = 'consumer_dependencies_count'; @@ -92,6 +129,9 @@ Future main() async { return TaskResult.success( { _kCostBenchmarkKey: await findCostsForRepo(), + _kNumberOfDependenciesKey: await countDependencies(), + _kNumberOfConsumerDependenciesKey: await countConsumerDependencies(), + _kNumberOfFlutterToolGlobals: await findGlobalsForTool(), }, benchmarkScoreKeys: [ _kCostBenchmarkKey,