From f1cdf57053ef70a1ec247ad38c20cf931279784b Mon Sep 17 00:00:00 2001 From: Ian Hickson Date: Thu, 26 Jan 2017 18:48:01 -0800 Subject: [PATCH] Be gentler, for MacOS (#7684) Turns out MacOS has a really low open files limit and so if you try to open EVERY FILE AT THE SAME TIME it falls over. This just opens the files one at a time, the way we used to back in the old days. --- .../bin/tasks/technical_debt__cost.dart | 65 ++++--------------- 1 file changed, 11 insertions(+), 54 deletions(-) diff --git a/dev/devicelab/bin/tasks/technical_debt__cost.dart b/dev/devicelab/bin/tasks/technical_debt__cost.dart index 0e468d22143..b80aae0e560 100644 --- a/dev/devicelab/bin/tasks/technical_debt__cost.dart +++ b/dev/devicelab/bin/tasks/technical_debt__cost.dart @@ -18,55 +18,21 @@ const double pythonCost = 3001.0; // six average SWE days, in dollars final RegExp todoPattern = new RegExp(r'(?://|#) *TODO'); final RegExp ignorePattern = new RegExp(r'// *ignore:'); -Stream findCostsForFile(File file) { +Future findCostsForFile(File file) async { if (path.extension(file.path) == '.py') - return new Stream.fromIterable([pythonCost]); + return pythonCost; if (path.extension(file.path) != '.dart' && path.extension(file.path) != '.yaml' && path.extension(file.path) != '.sh') - return null; - StreamController result = new StreamController(); - file.openRead().transform(UTF8.decoder).transform(const LineSplitter()).listen((String line) { + return 0.0; + double total = 0.0; + for (String line in await file.readAsLines()) { if (line.contains(todoPattern)) - result.add(todoCost); + total += todoCost; if (line.contains(ignorePattern)) - result.add(ignoreCost); - }, onDone: () { result.close(); }); - return result.stream; -} - -Stream findCostsForDirectory(Directory directory, Set gitFiles) { - StreamController result = new StreamController(); - Set> subscriptions = new Set>(); - - void checkDone(StreamSubscription subscription, String path) { - subscriptions.remove(subscription); - if (subscriptions.isEmpty) - result.close(); + total += ignoreCost; } - - StreamSubscription listSubscription; - subscriptions.add(listSubscription = directory.list(followLinks: false).listen((FileSystemEntity entity) { - String name = path.relative(entity.path, from: flutterDirectory.path); - if (gitFiles.contains(name)) { - if (entity is File) { - StreamSubscription subscription; - subscription = findCostsForFile(entity)?.listen((double cost) { - result.add(cost); - }, onDone: () { checkDone(subscription, name); }); - if (subscription != null) - subscriptions.add(subscription); - } else if (entity is Directory) { - StreamSubscription subscription; - subscription = findCostsForDirectory(entity, gitFiles)?.listen((double cost) { - result.add(cost); - }, onDone: () { checkDone(subscription, name); }); - if (subscription != null) - subscriptions.add(subscription); - } - } - }, onDone: () { checkDone(listSubscription, directory.path); })); - return result.stream; + return total; } const String _kBenchmarkKey = 'technical_debt_in_dollars'; @@ -78,21 +44,12 @@ Future main() async { ['ls-files', '--full-name', flutterDirectory.path], workingDirectory: flutterDirectory.path, ); - Set gitFiles = new Set(); - await for (String entry in git.stdout.transform(UTF8.decoder).transform(const LineSplitter())) { - String subentry = ''; - for (String component in path.split(entry)) { - if (subentry.isNotEmpty) - subentry += path.separator; - subentry += component; - gitFiles.add(subentry); - } - } + 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))); int gitExitCode = await git.exitCode; if (gitExitCode != 0) throw new Exception('git exit with unexpected error code $gitExitCode'); - List costs = await findCostsForDirectory(flutterDirectory, gitFiles).toList(); - double total = costs.fold(0.0, (double total, double cost) => total + cost); return new TaskResult.success( {_kBenchmarkKey: total}, benchmarkScoreKeys: [_kBenchmarkKey],