Unverified Commit 2fb53d83 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] remove all globals from cache and cache_test (#69505)

parent 9b201dd0
This diff is collapsed.
......@@ -130,7 +130,7 @@ class PrecacheCommand extends FlutterCommand {
Future<FlutterCommandResult> runCommand() async {
// Re-lock the cache.
if (_platform.environment['FLUTTER_ALREADY_LOCKED'] != 'true') {
await Cache.lock();
await _cache.lock();
}
if (boolArg('force')) {
_cache.clearStampFiles();
......
......@@ -120,6 +120,7 @@ Future<T> runInContext<T>(
fileSystem: globals.fs,
logger: globals.logger,
platform: globals.platform,
osUtils: globals.os,
),
CocoaPods: () => CocoaPods(
fileSystem: globals.fs,
......
......@@ -962,7 +962,7 @@ abstract class FlutterCommand extends Command<void> {
void _registerSignalHandlers(String commandPath, DateTime startTime) {
final SignalHandler handler = (io.ProcessSignal s) {
Cache.releaseLock();
globals.cache.releaseLock();
_sendPostUsage(
commandPath,
const FlutterCommandResult(ExitStatus.killed),
......@@ -1035,7 +1035,7 @@ abstract class FlutterCommand extends Command<void> {
await globals.cache.updateAll(<DevelopmentArtifact>{DevelopmentArtifact.universal});
await globals.cache.updateAll(await requiredArtifacts);
}
Cache.releaseLock();
globals.cache.releaseLock();
await validateCommand();
......
......@@ -235,7 +235,7 @@ class FlutterCommandRunner extends CommandRunner<void> {
globals.logger.quiet = topLevelResults['quiet'] as bool;
if (globals.platform.environment['FLUTTER_ALREADY_LOCKED'] != 'true') {
await Cache.lock();
await globals.cache.lock();
}
if (topLevelResults['suppress-analytics'] as bool) {
......
......@@ -484,7 +484,7 @@ class FlutterVersion {
/// 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.
Future<DateTime> _getLatestAvailableFlutterDate() async {
Cache.checkLockAcquired();
globals.cache.checkLockAcquired();
final VersionCheckStamp versionCheckStamp = await VersionCheckStamp.load();
if (versionCheckStamp.lastTimeVersionWasChecked != null) {
......
......@@ -20,7 +20,7 @@ void main() {
setUp(() {
cache = MockCache();
// Release lock between test cases.
Cache.releaseLock();
cache.releaseLock();
when(cache.isUpToDate()).thenAnswer((Invocation _) => Future<bool>.value(false));
when(cache.updateAll(any)).thenAnswer((Invocation invocation) {
......@@ -39,9 +39,8 @@ void main() {
);
await createTestCommandRunner(command).run(const <String>['precache']);
expect(Cache.isLocked(), isTrue);
// Do not throw StateError, lock is acquired.
expect(() => Cache.checkLockAcquired(platform), returnsNormally);
expect(() => cache.checkLockAcquired(), returnsNormally);
});
testUsingContext('precache should not re-entrantly acquire lock', () async {
......@@ -62,7 +61,7 @@ void main() {
expect(Cache.isLocked(), isFalse);
// Do not throw StateError, acquired reentrantly with FLUTTER_ALREADY_LOCKED.
expect(() => Cache.checkLockAcquired(platform), returnsNormally);
expect(() => cache.checkLockAcquired(), returnsNormally);
});
testUsingContext('precache downloads web artifacts on dev branch when feature is enabled.', () async {
......
......@@ -1024,7 +1024,7 @@ plugin1=${plugin1.path}
when(mockAndroidSdk.directory).thenReturn('irrelevant');
final Directory rootDirectory = fileSystem.currentDirectory;
cache = Cache(
cache = Cache.test(
rootOverride: rootDirectory,
fileSystem: fileSystem,
);
......
......@@ -72,7 +72,7 @@ void main() {
'zipStorePath=wrapper/dists\n'
'distributionUrl=https\\://services.gradle.org/distributions/gradle-5.6.2-all.zip\n');
}, overrides: <Type, Generator>{
Cache: () => Cache(rootOverride: tempDir),
Cache: () => Cache.test(rootOverride: tempDir, fileSystem: memoryFileSystem),
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
......@@ -113,7 +113,7 @@ void main() {
'zipStorePath=wrapper/dists\n'
'distributionUrl=https\\://services.gradle.org/distributions/gradle-5.6.2-all.zip\n');
}, overrides: <Type, Generator>{
Cache: () => Cache(rootOverride: tempDir),
Cache: () => Cache.test(rootOverride: tempDir, fileSystem: memoryFileSystem),
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
});
......
......@@ -771,7 +771,12 @@ void _testInMemory(String description, Future<void> testMethod()) {
testFileSystem.file('.packages').writeAsStringSync('\n');
// Transfer needed parts of the Flutter installation folder
// to the in-memory file system used during testing.
transfer(Cache().getArtifactDirectory('gradle_wrapper'), testFileSystem);
transfer(Cache(
fileSystem: globals.fs,
logger: globals.logger,
osUtils: globals.os,
platform: globals.platform,
).getArtifactDirectory('gradle_wrapper'), testFileSystem);
transfer(globals.fs.directory(Cache.flutterRoot)
.childDirectory('packages')
.childDirectory('flutter_tools')
......@@ -801,7 +806,12 @@ void _testInMemory(String description, Future<void> testMethod()) {
overrides: <Type, Generator>{
FileSystem: () => testFileSystem,
ProcessManager: () => FakeProcessManager.any(),
Cache: () => Cache(),
Cache: () => Cache(
logger: globals.logger,
fileSystem: globals.fs,
osUtils: globals.os,
platform: globals.platform,
),
FlutterProjectFactory: () => flutterProjectFactory,
},
);
......
......@@ -57,7 +57,7 @@ void main() {
testUsingContext('honors shouldUpdateCache false', () async {
final DummyFlutterCommand flutterCommand = DummyFlutterCommand(shouldUpdateCache: false);
await flutterCommand.run();
verifyZeroInteractions(cache);
verifyNever(cache.updateAll(any));
expect(flutterCommand.deprecated, isFalse);
expect(flutterCommand.hidden, isFalse);
},
......@@ -352,7 +352,7 @@ void main() {
final Completer<void> checkLockCompleter = Completer<void>();
final DummyFlutterCommand flutterCommand =
DummyFlutterCommand(commandFunction: () async {
await Cache.lock();
await globals.cache.lock();
checkLockCompleter.complete();
final Completer<void> c = Completer<void>();
await c.future;
......@@ -362,13 +362,13 @@ void main() {
unawaited(flutterCommand.run());
await checkLockCompleter.future;
Cache.checkLockAcquired();
globals.cache.checkLockAcquired();
signalController.add(mockSignal);
await completer.future;
await Cache.lock();
Cache.releaseLock();
await globals.cache.lock();
globals.cache.releaseLock();
}, overrides: <Type, Generator>{
ProcessInfo: () => mockProcessInfo,
Signals: () => FakeSignals(
......
......@@ -4,6 +4,9 @@
import 'dart:async';
import 'package:flutter_tools/src/base/file_system.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/os.dart';
import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/device.dart';
......@@ -51,12 +54,12 @@ class FakeDyldEnvironmentArtifact extends ArtifactSet {
};
@override
Future<bool> isUpToDate() => Future<bool>.value(true);
Future<bool> isUpToDate(FileSystem fileSystem) => Future<bool>.value(true);
@override
String get name => 'fake';
@override
Future<void> update(ArtifactUpdater artifactUpdater) async {
Future<void> update(ArtifactUpdater artifactUpdater, Logger logger, FileSystem fileSystem, OperatingSystemUtils operatingSystemUtils) async {
}
}
......@@ -897,5 +897,14 @@ class FakeCache implements Cache {
}
@override
void clearStampFiles() {}
void clearStampFiles() { }
@override
void checkLockAcquired() { }
@override
Future<void> lock() async { }
@override
void releaseLock() { }
}
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