Commit f1cdf570 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

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.
parent a4a1392c
......@@ -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<double> findCostsForFile(File file) {
Future<double> findCostsForFile(File file) async {
if (path.extension(file.path) == '.py')
return new Stream<double>.fromIterable(<double>[pythonCost]);
return pythonCost;
if (path.extension(file.path) != '.dart' &&
path.extension(file.path) != '.yaml' &&
path.extension(file.path) != '.sh')
return null;
StreamController<double> result = new StreamController<double>();
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<double> findCostsForDirectory(Directory directory, Set<String> gitFiles) {
StreamController<double> result = new StreamController<double>();
Set<StreamSubscription<dynamic>> subscriptions = new Set<StreamSubscription<dynamic>>();
void checkDone(StreamSubscription<dynamic> subscription, String path) {
subscriptions.remove(subscription);
if (subscriptions.isEmpty)
result.close();
total += ignoreCost;
}
StreamSubscription<FileSystemEntity> 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<double> 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<double> 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<Null> main() async {
<String>['ls-files', '--full-name', flutterDirectory.path],
workingDirectory: flutterDirectory.path,
);
Set<String> gitFiles = new Set<String>();
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<double> costs = await findCostsForDirectory(flutterDirectory, gitFiles).toList();
double total = costs.fold(0.0, (double total, double cost) => total + cost);
return new TaskResult.success(
<String, dynamic>{_kBenchmarkKey: total},
benchmarkScoreKeys: <String>[_kBenchmarkKey],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment