Commit 2a33e3f0 authored by Devon Carew's avatar Devon Carew

make flutter upgrade less verbose (#3237)

* more terse flutter upgrade

* fix an issue when updating and the engine update code has changed

* call flutter precache; add a --no-color hidden option

* fix a lint related to getters/setters
parent 47f5c6f2
...@@ -13,6 +13,10 @@ abstract class Logger { ...@@ -13,6 +13,10 @@ abstract class Logger {
String get separator => _sep; String get separator => _sep;
set supportsColor(bool value) {
_terminal.supportsColor = value;
}
/// Display an error level message to the user. Commands should use this if they /// Display an error level message to the user. Commands should use this if they
/// fail in some way. /// fail in some way.
void printError(String message, [StackTrace stackTrace]); void printError(String message, [StackTrace stackTrace]);
...@@ -195,14 +199,13 @@ class _AnsiTerminal { ...@@ -195,14 +199,13 @@ class _AnsiTerminal {
_AnsiTerminal() { _AnsiTerminal() {
// TODO(devoncarew): This detection does not work for Windows. // TODO(devoncarew): This detection does not work for Windows.
String term = Platform.environment['TERM']; String term = Platform.environment['TERM'];
_supportsColor = term != null && term != 'dumb'; supportsColor = term != null && term != 'dumb';
} }
static const String _bold = '\u001B[1m'; static const String _bold = '\u001B[1m';
static const String _reset = '\u001B[0m'; static const String _reset = '\u001B[0m';
bool _supportsColor; bool supportsColor;
bool get supportsColor => _supportsColor;
String writeBold(String str) => supportsColor ? '$_bold$str$_reset' : str; String writeBold(String str) => supportsColor ? '$_bold$str$_reset' : str;
} }
......
...@@ -15,7 +15,7 @@ typedef String StringConverter(String string); ...@@ -15,7 +15,7 @@ typedef String StringConverter(String string);
/// This runs the command in the background from the specified working /// This runs the command in the background from the specified working
/// directory. Completes when the process has been started. /// directory. Completes when the process has been started.
Future<Process> runCommand(List<String> cmd, {String workingDirectory}) async { Future<Process> runCommand(List<String> cmd, { String workingDirectory }) async {
printTrace(cmd.join(' ')); printTrace(cmd.join(' '));
String executable = cmd[0]; String executable = cmd[0];
List<String> arguments = cmd.length > 1 ? cmd.sublist(1) : []; List<String> arguments = cmd.length > 1 ? cmd.sublist(1) : [];
......
...@@ -20,42 +20,39 @@ class UpgradeCommand extends FlutterCommand { ...@@ -20,42 +20,39 @@ class UpgradeCommand extends FlutterCommand {
final String description = 'Upgrade your copy of Flutter.'; final String description = 'Upgrade your copy of Flutter.';
@override @override
Validator projectRootValidator = () => true; bool get requiresProjectRoot => false;
@override @override
Future<int> runInProject() async { Future<int> runInProject() async {
printStatus(FlutterVersion.getVersion(ArtifactStore.flutterRoot).toString());
try { try {
runCheckedSync(<String>[ runCheckedSync(<String>[
'git', 'rev-parse', '@{u}' 'git', 'rev-parse', '@{u}'
], workingDirectory: ArtifactStore.flutterRoot); ], workingDirectory: ArtifactStore.flutterRoot);
} catch (e) { } catch (e) {
printError('Unable to upgrade Flutter. No upstream repository configured for Flutter.'); printError('Unable to upgrade Flutter: no upstream repository configured.');
return 1; return 1;
} }
printStatus('');
printStatus('Upgrading Flutter...'); printStatus('Upgrading Flutter...');
int code = await runCommandAndStreamOutput(<String>[ int code = await runCommandAndStreamOutput(
'git', 'pull', '--ff-only' <String>['git', 'pull', '--ff-only'],
], workingDirectory: ArtifactStore.flutterRoot); workingDirectory: ArtifactStore.flutterRoot,
mapFunction: (String line) => matchesGitLine(line) ? null : line
);
if (code != 0) if (code != 0)
return code; return code;
// Causes us to update our locally cached packages. // Check for and download any engine and pkg/ updates.
printStatus(''); printStatus('');
printStatus('Upgrading engine...');
code = await runCommandAndStreamOutput(<String>[ code = await runCommandAndStreamOutput(<String>[
'bin/flutter', '--version' 'bin/flutter', '--no-color', 'precache'
], workingDirectory: ArtifactStore.flutterRoot); ], workingDirectory: ArtifactStore.flutterRoot);
if (code != 0) printStatus('');
return code; printStatus(FlutterVersion.getVersion(ArtifactStore.flutterRoot).toString());
// Check for and download any engine updates.
await cache.updateAll();
if (FileSystemEntity.isFileSync('pubspec.yaml')) { if (FileSystemEntity.isFileSync('pubspec.yaml')) {
printStatus(''); printStatus('');
...@@ -67,4 +64,19 @@ class UpgradeCommand extends FlutterCommand { ...@@ -67,4 +64,19 @@ class UpgradeCommand extends FlutterCommand {
return 0; return 0;
} }
// dev/benchmarks/complex_layout/lib/main.dart | 24 +-
static final RegExp _gitDiffRegex = new RegExp(r' (\S+)\s+\|\s+\d+ [+-]+');
// rename {packages/flutter/doc => dev/docs}/styles.html (92%)
// delete mode 100644 doc/index.html
// create mode 100644 examples/material_gallery/lib/gallery/demo.dart
static final RegExp _gitChangedRegex = new RegExp(r' (rename|delete mode|create mode) .+');
// Public for testing.
static bool matchesGitLine(String line) {
return _gitDiffRegex.hasMatch(line)
|| _gitChangedRegex.hasMatch(line)
|| line == 'Fast-forward';
}
} }
...@@ -56,7 +56,7 @@ class SimControl { ...@@ -56,7 +56,7 @@ class SimControl {
/// Returns [SimControl] active in the current app context (i.e. zone). /// Returns [SimControl] active in the current app context (i.e. zone).
static SimControl get instance => context[SimControl] ?? (context[SimControl] = new SimControl()); static SimControl get instance => context[SimControl] ?? (context[SimControl] = new SimControl());
Future<bool> boot({String deviceName}) async { Future<bool> boot({ String deviceName }) async {
if (_isAnyConnected()) if (_isAnyConnected())
return true; return true;
......
...@@ -40,6 +40,10 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -40,6 +40,10 @@ class FlutterCommandRunner extends CommandRunner {
argParser.addFlag('version', argParser.addFlag('version',
negatable: false, negatable: false,
help: 'Reports the version of this tool.'); help: 'Reports the version of this tool.');
argParser.addFlag('color',
negatable: true,
hide: !verboseHelp,
help: 'Whether to use terminal colors.');
String packagesHelp; String packagesHelp;
if (FileSystemEntity.isFileSync('.packages')) if (FileSystemEntity.isFileSync('.packages'))
...@@ -192,6 +196,9 @@ class FlutterCommandRunner extends CommandRunner { ...@@ -192,6 +196,9 @@ class FlutterCommandRunner extends CommandRunner {
if (globalResults['verbose']) if (globalResults['verbose'])
context[Logger] = new VerboseLogger(); context[Logger] = new VerboseLogger();
if (!globalResults['color'])
logger.supportsColor = false;
// we must set ArtifactStore.flutterRoot early because other features use it // we must set ArtifactStore.flutterRoot early because other features use it
// (e.g. enginePath's initialiser uses it) // (e.g. enginePath's initialiser uses it)
ArtifactStore.flutterRoot = path.normalize(path.absolute(globalResults['flutter-root'])); ArtifactStore.flutterRoot = path.normalize(path.absolute(globalResults['flutter-root']));
......
...@@ -26,6 +26,7 @@ import 'run_test.dart' as run_test; ...@@ -26,6 +26,7 @@ import 'run_test.dart' as run_test;
import 'service_protocol_test.dart' as service_protocol_test; import 'service_protocol_test.dart' as service_protocol_test;
import 'stop_test.dart' as stop_test; import 'stop_test.dart' as stop_test;
import 'trace_test.dart' as trace_test; import 'trace_test.dart' as trace_test;
import 'upgrade_test.dart' as upgrade_test;
void main() { void main() {
adb_test.main(); adb_test.main();
...@@ -47,4 +48,5 @@ void main() { ...@@ -47,4 +48,5 @@ void main() {
service_protocol_test.main(); service_protocol_test.main();
stop_test.main(); stop_test.main();
trace_test.main(); trace_test.main();
upgrade_test.main();
} }
// Copyright 2016 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 'package:flutter_tools/src/commands/upgrade.dart';
import 'package:test/test.dart';
void main() {
group('upgrade', () {
bool _match(String line) => UpgradeCommand.matchesGitLine(line);
test('regex match', () {
expect(_match(' .../material_gallery/lib/demo/buttons_demo.dart | 10 +--'), true);
expect(_match(' dev/benchmarks/complex_layout/lib/main.dart | 24 +-'), true);
expect(_match(' rename {packages/flutter/doc => dev/docs}/styles.html (92%)'), true);
expect(_match(' delete mode 100644 doc/index.html'), true);
expect(_match(' create mode 100644 examples/material_gallery/lib/gallery/demo.dart'), true);
expect(_match('Fast-forward'), true);
});
test('regex doesn\'t match', () {
expect(_match('Updating 79cfe1e..5046107'), false);
expect(_match('229 files changed, 6179 insertions(+), 3065 deletions(-)'), false);
});
});
}
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