use root directory as the default for rootOverride in Cache.test constructor (#158201)
While doing some hacking on `Cache` in https://github.com/flutter/flutter/pull/158081, I noticed that [`Cache.test`](de93182753/packages/flutter_tools/lib/src/cache.dart (L139)
) allows the caller to tell Cache to use some given directory as the flutter root (instead of depending on the static global [`Cache.flutterRoot`](4f3976a4f2/packages/flutter_tools/lib/src/cache.dart (L206)
)). This has a default value, `/cache`. However, `/cache` is an unintuitive name for the root directory of a Flutter installation. This led to confusion when updating some tests. I wanted to create `/bin/cache/engine-dart-sdk.stamp` for tests, but in reality I needed to create `/cache/bin/cache/engine-dart-sdk.stamp`. This PR changes this default to the current directory of the file system (which I'm guessing is `/` for all intents and purposes). <details> <summary> Pre-launch checklist </summary> </details>
This commit is contained in:
parent
b6fef5cfda
commit
8d3cca43b2
@ -144,11 +144,20 @@ class Cache {
|
|||||||
Platform? platform,
|
Platform? platform,
|
||||||
required ProcessManager processManager,
|
required ProcessManager processManager,
|
||||||
}) {
|
}) {
|
||||||
|
if (rootOverride?.fileSystem != null &&
|
||||||
|
fileSystem != null &&
|
||||||
|
rootOverride!.fileSystem != fileSystem) {
|
||||||
|
throw ArgumentError(
|
||||||
|
'If rootOverride and fileSystem are both non-null, '
|
||||||
|
'rootOverride.fileSystem must be the same as fileSystem.',
|
||||||
|
'fileSystem'
|
||||||
|
);
|
||||||
|
}
|
||||||
fileSystem ??= rootOverride?.fileSystem ?? MemoryFileSystem.test();
|
fileSystem ??= rootOverride?.fileSystem ?? MemoryFileSystem.test();
|
||||||
platform ??= FakePlatform(environment: <String, String>{});
|
platform ??= FakePlatform(environment: <String, String>{});
|
||||||
logger ??= BufferLogger.test();
|
logger ??= BufferLogger.test();
|
||||||
return Cache(
|
return Cache(
|
||||||
rootOverride: rootOverride ?? fileSystem.directory('cache'),
|
rootOverride: rootOverride ?? fileSystem.currentDirectory,
|
||||||
artifacts: artifacts ?? <ArtifactSet>[],
|
artifacts: artifacts ?? <ArtifactSet>[],
|
||||||
logger: logger,
|
logger: logger,
|
||||||
fileSystem: fileSystem,
|
fileSystem: fileSystem,
|
||||||
|
@ -24,7 +24,7 @@ void main() {
|
|||||||
setUp(() {
|
setUp(() {
|
||||||
fileSystem = MemoryFileSystem.test();
|
fileSystem = MemoryFileSystem.test();
|
||||||
gradleWrapperDirectory =
|
gradleWrapperDirectory =
|
||||||
fileSystem.directory('cache/bin/cache/artifacts/gradle_wrapper');
|
fileSystem.directory('bin/cache/artifacts/gradle_wrapper');
|
||||||
gradleWrapperDirectory.createSync(recursive: true);
|
gradleWrapperDirectory.createSync(recursive: true);
|
||||||
gradleWrapperDirectory
|
gradleWrapperDirectory
|
||||||
.childFile('gradlew')
|
.childFile('gradlew')
|
||||||
|
@ -338,7 +338,6 @@ void main() {
|
|||||||
testWithoutContext('a non-empty realm is included in the storage url', () async {
|
testWithoutContext('a non-empty realm is included in the storage url', () async {
|
||||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||||
final Directory internalDir = fileSystem.currentDirectory
|
final Directory internalDir = fileSystem.currentDirectory
|
||||||
.childDirectory('cache')
|
|
||||||
.childDirectory('bin')
|
.childDirectory('bin')
|
||||||
.childDirectory('internal');
|
.childDirectory('internal');
|
||||||
final File engineVersionFile = internalDir.childFile('engine.version');
|
final File engineVersionFile = internalDir.childFile('engine.version');
|
||||||
@ -803,7 +802,6 @@ void main() {
|
|||||||
testWithoutContext('FlutterWebSdk fetches web artifacts and deletes previous directory contents', () async {
|
testWithoutContext('FlutterWebSdk fetches web artifacts and deletes previous directory contents', () async {
|
||||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||||
final Directory internalDir = fileSystem.currentDirectory
|
final Directory internalDir = fileSystem.currentDirectory
|
||||||
.childDirectory('cache')
|
|
||||||
.childDirectory('bin')
|
.childDirectory('bin')
|
||||||
.childDirectory('internal');
|
.childDirectory('internal');
|
||||||
final File canvasKitVersionFile = internalDir.childFile('canvaskit.version');
|
final File canvasKitVersionFile = internalDir.childFile('canvaskit.version');
|
||||||
@ -842,7 +840,7 @@ void main() {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
expect(locations, <String>[
|
expect(locations, <String>[
|
||||||
'cache/bin/cache/flutter_web_sdk',
|
'/bin/cache/flutter_web_sdk',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
expect(webCacheDirectory.childFile('foo'), exists);
|
expect(webCacheDirectory.childFile('foo'), exists);
|
||||||
@ -852,7 +850,6 @@ void main() {
|
|||||||
testWithoutContext('FlutterWebSdk CanvasKit URL can be overridden via FLUTTER_STORAGE_BASE_URL', () async {
|
testWithoutContext('FlutterWebSdk CanvasKit URL can be overridden via FLUTTER_STORAGE_BASE_URL', () async {
|
||||||
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
|
||||||
final Directory internalDir = fileSystem.currentDirectory
|
final Directory internalDir = fileSystem.currentDirectory
|
||||||
.childDirectory('cache')
|
|
||||||
.childDirectory('bin')
|
.childDirectory('bin')
|
||||||
.childDirectory('internal');
|
.childDirectory('internal');
|
||||||
final File canvasKitVersionFile = internalDir.childFile('canvaskit.version');
|
final File canvasKitVersionFile = internalDir.childFile('canvaskit.version');
|
||||||
@ -909,7 +906,7 @@ void main() {
|
|||||||
handler.addError(webCacheDirectory, FileSystemOp.delete, const FileSystemException('', '', OSError('', 2)));
|
handler.addError(webCacheDirectory, FileSystemOp.delete, const FileSystemException('', '', OSError('', 2)));
|
||||||
|
|
||||||
await expectLater(() => webSdk.updateInner(artifactUpdater, fileSystem, FakeOperatingSystemUtils()), throwsToolExit(
|
await expectLater(() => webSdk.updateInner(artifactUpdater, fileSystem, FakeOperatingSystemUtils()), throwsToolExit(
|
||||||
message: RegExp('Unable to delete file or directory at "cache/bin/cache/flutter_web_sdk"'),
|
message: RegExp('Unable to delete file or directory at "/bin/cache/flutter_web_sdk"'),
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1108,11 +1105,11 @@ void main() {
|
|||||||
Platform: () => FakePlatform(),
|
Platform: () => FakePlatform(),
|
||||||
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
|
ProcessManager: () => FakeProcessManager.list(<FakeCommand>[
|
||||||
const FakeCommand(command: <String>[
|
const FakeCommand(command: <String>[
|
||||||
'/cache/bin/cache/flutter_gradle_wrapper.rand0/gradlew',
|
'/bin/cache/flutter_gradle_wrapper.rand0/gradlew',
|
||||||
'-b',
|
'-b',
|
||||||
'packages/flutter_tools/gradle/resolve_dependencies.gradle',
|
'packages/flutter_tools/gradle/resolve_dependencies.gradle',
|
||||||
'--project-cache-dir',
|
'--project-cache-dir',
|
||||||
'cache/bin/cache/flutter_gradle_wrapper.rand0',
|
'/bin/cache/flutter_gradle_wrapper.rand0',
|
||||||
'resolveDependencies',
|
'resolveDependencies',
|
||||||
]),
|
]),
|
||||||
]),
|
]),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user