fast fail update-packages

This commit is contained in:
Devon Carew 2016-04-05 10:22:36 -07:00
parent 5e3d8cf2d3
commit e9a24510bd

View File

@ -10,14 +10,15 @@ import '../dart/pub.dart';
import '../globals.dart';
import '../runner/flutter_command.dart';
/// Return the total number of projects run; throws the exit code on error.
Future<int> _runPub(Directory directory, { bool upgrade: false }) async {
int updateCount = 0;
for (FileSystemEntity dir in directory.listSync()) {
if (dir is Directory && FileSystemEntity.isFileSync(dir.path + Platform.pathSeparator + 'pubspec.yaml')) {
updateCount++;
// TODO(eseidel): Should this fail immediately if pubGet fails?
// Currently we're ignoring the return code.
await pubGet(directory: dir.path, upgrade: upgrade, checkLastModified: false);
int code = await pubGet(directory: dir.path, upgrade: upgrade, checkLastModified: false);
if (code != 0)
throw code;
}
}
return updateCount;
@ -46,13 +47,20 @@ class UpdatePackagesCommand extends FlutterCommand {
@override
Future<int> runInProject() async {
Stopwatch timer = new Stopwatch()..start();
int count = 0;
bool upgrade = argResults['upgrade'];
count += await _runPub(new Directory("${ArtifactStore.flutterRoot}/packages"), upgrade: upgrade);
count += await _runPub(new Directory("${ArtifactStore.flutterRoot}/examples"), upgrade: upgrade);
count += await _runPub(new Directory("${ArtifactStore.flutterRoot}/dev"), upgrade: upgrade);
printStatus('Ran "pub" $count time${count == 1 ? "" : "s"} in ${timer.elapsedMilliseconds} ms');
return 0;
try {
Stopwatch timer = new Stopwatch()..start();
int count = 0;
bool upgrade = argResults['upgrade'];
count += await _runPub(new Directory("${ArtifactStore.flutterRoot}/packages"), upgrade: upgrade);
count += await _runPub(new Directory("${ArtifactStore.flutterRoot}/examples"), upgrade: upgrade);
count += await _runPub(new Directory("${ArtifactStore.flutterRoot}/dev"), upgrade: upgrade);
printStatus('Ran "pub" $count time${count == 1 ? "" : "s"} in ${timer.elapsedMilliseconds} ms');
return 0;
} on int catch (code) {
return code;
}
}
}