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,
......
This diff is collapsed.
...@@ -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