nixpkgs/pkgs/development/compilers/flutter/patches/flutter3/move-cache.patch
FlafyDev 570f3efd1d flutter: Separate cache and unwrapped derivations
flutter-unwrapped will now not come with engine artifacts in its cache directory(`$out/bin/cache`).

To specify a different cache directory, set FLUTTER_CACHE_DIR.

Flutter's wrapper now sets FLUTTER_CACHE_DIR to set engine artifacts.

The sh file `$out/bin/internal/shared.sh` runs when launching Flutter and calls `"$FLUTTER_ROOT/bin/cache/` instead of our environment variable `FLUTTER_CACHE_DIR`.
I decided not to patch it since the script doesn't require engine artifacts(which are the only thing not added by the unwrapped derivation), so it shouldn't fail, and patching it will just be harder to maintain.
2023-06-30 15:23:34 +03:00

54 lines
2.5 KiB
Diff

diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart
index dd80b1e46e..8e54517765 100644
--- a/packages/flutter_tools/lib/src/cache.dart
+++ b/packages/flutter_tools/lib/src/cache.dart
@@ -22,6 +22,7 @@ import 'base/user_messages.dart';
import 'build_info.dart';
import 'convert.dart';
import 'features.dart';
+import 'globals.dart' as globals;
const String kFlutterRootEnvironmentVariableName = 'FLUTTER_ROOT'; // should point to //flutter/ (root of flutter/flutter repo)
const String kFlutterEngineEnvironmentVariableName = 'FLUTTER_ENGINE'; // should point to //engine/src/ (root of flutter/engine repo)
@@ -318,8 +319,13 @@ class Cache {
return;
}
assert(_lock == null);
+ final Directory dir = _fileSystem.directory(_fileSystem.path.join(globals.fsUtils.homeDirPath!, '.cache', 'flutter'));
+ if (!dir.existsSync()) {
+ dir.createSync(recursive: true);
+ globals.os.chmod(dir, '755');
+ }
final File lockFile =
- _fileSystem.file(_fileSystem.path.join(flutterRoot!, 'bin', 'cache', 'lockfile'));
+ _fileSystem.file(_fileSystem.path.join(globals.fsUtils.homeDirPath!, '.cache', 'flutter', 'lockfile'));
try {
_lock = lockFile.openSync(mode: FileMode.write);
} on FileSystemException catch (e) {
@@ -378,8 +384,7 @@ class Cache {
String get devToolsVersion {
if (_devToolsVersion == null) {
- const String devToolsDirPath = 'dart-sdk/bin/resources/devtools';
- final Directory devToolsDir = getCacheDir(devToolsDirPath, shouldCreate: false);
+ final Directory devToolsDir = _fileSystem.directory(_fileSystem.path.join(flutterRoot!, 'bin/cache/dart-sdk/bin/resources/devtools'));
if (!devToolsDir.existsSync()) {
throw Exception('Could not find directory at ${devToolsDir.path}');
}
diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart
index 1c31c1b5db..76c7210d3b 100644
--- a/packages/flutter_tools/lib/src/cache.dart
+++ b/packages/flutter_tools/lib/src/cache.dart
@@ -529,6 +529,11 @@ class Cache {
/// Return the top-level directory in the cache; this is `bin/cache`.
Directory getRoot() {
+ const Platform platform = LocalPlatform();
+ if (platform.environment.containsKey('FLUTTER_CACHE_DIR')) {
+ return _fileSystem.directory(platform.environment['FLUTTER_CACHE_DIR']);
+ }
+
if (_rootOverride != null) {
return _fileSystem.directory(_fileSystem.path.join(_rootOverride!.path, 'bin', 'cache'));
} else {