mirror of
https://github.com/flutter/flutter.git
synced 2025-06-03 00:51:18 +00:00
Allow FlutterVersion to be overridden in the context (#8801)
This commit is contained in:
parent
6f9bfbdaba
commit
12ebb66d9e
@ -32,8 +32,8 @@ class UpgradeCommand extends FlutterCommand {
|
||||
throwToolExit('Unable to upgrade Flutter: no upstream repository configured.');
|
||||
}
|
||||
|
||||
final FlutterVersion version = new FlutterVersion(Cache.flutterRoot);
|
||||
if (version.channel == 'alpha') {
|
||||
final FlutterVersion flutterVersion = FlutterVersion.instance;
|
||||
if (flutterVersion.channel == 'alpha') {
|
||||
// The alpha branch is deprecated. Rather than trying to pull the alpha
|
||||
// branch, we should switch upstream to master.
|
||||
printStatus('Switching to from alpha to master...');
|
||||
@ -66,7 +66,7 @@ class UpgradeCommand extends FlutterCommand {
|
||||
);
|
||||
|
||||
printStatus('');
|
||||
printStatus(FlutterVersion.getVersion(Cache.flutterRoot).toString());
|
||||
printStatus(flutterVersion.toString());
|
||||
|
||||
final String projRoot = findProjectRoot();
|
||||
if (projRoot != null) {
|
||||
|
@ -15,6 +15,7 @@ import 'base/file_system.dart';
|
||||
import 'base/io.dart';
|
||||
import 'base/platform.dart';
|
||||
import 'base/process_manager.dart';
|
||||
import 'cache.dart';
|
||||
import 'device.dart';
|
||||
import 'globals.dart';
|
||||
import 'ios/ios_workflow.dart';
|
||||
@ -228,9 +229,9 @@ class _FlutterValidator extends DoctorValidator {
|
||||
final List<ValidationMessage> messages = <ValidationMessage>[];
|
||||
final ValidationType valid = ValidationType.installed;
|
||||
|
||||
final FlutterVersion version = FlutterVersion.getVersion();
|
||||
final FlutterVersion version = FlutterVersion.instance;
|
||||
|
||||
messages.add(new ValidationMessage('Flutter at ${version.flutterRoot}'));
|
||||
messages.add(new ValidationMessage('Flutter at ${Cache.flutterRoot}'));
|
||||
messages.add(new ValidationMessage(
|
||||
'Framework revision ${version.frameworkRevisionShort} '
|
||||
'(${version.frameworkAge}), ${version.frameworkDate}'
|
||||
|
@ -254,7 +254,7 @@ class FlutterCommandRunner extends CommandRunner<Null> {
|
||||
|
||||
if (globalResults['version']) {
|
||||
flutterUsage.sendCommand('version');
|
||||
printStatus(FlutterVersion.getVersion(Cache.flutterRoot).toString());
|
||||
printStatus(FlutterVersion.instance.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'base/context.dart';
|
||||
import 'base/io.dart';
|
||||
import 'base/process.dart';
|
||||
import 'base/process_manager.dart';
|
||||
@ -16,7 +17,7 @@ final Set<String> kKnownBranchNames = new Set<String>.from(<String>[
|
||||
]);
|
||||
|
||||
class FlutterVersion {
|
||||
FlutterVersion(this.flutterRoot) {
|
||||
FlutterVersion._() {
|
||||
_channel = _runGit('git rev-parse --abbrev-ref --symbolic @{u}');
|
||||
|
||||
final int slash = _channel.indexOf('/');
|
||||
@ -32,8 +33,6 @@ class FlutterVersion {
|
||||
_frameworkAge = _runGit('git log -n 1 --pretty=format:%ar');
|
||||
}
|
||||
|
||||
final String flutterRoot;
|
||||
|
||||
String _repositoryUrl;
|
||||
String get repositoryUrl => _repositoryUrl;
|
||||
|
||||
@ -55,7 +54,7 @@ class FlutterVersion {
|
||||
String get engineRevision => Cache.engineRevision;
|
||||
String get engineRevisionShort => _shortGitRevision(engineRevision);
|
||||
|
||||
String _runGit(String command) => runSync(command.split(' '), workingDirectory: flutterRoot);
|
||||
String _runGit(String command) => runSync(command.split(' '), workingDirectory: Cache.flutterRoot);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
@ -77,9 +76,7 @@ class FlutterVersion {
|
||||
return _runSync(<String>['git', 'log', '-n', '1', '--pretty=format:%ad', '--date=format:%Y-%m-%d %H:%M:%S'], Cache.flutterRoot);
|
||||
}
|
||||
|
||||
static FlutterVersion getVersion([String flutterRoot]) {
|
||||
return new FlutterVersion(flutterRoot != null ? flutterRoot : Cache.flutterRoot);
|
||||
}
|
||||
static FlutterVersion get instance => context.putIfAbsent(FlutterVersion, () => new FlutterVersion._());
|
||||
|
||||
/// Return a short string for the version (`alpha/a76bc8e22b`).
|
||||
static String getVersionString({ bool whitelistBranchName: false }) {
|
||||
|
Loading…
Reference in New Issue
Block a user