flutter/packages/flutter_tools/lib/src/commands/update_packages.dart
Dan Rubel 34e466f1fd Refactor flutter command exit code - part 3 of 3 (#6838)
* Remove the workaround that pinned args to v0.13.6
This reverts most of the changes in commit 6331b6c8b5d964ec0dbf2cd9bb84c60c650a0878
* throw exception if exit code is not an integer
* rework command infrastructure to throw ToolExit when non-zero exitCode
* convert commands to return Future<Null>
* cleanup remaining commands to use throwToolExit for non-zero exit code
* remove isUnusual exception message
* add type annotations for updated args package
2016-11-14 14:21:30 -05:00

65 lines
2.0 KiB
Dart

// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:io';
import 'package:path/path.dart' as path;
import '../base/logger.dart';
import '../base/net.dart';
import '../cache.dart';
import '../dart/pub.dart';
import '../globals.dart';
import '../runner/flutter_command.dart';
class UpdatePackagesCommand extends FlutterCommand {
UpdatePackagesCommand({ this.hidden: false }) {
argParser.addFlag(
'upgrade',
help: 'Ignores pubspec.lock and retrieves newer versions of packages.',
defaultsTo: false
);
}
@override
final String name = 'update-packages';
@override
final String description = 'Update the packages inside the Flutter repo.';
@override
final bool hidden;
Future<Null> _downloadCoverageData() async {
Status status = logger.startProgress("Downloading lcov data for package:flutter...");
final List<int> data = await fetchUrl(Uri.parse('https://storage.googleapis.com/flutter_infra/flutter/coverage/lcov.info'));
final String coverageDir = path.join(Cache.flutterRoot, 'packages/flutter/coverage');
new File(path.join(coverageDir, 'lcov.base.info'))
..createSync(recursive: true)
..writeAsBytesSync(data, flush: true);
new File(path.join(coverageDir, 'lcov.info'))
..createSync(recursive: true)
..writeAsBytesSync(data, flush: true);
status.stop();
}
@override
Future<Null> runCommand() async {
final Stopwatch timer = new Stopwatch()..start();
int count = 0;
final bool upgrade = argResults['upgrade'];
for (Directory dir in runner.getRepoPackages()) {
await pubGet(directory: dir.path, upgrade: upgrade, checkLastModified: false);
count++;
}
await _downloadCoverageData();
final double seconds = timer.elapsedMilliseconds / 1000.0;
printStatus('\nRan \'pub\' $count time${count == 1 ? "" : "s"} and fetched coverage data in ${seconds.toStringAsFixed(1)}s.');
}
}