Unverified Commit 12ba9046 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Migrate tool version to null safety (#79911)

parent bf41c839
...@@ -167,11 +167,11 @@ abstract class ProcessUtils { ...@@ -167,11 +167,11 @@ abstract class ProcessUtils {
Future<RunResult> run( Future<RunResult> run(
List<String> cmd, { List<String> cmd, {
bool throwOnError = false, bool throwOnError = false,
RunResultChecker allowedFailures, RunResultChecker? allowedFailures,
String workingDirectory, String? workingDirectory,
bool allowReentrantFlutter = false, bool allowReentrantFlutter = false,
Map<String, String> environment, Map<String, String>? environment,
Duration timeout, Duration? timeout,
int timeoutRetries = 0, int timeoutRetries = 0,
}); });
...@@ -180,10 +180,10 @@ abstract class ProcessUtils { ...@@ -180,10 +180,10 @@ abstract class ProcessUtils {
List<String> cmd, { List<String> cmd, {
bool throwOnError = false, bool throwOnError = false,
bool verboseExceptions = false, bool verboseExceptions = false,
RunResultChecker allowedFailures, RunResultChecker? allowedFailures,
bool hideStdout = false, bool hideStdout = false,
String workingDirectory, String? workingDirectory,
Map<String, String> environment, Map<String, String>? environment,
bool allowReentrantFlutter = false, bool allowReentrantFlutter = false,
Encoding encoding = systemEncoding, Encoding encoding = systemEncoding,
}); });
...@@ -192,9 +192,9 @@ abstract class ProcessUtils { ...@@ -192,9 +192,9 @@ abstract class ProcessUtils {
/// directory. Completes when the process has been started. /// directory. Completes when the process has been started.
Future<Process> start( Future<Process> start(
List<String> cmd, { List<String> cmd, {
String workingDirectory, String? workingDirectory,
bool allowReentrantFlutter = false, bool allowReentrantFlutter = false,
Map<String, String> environment, Map<String, String>? environment,
}); });
/// This runs the command and streams stdout/stderr from the child process to /// This runs the command and streams stdout/stderr from the child process to
...@@ -210,24 +210,24 @@ abstract class ProcessUtils { ...@@ -210,24 +210,24 @@ abstract class ProcessUtils {
/// treated as errors, just as if they had been logged to stderr instead. /// treated as errors, just as if they had been logged to stderr instead.
Future<int> stream( Future<int> stream(
List<String> cmd, { List<String> cmd, {
String workingDirectory, String? workingDirectory,
bool allowReentrantFlutter = false, bool allowReentrantFlutter = false,
String prefix = '', String prefix = '',
bool trace = false, bool trace = false,
RegExp filter, RegExp? filter,
RegExp stdoutErrorMatcher, RegExp? stdoutErrorMatcher,
StringConverter mapFunction, StringConverter? mapFunction,
Map<String, String> environment, Map<String, String>? environment,
}); });
bool exitsHappySync( bool exitsHappySync(
List<String> cli, { List<String> cli, {
Map<String, String> environment, Map<String, String>? environment,
}); });
Future<bool> exitsHappy( Future<bool> exitsHappy(
List<String> cli, { List<String> cli, {
Map<String, String> environment, Map<String, String>? environment,
}); });
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
import '../base/common.dart'; import '../base/common.dart';
import '../cache.dart'; import '../cache.dart';
import '../globals.dart' as globals; import '../globals_null_migrated.dart' as globals;
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import '../version.dart'; import '../version.dart';
......
...@@ -15,7 +15,7 @@ import '../dart/pub.dart'; ...@@ -15,7 +15,7 @@ import '../dart/pub.dart';
import '../features.dart'; import '../features.dart';
import '../flutter_manifest.dart'; import '../flutter_manifest.dart';
import '../flutter_project_metadata.dart'; import '../flutter_project_metadata.dart';
import '../globals.dart' as globals; import '../globals_null_migrated.dart' as globals;
import '../project.dart'; import '../project.dart';
import '../reporting/reporting.dart'; import '../reporting/reporting.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
......
...@@ -18,7 +18,7 @@ import '../convert.dart'; ...@@ -18,7 +18,7 @@ import '../convert.dart';
import '../dart/pub.dart'; import '../dart/pub.dart';
import '../features.dart'; import '../features.dart';
import '../flutter_project_metadata.dart'; import '../flutter_project_metadata.dart';
import '../globals.dart' as globals; import '../globals_null_migrated.dart' as globals;
import '../project.dart'; import '../project.dart';
import '../runner/flutter_command.dart'; import '../runner/flutter_command.dart';
import '../template.dart'; import '../template.dart';
......
...@@ -25,7 +25,6 @@ import 'persistent_tool_state.dart'; ...@@ -25,7 +25,6 @@ import 'persistent_tool_state.dart';
import 'project.dart'; import 'project.dart';
import 'reporting/reporting.dart'; import 'reporting/reporting.dart';
import 'runner/local_engine.dart'; import 'runner/local_engine.dart';
import 'version.dart';
export 'globals_null_migrated.dart'; export 'globals_null_migrated.dart';
...@@ -49,7 +48,6 @@ CocoaPodsValidator get cocoapodsValidator => context.get<CocoaPodsValidator>(); ...@@ -49,7 +48,6 @@ CocoaPodsValidator get cocoapodsValidator => context.get<CocoaPodsValidator>();
LocalEngineLocator get localEngineLocator => context.get<LocalEngineLocator>(); LocalEngineLocator get localEngineLocator => context.get<LocalEngineLocator>();
CocoaPods get cocoaPods => context.get<CocoaPods>(); CocoaPods get cocoaPods => context.get<CocoaPods>();
FlutterVersion get flutterVersion => context.get<FlutterVersion>();
FuchsiaArtifacts get fuchsiaArtifacts => context.get<FuchsiaArtifacts>(); FuchsiaArtifacts get fuchsiaArtifacts => context.get<FuchsiaArtifacts>();
IOSSimulatorUtils get iosSimulatorUtils => context.get<IOSSimulatorUtils>(); IOSSimulatorUtils get iosSimulatorUtils => context.get<IOSSimulatorUtils>();
IOSWorkflow get iosWorkflow => context.get<IOSWorkflow>(); IOSWorkflow get iosWorkflow => context.get<IOSWorkflow>();
......
...@@ -23,6 +23,7 @@ import 'base/time.dart'; ...@@ -23,6 +23,7 @@ import 'base/time.dart';
import 'base/user_messages.dart'; import 'base/user_messages.dart';
import 'cache.dart'; import 'cache.dart';
import 'ios/plist_parser.dart'; import 'ios/plist_parser.dart';
import 'version.dart';
Cache get cache => context.get<Cache>()!; Cache get cache => context.get<Cache>()!;
Config get config => context.get<Config>()!; Config get config => context.get<Config>()!;
...@@ -32,6 +33,7 @@ OperatingSystemUtils get os => context.get<OperatingSystemUtils>()!; ...@@ -32,6 +33,7 @@ OperatingSystemUtils get os => context.get<OperatingSystemUtils>()!;
Signals get signals => context.get<Signals>() ?? LocalSignals.instance; Signals get signals => context.get<Signals>() ?? LocalSignals.instance;
AndroidStudio? get androidStudio => context.get<AndroidStudio>(); AndroidStudio? get androidStudio => context.get<AndroidStudio>();
AndroidSdk? get androidSdk => context.get<AndroidSdk>(); AndroidSdk? get androidSdk => context.get<AndroidSdk>();
FlutterVersion get flutterVersion => context.get<FlutterVersion>()!;
/// Currently active implementation of the file system. /// Currently active implementation of the file system.
/// ///
......
...@@ -13,7 +13,7 @@ import 'base/logger.dart'; ...@@ -13,7 +13,7 @@ import 'base/logger.dart';
import 'build_info.dart'; import 'build_info.dart';
import 'convert.dart'; import 'convert.dart';
import 'device.dart'; import 'device.dart';
import 'globals.dart' as globals; import 'globals_null_migrated.dart' as globals;
Future<String> sharedSkSlWriter(Device device, Map<String, Object> data, { Future<String> sharedSkSlWriter(Device device, Map<String, Object> data, {
File outputFile, File outputFile,
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'base/common.dart'; import 'base/common.dart';
...@@ -18,6 +16,8 @@ import 'globals_null_migrated.dart' as globals; ...@@ -18,6 +16,8 @@ import 'globals_null_migrated.dart' as globals;
/// The flutter GitHub repository. /// The flutter GitHub repository.
String get _flutterGit => globals.platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git'; String get _flutterGit => globals.platform.environment['FLUTTER_GIT_URL'] ?? 'https://github.com/flutter/flutter.git';
const String _unknownFrameworkVersion = '0.0.0-unknown';
/// The names of each channel/branch in order of increasing stability. /// The names of each channel/branch in order of increasing stability.
enum Channel { enum Channel {
master, master,
...@@ -45,7 +45,7 @@ String getNameForChannel(Channel channel) { ...@@ -45,7 +45,7 @@ String getNameForChannel(Channel channel) {
/// ///
/// Returns `null` if [name] is not in the list of official channels, according /// Returns `null` if [name] is not in the list of official channels, according
/// to [kOfficialChannels]. /// to [kOfficialChannels].
Channel getChannelForName(String name) { Channel? getChannelForName(String name) {
if (kOfficialChannels.contains(name)) { if (kOfficialChannels.contains(name)) {
return Channel.values[kOfficialChannels.toList().indexOf(name)]; return Channel.values[kOfficialChannels.toList().indexOf(name)];
} }
...@@ -60,8 +60,8 @@ class FlutterVersion { ...@@ -60,8 +60,8 @@ class FlutterVersion {
/// available upstream. /// available upstream.
FlutterVersion({ FlutterVersion({
SystemClock clock = const SystemClock(), SystemClock clock = const SystemClock(),
String workingDirectory, String? workingDirectory,
String frameworkRevision, String? frameworkRevision,
}) : _clock = clock, }) : _clock = clock,
_workingDirectory = workingDirectory { _workingDirectory = workingDirectory {
_frameworkRevision = frameworkRevision ?? _runGit( _frameworkRevision = frameworkRevision ?? _runGit(
...@@ -74,7 +74,7 @@ class FlutterVersion { ...@@ -74,7 +74,7 @@ class FlutterVersion {
} }
final SystemClock _clock; final SystemClock _clock;
final String _workingDirectory; final String? _workingDirectory;
/// Fetches tags from the upstream Flutter repository and re-calculates the /// Fetches tags from the upstream Flutter repository and re-calculates the
/// version. /// version.
...@@ -87,52 +87,54 @@ class FlutterVersion { ...@@ -87,52 +87,54 @@ class FlutterVersion {
_frameworkVersion = gitTagVersion.frameworkVersionFor(_frameworkRevision); _frameworkVersion = gitTagVersion.frameworkVersionFor(_frameworkRevision);
} }
String _repositoryUrl; String? _repositoryUrl;
String get repositoryUrl { String? get repositoryUrl {
final String _ = channel; final String _ = channel;
return _repositoryUrl; return _repositoryUrl;
} }
String _channel; String? _channel;
/// The channel is the upstream branch. /// The channel is the upstream branch.
/// `master`, `dev`, `beta`, `stable`; or old ones, like `alpha`, `hackathon`, ... /// `master`, `dev`, `beta`, `stable`; or old ones, like `alpha`, `hackathon`, ...
String get channel { String get channel {
if (_channel == null) { String? channel = _channel;
final String channel = _runGit( if (channel == null) {
final String gitChannel = _runGit(
'git rev-parse --abbrev-ref --symbolic @{u}', 'git rev-parse --abbrev-ref --symbolic @{u}',
globals.processUtils, globals.processUtils,
_workingDirectory, _workingDirectory,
); );
final int slash = channel.indexOf('/'); final int slash = gitChannel.indexOf('/');
if (slash != -1) { if (slash != -1) {
final String remote = channel.substring(0, slash); final String remote = gitChannel.substring(0, slash);
_repositoryUrl = _runGit( _repositoryUrl = _runGit(
'git ls-remote --get-url $remote', 'git ls-remote --get-url $remote',
globals.processUtils, globals.processUtils,
_workingDirectory, _workingDirectory,
); );
_channel = channel.substring(slash + 1); channel = gitChannel.substring(slash + 1);
} else if (channel.isEmpty) { } else if (gitChannel.isEmpty) {
_channel = 'unknown'; channel = 'unknown';
} else { } else {
_channel = channel; channel = gitChannel;
} }
_channel = channel;
} }
return _channel; return channel;
} }
GitTagVersion _gitTagVersion; late GitTagVersion _gitTagVersion;
GitTagVersion get gitTagVersion => _gitTagVersion; GitTagVersion get gitTagVersion => _gitTagVersion;
/// The name of the local branch. /// The name of the local branch.
/// Use getBranchName() to read this. /// Use getBranchName() to read this.
String _branch; String? _branch;
String _frameworkRevision; late String _frameworkRevision;
String get frameworkRevision => _frameworkRevision; String get frameworkRevision => _frameworkRevision;
String get frameworkRevisionShort => _shortGitRevision(frameworkRevision); String get frameworkRevisionShort => _shortGitRevision(frameworkRevision);
String _frameworkAge; String? _frameworkAge;
String get frameworkAge { String get frameworkAge {
return _frameworkAge ??= _runGit( return _frameworkAge ??= _runGit(
gitLog(<String>['-n', '1', '--pretty=format:%ar']).join(' '), gitLog(<String>['-n', '1', '--pretty=format:%ar']).join(' '),
...@@ -141,7 +143,7 @@ class FlutterVersion { ...@@ -141,7 +143,7 @@ class FlutterVersion {
); );
} }
String _frameworkVersion; late String _frameworkVersion;
String get frameworkVersion => _frameworkVersion; String get frameworkVersion => _frameworkVersion;
String get dartSdkVersion => globals.cache.dartSdkVersion; String get dartSdkVersion => globals.cache.dartSdkVersion;
...@@ -150,12 +152,12 @@ class FlutterVersion { ...@@ -150,12 +152,12 @@ class FlutterVersion {
String get engineRevisionShort => _shortGitRevision(engineRevision); String get engineRevisionShort => _shortGitRevision(engineRevision);
void ensureVersionFile() { void ensureVersionFile() {
globals.fs.file(globals.fs.path.join(Cache.flutterRoot, 'version')).writeAsStringSync(_frameworkVersion); globals.fs.file(globals.fs.path.join(Cache.flutterRoot!, 'version')).writeAsStringSync(_frameworkVersion);
} }
@override @override
String toString() { String toString() {
final String versionText = frameworkVersion == 'unknown' ? '' : ' $frameworkVersion'; final String versionText = frameworkVersion == _unknownFrameworkVersion ? '' : ' $frameworkVersion';
final String flutterText = 'Flutter$versionText • channel $channel${repositoryUrl ?? 'unknown source'}'; final String flutterText = 'Flutter$versionText • channel $channel${repositoryUrl ?? 'unknown source'}';
final String frameworkText = 'Framework • revision $frameworkRevisionShort ($frameworkAge) • $frameworkCommitDate'; final String frameworkText = 'Framework • revision $frameworkRevisionShort ($frameworkAge) • $frameworkCommitDate';
final String engineText = 'Engine • revision $engineRevisionShort'; final String engineText = 'Engine • revision $engineRevisionShort';
...@@ -170,7 +172,7 @@ class FlutterVersion { ...@@ -170,7 +172,7 @@ class FlutterVersion {
} }
Map<String, Object> toJson() => <String, Object>{ Map<String, Object> toJson() => <String, Object>{
'frameworkVersion': frameworkVersion ?? 'unknown', 'frameworkVersion': frameworkVersion,
'channel': channel, 'channel': channel,
'repositoryUrl': repositoryUrl ?? 'unknown source', 'repositoryUrl': repositoryUrl ?? 'unknown source',
'frameworkRevision': frameworkRevision, 'frameworkRevision': frameworkRevision,
...@@ -192,7 +194,7 @@ class FlutterVersion { ...@@ -192,7 +194,7 @@ class FlutterVersion {
// If lenient is true, and the git command fails, a placeholder date is // If lenient is true, and the git command fails, a placeholder date is
// returned. Otherwise, the VersionCheckError exception is propagated. // returned. Otherwise, the VersionCheckError exception is propagated.
static String _latestGitCommitDate({ static String _latestGitCommitDate({
String branch, String? branch,
bool lenient = false, bool lenient = false,
}) { }) {
final List<String> args = gitLog(<String>[ final List<String> args = gitLog(<String>[
...@@ -270,7 +272,7 @@ class FlutterVersion { ...@@ -270,7 +272,7 @@ class FlutterVersion {
/// Return a short string for the version (e.g. `master/0.0.59-pre.92`, `scroll_refactor/a76bc8e22b`). /// Return a short string for the version (e.g. `master/0.0.59-pre.92`, `scroll_refactor/a76bc8e22b`).
String getVersionString({ bool redactUnknownBranches = false }) { String getVersionString({ bool redactUnknownBranches = false }) {
if (frameworkVersion != 'unknown') { if (frameworkVersion != _unknownFrameworkVersion) {
return '${getBranchName(redactUnknownBranches: redactUnknownBranches)}/$frameworkVersion'; return '${getBranchName(redactUnknownBranches: redactUnknownBranches)}/$frameworkVersion';
} }
return '${getBranchName(redactUnknownBranches: redactUnknownBranches)}/$frameworkRevisionShort'; return '${getBranchName(redactUnknownBranches: redactUnknownBranches)}/$frameworkRevisionShort';
...@@ -285,33 +287,13 @@ class FlutterVersion { ...@@ -285,33 +287,13 @@ class FlutterVersion {
final String branch = _runGit('git rev-parse --abbrev-ref HEAD', globals.processUtils); final String branch = _runGit('git rev-parse --abbrev-ref HEAD', globals.processUtils);
return branch == 'HEAD' ? channel : branch; return branch == 'HEAD' ? channel : branch;
}(); }();
if (redactUnknownBranches || _branch.isEmpty) { if (redactUnknownBranches || _branch!.isEmpty) {
// Only return the branch names we know about; arbitrary branch names might contain PII. // Only return the branch names we know about; arbitrary branch names might contain PII.
if (!kOfficialChannels.contains(_branch)) { if (!kOfficialChannels.contains(_branch)) {
return '[user-branch]'; return '[user-branch]';
} }
} }
return _branch; return _branch!;
}
/// Returns true if `tentativeDescendantRevision` is a direct descendant to
/// the `tentativeAncestorRevision` revision on the Flutter framework repo
/// tree.
bool checkRevisionAncestry({
String tentativeDescendantRevision,
String tentativeAncestorRevision,
}) {
final ProcessResult result = globals.processManager.runSync(
<String>[
'git',
'merge-base',
'--is-ancestor',
tentativeAncestorRevision,
tentativeDescendantRevision
],
workingDirectory: Cache.flutterRoot,
);
return result.exitCode == 0;
} }
/// The amount of time we wait before pinging the server to check for the /// The amount of time we wait before pinging the server to check for the
...@@ -396,7 +378,7 @@ class FlutterVersion { ...@@ -396,7 +378,7 @@ class FlutterVersion {
// Get whether there's a newer version on the remote. This only goes // Get whether there's a newer version on the remote. This only goes
// to the server if we haven't checked recently so won't happen on every // to the server if we haven't checked recently so won't happen on every
// command. // command.
final DateTime latestFlutterCommitDate = await _getLatestAvailableFlutterDate(); final DateTime? latestFlutterCommitDate = await _getLatestAvailableFlutterDate();
final VersionCheckResult remoteVersionStatus = latestFlutterCommitDate == null final VersionCheckResult remoteVersionStatus = latestFlutterCommitDate == null
? VersionCheckResult.unknown ? VersionCheckResult.unknown
: latestFlutterCommitDate.isAfter(localFrameworkCommitDate) : latestFlutterCommitDate.isAfter(localFrameworkCommitDate)
...@@ -471,13 +453,13 @@ class FlutterVersion { ...@@ -471,13 +453,13 @@ class FlutterVersion {
/// ///
/// Returns null if the cached version is out-of-date or missing, and we are /// Returns null if the cached version is out-of-date or missing, and we are
/// unable to reach the server to get the latest version. /// unable to reach the server to get the latest version.
Future<DateTime> _getLatestAvailableFlutterDate() async { Future<DateTime?> _getLatestAvailableFlutterDate() async {
globals.cache.checkLockAcquired(); globals.cache.checkLockAcquired();
final VersionCheckStamp versionCheckStamp = await VersionCheckStamp.load(); final VersionCheckStamp versionCheckStamp = await VersionCheckStamp.load();
if (versionCheckStamp.lastTimeVersionWasChecked != null) { if (versionCheckStamp.lastTimeVersionWasChecked != null) {
final Duration timeSinceLastCheck = _clock.now().difference( final Duration timeSinceLastCheck = _clock.now().difference(
versionCheckStamp.lastTimeVersionWasChecked, versionCheckStamp.lastTimeVersionWasChecked!,
); );
// Don't ping the server too often. Return cached value if it's fresh. // Don't ping the server too often. Return cached value if it's fresh.
...@@ -520,16 +502,16 @@ class VersionCheckStamp { ...@@ -520,16 +502,16 @@ class VersionCheckStamp {
this.lastTimeWarningWasPrinted, this.lastTimeWarningWasPrinted,
}); });
final DateTime lastTimeVersionWasChecked; final DateTime? lastTimeVersionWasChecked;
final DateTime lastKnownRemoteVersion; final DateTime? lastKnownRemoteVersion;
final DateTime lastTimeWarningWasPrinted; final DateTime? lastTimeWarningWasPrinted;
/// The prefix of the stamp file where we cache Flutter version check data. /// The prefix of the stamp file where we cache Flutter version check data.
@visibleForTesting @visibleForTesting
static const String flutterVersionCheckStampFile = 'flutter_version_check'; static const String flutterVersionCheckStampFile = 'flutter_version_check';
static Future<VersionCheckStamp> load() async { static Future<VersionCheckStamp> load() async {
final String versionCheckStamp = globals.cache.getStampFor(flutterVersionCheckStampFile); final String? versionCheckStamp = globals.cache.getStampFor(flutterVersionCheckStampFile);
if (versionCheckStamp != null) { if (versionCheckStamp != null) {
// Attempt to parse stamp JSON. // Attempt to parse stamp JSON.
...@@ -551,7 +533,7 @@ class VersionCheckStamp { ...@@ -551,7 +533,7 @@ class VersionCheckStamp {
} }
static VersionCheckStamp fromJson(Map<String, dynamic> jsonObject) { static VersionCheckStamp fromJson(Map<String, dynamic> jsonObject) {
DateTime readDateTime(String property) { DateTime? readDateTime(String property) {
return jsonObject.containsKey(property) return jsonObject.containsKey(property)
? DateTime.parse(jsonObject[property] as String) ? DateTime.parse(jsonObject[property] as String)
: null; : null;
...@@ -565,9 +547,9 @@ class VersionCheckStamp { ...@@ -565,9 +547,9 @@ class VersionCheckStamp {
} }
Future<void> store({ Future<void> store({
DateTime newTimeVersionWasChecked, DateTime? newTimeVersionWasChecked,
DateTime newKnownRemoteVersion, DateTime? newKnownRemoteVersion,
DateTime newTimeWarningWasPrinted, DateTime? newTimeWarningWasPrinted,
}) async { }) async {
final Map<String, String> jsonData = toJson(); final Map<String, String> jsonData = toJson();
...@@ -588,9 +570,9 @@ class VersionCheckStamp { ...@@ -588,9 +570,9 @@ class VersionCheckStamp {
} }
Map<String, String> toJson({ Map<String, String> toJson({
DateTime updateTimeVersionWasChecked, DateTime? updateTimeVersionWasChecked,
DateTime updateKnownRemoteVersion, DateTime? updateKnownRemoteVersion,
DateTime updateTimeWarningWasPrinted, DateTime? updateTimeWarningWasPrinted,
}) { }) {
updateTimeVersionWasChecked = updateTimeVersionWasChecked ?? lastTimeVersionWasChecked; updateTimeVersionWasChecked = updateTimeVersionWasChecked ?? lastTimeVersionWasChecked;
updateKnownRemoteVersion = updateKnownRemoteVersion ?? lastKnownRemoteVersion; updateKnownRemoteVersion = updateKnownRemoteVersion ?? lastKnownRemoteVersion;
...@@ -654,7 +636,7 @@ String _runSync(List<String> command, { bool lenient = true }) { ...@@ -654,7 +636,7 @@ String _runSync(List<String> command, { bool lenient = true }) {
return ''; return '';
} }
String _runGit(String command, ProcessUtils processUtils, [String workingDirectory]) { String _runGit(String command, ProcessUtils processUtils, [String? workingDirectory]) {
return processUtils.runSync( return processUtils.runSync(
command.split(' '), command.split(' '),
workingDirectory: workingDirectory ?? Cache.flutterRoot, workingDirectory: workingDirectory ?? Cache.flutterRoot,
...@@ -678,7 +660,7 @@ Future<String> _run(List<String> command) async { ...@@ -678,7 +660,7 @@ Future<String> _run(List<String> command) async {
); );
} }
String _shortGitRevision(String revision) { String _shortGitRevision(String? revision) {
if (revision == null) { if (revision == null) {
return ''; return '';
} }
...@@ -710,33 +692,33 @@ class GitTagVersion { ...@@ -710,33 +692,33 @@ class GitTagVersion {
gitTag = ''; gitTag = '';
/// The X in vX.Y.Z. /// The X in vX.Y.Z.
final int x; final int? x;
/// The Y in vX.Y.Z. /// The Y in vX.Y.Z.
final int y; final int? y;
/// The Z in vX.Y.Z. /// The Z in vX.Y.Z.
final int z; final int? z;
/// the F in vX.Y.Z+hotfix.F. /// the F in vX.Y.Z+hotfix.F.
final int hotfix; final int? hotfix;
/// Number of commits since the vX.Y.Z tag. /// Number of commits since the vX.Y.Z tag.
final int commits; final int? commits;
/// The git hash (or an abbreviation thereof) for this commit. /// The git hash (or an abbreviation thereof) for this commit.
final String hash; final String? hash;
/// The N in X.Y.Z-dev.N.M. /// The N in X.Y.Z-dev.N.M.
final int devVersion; final int? devVersion;
/// The M in X.Y.Z-dev.N.M. /// The M in X.Y.Z-dev.N.M.
final int devPatch; final int? devPatch;
/// The git tag that is this version's closest ancestor. /// The git tag that is this version's closest ancestor.
final String gitTag; final String? gitTag;
static GitTagVersion determine(ProcessUtils processUtils, {String workingDirectory, bool fetchTags = false, String gitRef = 'HEAD'}) { static GitTagVersion determine(ProcessUtils processUtils, {String? workingDirectory, bool fetchTags = false, String gitRef = 'HEAD'}) {
if (fetchTags) { if (fetchTags) {
final String channel = _runGit('git rev-parse --abbrev-ref HEAD', processUtils, workingDirectory); final String channel = _runGit('git rev-parse --abbrev-ref HEAD', processUtils, workingDirectory);
if (channel == 'dev' || channel == 'beta' || channel == 'stable') { if (channel == 'dev' || channel == 'beta' || channel == 'stable') {
...@@ -783,26 +765,26 @@ class GitTagVersion { ...@@ -783,26 +765,26 @@ class GitTagVersion {
static GitTagVersion parseVersion(String version) { static GitTagVersion parseVersion(String version) {
final RegExp versionPattern = RegExp( final RegExp versionPattern = RegExp(
r'^(\d+)\.(\d+)\.(\d+)(-\d+\.\d+\.pre)?(?:-(\d+)-g([a-f0-9]+))?$'); r'^(\d+)\.(\d+)\.(\d+)(-\d+\.\d+\.pre)?(?:-(\d+)-g([a-f0-9]+))?$');
final Match match = versionPattern.firstMatch(version.trim()); final Match? match = versionPattern.firstMatch(version.trim());
if (match == null) { if (match == null) {
return const GitTagVersion.unknown(); return const GitTagVersion.unknown();
} }
final List<String> matchGroups = match.groups(<int>[1, 2, 3, 4, 5, 6]); final List<String?> matchGroups = match.groups(<int>[1, 2, 3, 4, 5, 6]);
final int x = matchGroups[0] == null ? null : int.tryParse(matchGroups[0]); final int? x = matchGroups[0] == null ? null : int.tryParse(matchGroups[0]!);
final int y = matchGroups[1] == null ? null : int.tryParse(matchGroups[1]); final int? y = matchGroups[1] == null ? null : int.tryParse(matchGroups[1]!);
final int z = matchGroups[2] == null ? null : int.tryParse(matchGroups[2]); final int? z = matchGroups[2] == null ? null : int.tryParse(matchGroups[2]!);
final String devString = matchGroups[3]; final String? devString = matchGroups[3];
int devVersion, devPatch; int? devVersion, devPatch;
if (devString != null) { if (devString != null) {
final Match devMatch = RegExp(r'^-(\d+)\.(\d+)\.pre$') final Match? devMatch = RegExp(r'^-(\d+)\.(\d+)\.pre$')
.firstMatch(devString); .firstMatch(devString);
final List<String> devGroups = devMatch.groups(<int>[1, 2]); final List<String?>? devGroups = devMatch?.groups(<int>[1, 2]);
devVersion = devGroups[0] == null ? null : int.tryParse(devGroups[0]); devVersion = devGroups?[0] == null ? null : int.tryParse(devGroups![0]!);
devPatch = devGroups[1] == null ? null : int.tryParse(devGroups[1]); devPatch = devGroups?[1] == null ? null : int.tryParse(devGroups![1]!);
} }
// count of commits past last tagged version // count of commits past last tagged version
final int commits = matchGroups[4] == null ? 0 : int.tryParse(matchGroups[4]); final int? commits = matchGroups[4] == null ? 0 : int.tryParse(matchGroups[4]!);
final String hash = matchGroups[5] ?? ''; final String hash = matchGroups[5] ?? '';
return GitTagVersion( return GitTagVersion(
...@@ -829,20 +811,20 @@ class GitTagVersion { ...@@ -829,20 +811,20 @@ class GitTagVersion {
} }
String frameworkVersionFor(String revision) { String frameworkVersionFor(String revision) {
if (x == null || y == null || z == null || !revision.startsWith(hash)) { if (x == null || y == null || z == null || (hash != null && !revision.startsWith(hash!))) {
return '0.0.0-unknown'; return _unknownFrameworkVersion;
} }
if (commits == 0) { if (commits == 0 && gitTag != null) {
return gitTag; return gitTag!;
} }
if (hotfix != null) { if (hotfix != null) {
// This is an unexpected state where untagged commits exist past a hotfix // This is an unexpected state where untagged commits exist past a hotfix
return '$x.$y.$z+hotfix.${hotfix + 1}.pre.$commits'; return '$x.$y.$z+hotfix.${hotfix! + 1}.pre.$commits';
} }
if (devPatch != null && devVersion != null) { if (devPatch != null && devVersion != null) {
return '$x.$y.$z-${devVersion + 1}.0.pre.$commits'; return '$x.$y.$z-${devVersion! + 1}.0.pre.$commits';
} }
return '$x.$y.${z + 1}-0.0.pre.$commits'; return '$x.$y.${z! + 1}-0.0.pre.$commits';
} }
} }
......
...@@ -12,7 +12,7 @@ import 'package:flutter_tools/src/base/io.dart'; ...@@ -12,7 +12,7 @@ import 'package:flutter_tools/src/base/io.dart';
import 'package:flutter_tools/src/base/platform.dart'; import 'package:flutter_tools/src/base/platform.dart';
import 'package:flutter_tools/src/base/terminal.dart'; import 'package:flutter_tools/src/base/terminal.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
import 'package:flutter_tools/src/runner/flutter_command.dart'; import 'package:flutter_tools/src/runner/flutter_command.dart';
import 'package:flutter_tools/src/runner/flutter_command_runner.dart'; import 'package:flutter_tools/src/runner/flutter_command_runner.dart';
import 'package:flutter_tools/src/version.dart'; import 'package:flutter_tools/src/version.dart';
......
...@@ -14,7 +14,7 @@ import 'package:flutter_tools/src/base/process.dart'; ...@@ -14,7 +14,7 @@ import 'package:flutter_tools/src/base/process.dart';
import 'package:flutter_tools/src/base/time.dart'; import 'package:flutter_tools/src/base/time.dart';
import 'package:flutter_tools/src/base/utils.dart'; import 'package:flutter_tools/src/base/utils.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/globals.dart' as globals; import 'package:flutter_tools/src/globals_null_migrated.dart' as globals;
import 'package:flutter_tools/src/version.dart'; import 'package:flutter_tools/src/version.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
...@@ -61,17 +61,6 @@ void main() { ...@@ -61,17 +61,6 @@ void main() {
}); });
testUsingContext('prints nothing when Flutter installation looks fresh', () async { testUsingContext('prints nothing when Flutter installation looks fresh', () async {
fakeData(
mockProcessManager,
mockCache,
localCommitDate: getChannelUpToDateVersion(),
// Server will be pinged because we haven't pinged within last x days
expectServerPing: true,
remoteCommitDate: getChannelOutOfDateVersion(),
expectSetStamp: true,
channel: channel,
);
processManager.addCommand(const FakeCommand( processManager.addCommand(const FakeCommand(
command: <String>['git', '-c', 'log.showSignature=false', 'log', '-n', '1', '--pretty=format:%H'], command: <String>['git', '-c', 'log.showSignature=false', 'log', '-n', '1', '--pretty=format:%H'],
stdout: '1234abcd', stdout: '1234abcd',
...@@ -116,7 +105,40 @@ void main() { ...@@ -116,7 +105,40 @@ void main() {
command: <String>['git', 'remote'], command: <String>['git', 'remote'],
)); ));
await globals.flutterVersion.checkFlutterVersionFreshness(); processManager.addCommands(<FakeCommand>[
const FakeCommand(
command: <String>['git', '-c', 'log.showSignature=false', 'log', '-n', '1', '--pretty=format:%ar'],
stdout: '1 second ago',
),
FakeCommand(
command: const <String>['git', '-c', 'log.showSignature=false', 'log', '-n', '1', '--pretty=format:%ad', '--date=iso'],
stdout: getChannelUpToDateVersion().toString(),
),
FakeCommand(
command: const <String>['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
stdout: channel,
),
]);
final FlutterVersion flutterVersion = globals.flutterVersion;
await flutterVersion.checkFlutterVersionFreshness();
expect(flutterVersion.channel, channel);
expect(flutterVersion.frameworkRevision, '1234abcd');
expect(flutterVersion.frameworkRevisionShort, '1234abcd');
expect(flutterVersion.frameworkVersion, '0.0.0-unknown');
expect(
flutterVersion.toString(),
'Flutter • channel $channel • unknown source\n'
'Framework • revision 1234abcd (1 second ago) • ${getChannelUpToDateVersion()}\n'
'Engine • revision \n'
'Tools • Dart null',
);
expect(flutterVersion.frameworkAge, '1 second ago');
expect(flutterVersion.getVersionString(), '$channel/1234abcd');
expect(flutterVersion.getBranchName(), channel);
expect(flutterVersion.getVersionString(redactUnknownBranches: true), '$channel/1234abcd');
expect(flutterVersion.getBranchName(redactUnknownBranches: true), channel);
_expectVersionMessage(''); _expectVersionMessage('');
expect(processManager.hasRemainingExpectations, isFalse); expect(processManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
...@@ -291,39 +313,6 @@ void main() { ...@@ -291,39 +313,6 @@ void main() {
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Cache: () => mockCache, Cache: () => mockCache,
}); });
testUsingContext('versions comparison', () async {
fakeData(
mockProcessManager,
mockCache,
localCommitDate: getChannelOutOfDateVersion(),
errorOnFetch: true,
expectServerPing: true,
expectSetStamp: true,
channel: channel,
);
final FlutterVersion version = globals.flutterVersion;
when(mockProcessManager.runSync(
<String>['git', 'merge-base', '--is-ancestor', 'abcdef', '123456'],
workingDirectory: anyNamed('workingDirectory'),
)).thenReturn(ProcessResult(1, 0, '', ''));
expect(
version.checkRevisionAncestry(
tentativeDescendantRevision: '123456',
tentativeAncestorRevision: 'abcdef',
),
true);
verify(mockProcessManager.runSync(
<String>['git', 'merge-base', '--is-ancestor', 'abcdef', '123456'],
workingDirectory: anyNamed('workingDirectory'),
));
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => mockProcessManager,
});
}); });
group('$VersionCheckStamp for $channel', () { group('$VersionCheckStamp for $channel', () {
...@@ -449,6 +438,42 @@ void main() { ...@@ -449,6 +438,42 @@ void main() {
}); });
} }
testUsingContext('version handles unknown branch', () async {
processManager.addCommands(<FakeCommand>[
const FakeCommand(
command: <String>['git', '-c', 'log.showSignature=false', 'log', '-n', '1', '--pretty=format:%H'],
stdout: '1234abcd',
),
const FakeCommand(
command: <String>['git', 'tag', '--points-at', '1234abcd'],
),
const FakeCommand(
command: <String>['git', 'describe', '--match', '*.*.*', '--long', '--tags', '1234abcd'],
stdout: '0.1.2-3-1234abcd',
),
const FakeCommand(
command: <String>['git', 'rev-parse', '--abbrev-ref', '--symbolic', '@{u}'],
stdout: 'feature-branch',
),
const FakeCommand(
command: <String>['git', 'rev-parse', '--abbrev-ref', 'HEAD'],
stdout: 'feature-branch',
),
]);
final FlutterVersion flutterVersion = globals.flutterVersion;
expect(flutterVersion.channel, 'feature-branch');
expect(flutterVersion.getVersionString(), 'feature-branch/1234abcd');
expect(flutterVersion.getBranchName(), 'feature-branch');
expect(flutterVersion.getVersionString(redactUnknownBranches: true), '[user-branch]/1234abcd');
expect(flutterVersion.getBranchName(redactUnknownBranches: true), '[user-branch]');
expect(processManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
FlutterVersion: () => FlutterVersion(clock: _testClock),
ProcessManager: () => processManager,
Cache: () => mockCache,
});
testUsingContext('GitTagVersion', () { testUsingContext('GitTagVersion', () {
const String hash = 'abcdef'; const String hash = 'abcdef';
GitTagVersion gitTagVersion; GitTagVersion gitTagVersion;
......
...@@ -526,11 +526,6 @@ class FakeFlutterVersion implements FlutterVersion { ...@@ -526,11 +526,6 @@ class FakeFlutterVersion implements FlutterVersion {
_didCheckFlutterVersionFreshness = true; _didCheckFlutterVersionFreshness = true;
} }
@override
bool checkRevisionAncestry({String tentativeDescendantRevision, String tentativeAncestorRevision}) {
throw UnimplementedError();
}
@override @override
Future<void> ensureVersionFile() async { } Future<void> ensureVersionFile() async { }
......
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