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 {
Future<RunResult> run(
List<String> cmd, {
bool throwOnError = false,
RunResultChecker allowedFailures,
String workingDirectory,
RunResultChecker? allowedFailures,
String? workingDirectory,
bool allowReentrantFlutter = false,
Map<String, String> environment,
Duration timeout,
Map<String, String>? environment,
Duration? timeout,
int timeoutRetries = 0,
});
......@@ -180,10 +180,10 @@ abstract class ProcessUtils {
List<String> cmd, {
bool throwOnError = false,
bool verboseExceptions = false,
RunResultChecker allowedFailures,
RunResultChecker? allowedFailures,
bool hideStdout = false,
String workingDirectory,
Map<String, String> environment,
String? workingDirectory,
Map<String, String>? environment,
bool allowReentrantFlutter = false,
Encoding encoding = systemEncoding,
});
......@@ -192,9 +192,9 @@ abstract class ProcessUtils {
/// directory. Completes when the process has been started.
Future<Process> start(
List<String> cmd, {
String workingDirectory,
String? workingDirectory,
bool allowReentrantFlutter = false,
Map<String, String> environment,
Map<String, String>? environment,
});
/// This runs the command and streams stdout/stderr from the child process to
......@@ -210,24 +210,24 @@ abstract class ProcessUtils {
/// treated as errors, just as if they had been logged to stderr instead.
Future<int> stream(
List<String> cmd, {
String workingDirectory,
String? workingDirectory,
bool allowReentrantFlutter = false,
String prefix = '',
bool trace = false,
RegExp filter,
RegExp stdoutErrorMatcher,
StringConverter mapFunction,
Map<String, String> environment,
RegExp? filter,
RegExp? stdoutErrorMatcher,
StringConverter? mapFunction,
Map<String, String>? environment,
});
bool exitsHappySync(
List<String> cli, {
Map<String, String> environment,
Map<String, String>? environment,
});
Future<bool> exitsHappy(
List<String> cli, {
Map<String, String> environment,
Map<String, String>? environment,
});
}
......
......@@ -6,7 +6,7 @@
import '../base/common.dart';
import '../cache.dart';
import '../globals.dart' as globals;
import '../globals_null_migrated.dart' as globals;
import '../runner/flutter_command.dart';
import '../version.dart';
......
......@@ -15,7 +15,7 @@ import '../dart/pub.dart';
import '../features.dart';
import '../flutter_manifest.dart';
import '../flutter_project_metadata.dart';
import '../globals.dart' as globals;
import '../globals_null_migrated.dart' as globals;
import '../project.dart';
import '../reporting/reporting.dart';
import '../runner/flutter_command.dart';
......
......@@ -18,7 +18,7 @@ import '../convert.dart';
import '../dart/pub.dart';
import '../features.dart';
import '../flutter_project_metadata.dart';
import '../globals.dart' as globals;
import '../globals_null_migrated.dart' as globals;
import '../project.dart';
import '../runner/flutter_command.dart';
import '../template.dart';
......
......@@ -25,7 +25,6 @@ import 'persistent_tool_state.dart';
import 'project.dart';
import 'reporting/reporting.dart';
import 'runner/local_engine.dart';
import 'version.dart';
export 'globals_null_migrated.dart';
......@@ -49,7 +48,6 @@ CocoaPodsValidator get cocoapodsValidator => context.get<CocoaPodsValidator>();
LocalEngineLocator get localEngineLocator => context.get<LocalEngineLocator>();
CocoaPods get cocoaPods => context.get<CocoaPods>();
FlutterVersion get flutterVersion => context.get<FlutterVersion>();
FuchsiaArtifacts get fuchsiaArtifacts => context.get<FuchsiaArtifacts>();
IOSSimulatorUtils get iosSimulatorUtils => context.get<IOSSimulatorUtils>();
IOSWorkflow get iosWorkflow => context.get<IOSWorkflow>();
......
......@@ -23,6 +23,7 @@ import 'base/time.dart';
import 'base/user_messages.dart';
import 'cache.dart';
import 'ios/plist_parser.dart';
import 'version.dart';
Cache get cache => context.get<Cache>()!;
Config get config => context.get<Config>()!;
......@@ -32,6 +33,7 @@ OperatingSystemUtils get os => context.get<OperatingSystemUtils>()!;
Signals get signals => context.get<Signals>() ?? LocalSignals.instance;
AndroidStudio? get androidStudio => context.get<AndroidStudio>();
AndroidSdk? get androidSdk => context.get<AndroidSdk>();
FlutterVersion get flutterVersion => context.get<FlutterVersion>()!;
/// Currently active implementation of the file system.
///
......
......@@ -13,7 +13,7 @@ import 'base/logger.dart';
import 'build_info.dart';
import 'convert.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, {
File outputFile,
......
This diff is collapsed.
......@@ -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/terminal.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_runner.dart';
import 'package:flutter_tools/src/version.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/utils.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:mockito/mockito.dart';
......@@ -61,17 +61,6 @@ void main() {
});
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(
command: <String>['git', '-c', 'log.showSignature=false', 'log', '-n', '1', '--pretty=format:%H'],
stdout: '1234abcd',
......@@ -116,7 +105,40 @@ void main() {
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('');
expect(processManager.hasRemainingExpectations, isFalse);
}, overrides: <Type, Generator>{
......@@ -291,39 +313,6 @@ void main() {
ProcessManager: () => mockProcessManager,
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', () {
......@@ -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', () {
const String hash = 'abcdef';
GitTagVersion gitTagVersion;
......
......@@ -526,11 +526,6 @@ class FakeFlutterVersion implements FlutterVersion {
_didCheckFlutterVersionFreshness = true;
}
@override
bool checkRevisionAncestry({String tentativeDescendantRevision, String tentativeAncestorRevision}) {
throw UnimplementedError();
}
@override
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