Start using bin/cache/engine.{stamp|realm} instead of bin/internal/engine.{realm|version}. (#164352)

Towards https://github.com/flutter/flutter/issues/164315.

See also:
https://github.com/flutter/flutter/blob/master/docs/tool/Engine-artifacts.md.

There are more usages in `flutter/flutter`, but some will require more
specialized review (i.e. from release folks, or the Dart SDK team), so
I'll split those off.

~~Requires https://github.com/flutter/flutter/pull/164317 to merge
first.~~ ✅
This commit is contained in:
Matan Lurey
2025-03-01 16:54:33 -08:00
committed by GitHub
parent 0c055f2c50
commit 71d50a1616
16 changed files with 60 additions and 39 deletions

View File

@@ -44,7 +44,7 @@ void configureProject(Project project, String outputDir) {
String storageUrl = System.getenv('FLUTTER_STORAGE_BASE_URL') ?: "https://storage.googleapis.com"
String engineRealm = Paths.get(getFlutterRoot(project), "bin", "internal", "engine.realm")
String engineRealm = Paths.get(getFlutterRoot(project), "bin", "cache", "engine.realm")
.toFile().text.trim()
if (engineRealm) {
engineRealm += "/"
@@ -57,7 +57,7 @@ void configureProject(Project project, String outputDir) {
url "$storageUrl/${engineRealm}download.flutter.io"
}
}
String engineVersion = Paths.get(getFlutterRoot(project), "bin", "internal", "engine.version")
String engineVersion = Paths.get(getFlutterRoot(project), "bin", "cache", "engine.stamp")
.toFile().text.trim()
project.dependencies {
// Add the embedding dependency.
@@ -179,7 +179,7 @@ projectsEvaluated {
// Configure the `assembleAar<variantName>` task for each plugin's projects and make
// the module's equivalent task depend on the plugin's task.
String variantName = variant.name.capitalize()
Task moduleProjectTask = moduleProject.tasks.named("assembleAar$variantName").get()
assert(moduleProjectTask != null)
Task pluginProjectTask = pluginProject.tasks.named("assembleAar$variantName").get()

View File

@@ -25,8 +25,8 @@ val engineVersion =
Paths.get(
flutterRoot.absolutePath,
"bin",
"internal",
"engine.version"
"cache",
"engine.stamp"
)
.toFile()
.readText()
@@ -36,7 +36,7 @@ var engineRealm =
Paths.get(
flutterRoot.absolutePath,
"bin",
"internal",
"cache",
"engine.realm"
)
.toFile()

View File

@@ -213,9 +213,9 @@ class FlutterPlugin implements Plugin<Project> {
engineVersion = useLocalEngine()
? "+" // Match any version since there's only one.
: "1.0.0-" + Paths.get(flutterRoot.absolutePath, "bin", "internal", "engine.version").toFile().text.trim()
: "1.0.0-" + Paths.get(flutterRoot.absolutePath, "bin", "cache", "engine.stamp").toFile().text.trim()
engineRealm = Paths.get(flutterRoot.absolutePath, "bin", "internal", "engine.realm").toFile().text.trim()
engineRealm = Paths.get(flutterRoot.absolutePath, "bin", "cache", "engine.realm").toFile().text.trim()
if (engineRealm) {
engineRealm += "/"
}

View File

@@ -165,7 +165,7 @@ class SourceVisitor implements ResolvedFiles {
///
/// If the [Artifact] points to a directory then all child files are included.
/// To increase the performance of builds that use a known revision of Flutter,
/// these are updated to point towards the engine.version file instead of
/// these are updated to point towards the `engine.stamp` file instead of
/// the artifact itself.
void visitArtifact(Artifact artifact, TargetPlatform? platform, BuildMode? mode) {
// This is not a local engine.
@@ -173,8 +173,8 @@ class SourceVisitor implements ResolvedFiles {
sources.add(
environment.flutterRootDir
.childDirectory('bin')
.childDirectory('internal')
.childFile('engine.version'),
.childDirectory('cache')
.childFile('engine.stamp'),
);
return;
}
@@ -199,7 +199,7 @@ class SourceVisitor implements ResolvedFiles {
///
/// If the [Artifact] points to a directory then all child files are included.
/// To increase the performance of builds that use a known revision of Flutter,
/// these are updated to point towards the engine.version file instead of
/// these are updated to point towards the `engine.stamp` file instead of
/// the artifact itself.
void visitHostArtifact(HostArtifact artifact) {
// This is not a local engine.
@@ -207,8 +207,8 @@ class SourceVisitor implements ResolvedFiles {
sources.add(
environment.flutterRootDir
.childDirectory('bin')
.childDirectory('internal')
.childFile('engine.version'),
.childDirectory('cache')
.childFile('engine.stamp'),
);
return;
}

View File

@@ -491,7 +491,7 @@ class Cache {
/// The current version of the Flutter engine the flutter tool will download.
String get engineRevision {
_engineRevision ??= getVersionFor('engine');
_engineRevision ??= getStampFor('engine');
if (_engineRevision == null) {
throwToolExit('Could not determine engine revision.');
}
@@ -684,12 +684,14 @@ class Cache {
return versionFile.existsSync() ? versionFile.readAsStringSync().trim() : null;
}
// TODO(matanlurey): Remove the ability to do "generic" realms, and special case for engine.
// https://github.com/flutter/flutter/issues/164315
String? getRealmFor(String artifactName) {
final File realmFile = _fileSystem.file(
_fileSystem.path.join(
_rootOverride?.path ?? flutterRoot!,
'bin',
'internal',
'cache',
'$artifactName.realm',
),
);
@@ -930,6 +932,9 @@ abstract class EngineCachedArtifact extends CachedArtifact {
@override
final String stampName;
@override
String? get version => cache.engineRevision;
/// Return a list of (directory path, download URL path) tuples.
List<List<String>> getBinaryDirs();

View File

@@ -171,7 +171,7 @@ class FlutterWebSdk extends CachedArtifact {
Directory get location => cache.getWebSdkDirectory();
@override
String? get version => cache.getVersionFor('engine');
String? get version => cache.engineRevision;
@override
Future<void> updateInner(
@@ -568,7 +568,7 @@ class FlutterRunnerSDKArtifacts extends CachedArtifact {
Directory get location => cache.getArtifactDirectory('flutter_runner');
@override
String? get version => cache.getVersionFor('engine');
String? get version => cache.engineRevision;
@override
Future<void> updateInner(
@@ -627,7 +627,7 @@ class FlutterRunnerDebugSymbols extends CachedArtifact {
Directory get location => cache.getArtifactDirectory(name);
@override
String? get version => cache.getVersionFor('engine');
String? get version => cache.engineRevision;
Future<void> _downloadDebugSymbols(String targetArch, ArtifactUpdater artifactUpdater) async {
final String packageName = 'fuchsia-debug-symbols-$targetArch';

View File

@@ -54,7 +54,7 @@ void main() {
fileSystem: memoryFileSystem,
processManager: FakeProcessManager.any(),
);
rootOverride.childDirectory('bin').childDirectory('internal').childFile('engine.version')
rootOverride.childDirectory('bin').childDirectory('cache').childFile('engine.stamp')
..createSync(recursive: true)
..writeAsStringSync(engineRevision);
});
@@ -346,7 +346,7 @@ void main() {
fileSystem: memoryFileSystem,
processManager: FakeProcessManager.any(),
);
rootOverride.childDirectory('bin').childDirectory('internal').childFile('engine.version')
rootOverride.childDirectory('bin').childDirectory('cache').childFile('engine.stamp')
..createSync(recursive: true)
..writeAsStringSync(engineRevision);
});

View File

@@ -260,7 +260,7 @@ void main() {
);
test(
'Non-local engine builds use the engine.version file as an Artifact dependency',
'Non-local engine builds use the engine.stamp file as an Artifact dependency',
() => testbed.run(() {
final Artifacts artifacts = Artifacts.test();
final Environment environment = Environment.test(
@@ -279,7 +279,7 @@ void main() {
);
fizzSource.accept(visitor);
expect(visitor.sources.single.path, contains('engine.version'));
expect(visitor.sources.single.path, contains('engine.stamp'));
}),
);
}

View File

@@ -356,14 +356,14 @@ void main() {
testWithoutContext('a non-empty realm is included in the storage url', () async {
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final Directory internalDir = fileSystem.currentDirectory
final Directory cacheDir = fileSystem.currentDirectory
.childDirectory('bin')
.childDirectory('internal');
final File engineVersionFile = internalDir.childFile('engine.version');
.childDirectory('cache');
final File engineVersionFile = cacheDir.childFile('engine.stamp');
engineVersionFile.createSync(recursive: true);
engineVersionFile.writeAsStringSync('abcdef');
final File engineRealmFile = internalDir.childFile('engine.realm');
final File engineRealmFile = cacheDir.childFile('engine.realm');
engineRealmFile.createSync(recursive: true);
engineRealmFile.writeAsStringSync('flutter_archives_v2');
@@ -465,7 +465,7 @@ void main() {
expect(packageUrl, isNotNull);
expect(
packageUrl.toString(),
'https://storage.googleapis.com/flutter_infra_release/flutter/null/package_dir.zip',
'https://storage.googleapis.com/flutter_infra_release/flutter/abc123/package_dir.zip',
);
final Directory dir =
@@ -903,7 +903,10 @@ void main() {
canvasKitVersionFile.createSync(recursive: true);
canvasKitVersionFile.writeAsStringSync('abcdefg');
final File engineVersionFile = internalDir.childFile('engine.version');
final Directory cacheDir = fileSystem.currentDirectory
.childDirectory('bin')
.childDirectory('cache');
final File engineVersionFile = cacheDir.childFile('engine.stamp');
engineVersionFile.createSync(recursive: true);
engineVersionFile.writeAsStringSync('hijklmnop');
@@ -953,7 +956,10 @@ void main() {
canvasKitVersionFile.createSync(recursive: true);
canvasKitVersionFile.writeAsStringSync('abcdefg');
final File engineVersionFile = internalDir.childFile('engine.version');
final Directory cacheDir = fileSystem.currentDirectory
.childDirectory('bin')
.childDirectory('cache');
final File engineVersionFile = cacheDir.childFile('engine.stamp');
engineVersionFile.createSync(recursive: true);
engineVersionFile.writeAsStringSync('hijklmnop');
@@ -999,6 +1005,13 @@ void main() {
final FakeArtifactUpdater artifactUpdater = FakeArtifactUpdater();
final FlutterWebSdk webSdk = FlutterWebSdk(cache);
final Directory cacheDir = fileSystem.currentDirectory
.childDirectory('bin')
.childDirectory('cache');
final File engineVersionFile = cacheDir.childFile('engine.stamp');
engineVersionFile.createSync(recursive: true);
engineVersionFile.writeAsStringSync('hijklmnop');
artifactUpdater.onDownloadZipArchive = (String message, Uri uri, Directory location) {
location.createSync(recursive: true);
location.childFile('foo').createSync();
@@ -1347,6 +1360,9 @@ class FakeSecondaryCache extends Fake implements Cache {
@override
String get storageBaseUrl => 'https://storage.googleapis.com';
@override
String get engineRevision => version ?? 'abc123';
@override
Directory getDownloadDir() => artifactDirectory;