Unverified Commit a2a888ec authored by Yegor's avatar Yegor Committed by GitHub

make CIPD url customizable using FLUTTER_STORAGE_BASE_URL (#94137)

parent 30b6b9e7
......@@ -446,6 +446,29 @@ class Cache {
return overrideUrl;
}
String get cipdBaseUrl {
final String? overrideUrl = _platform.environment['FLUTTER_STORAGE_BASE_URL'];
if (overrideUrl == null) {
return 'https://chrome-infra-packages.appspot.com/dl';
}
final Uri original;
try {
original = Uri.parse(overrideUrl);
} on FormatException catch (err) {
throwToolExit('"FLUTTER_STORAGE_BASE_URL" contains an invalid URI:\n$err');
}
final String cipdOverride = original.replace(
pathSegments: <String>[
...original.pathSegments,
'flutter_infra_release',
'cipd',
],
).toString();
return cipdOverride;
}
bool _hasWarnedAboutStorageOverride = false;
void _maybeWarnAboutStorageOverride(String overrideUrl) {
......
......@@ -198,7 +198,7 @@ class FlutterWebSdk extends CachedArtifact {
}
final String canvasKitVersion = cache.getVersionFor('canvaskit')!;
final String canvasKitUrl = '$_cipdBaseUrl/flutter/web/canvaskit_bundle/+/$canvasKitVersion';
final String canvasKitUrl = '${cache.cipdBaseUrl}/flutter/web/canvaskit_bundle/+/$canvasKitVersion';
return artifactUpdater.downloadZipArchive(
'Downloading CanvasKit...',
Uri.parse(canvasKitUrl),
......@@ -575,8 +575,6 @@ class GradleWrapper extends CachedArtifact {
}
}
const String _cipdBaseUrl = 'https://chrome-infra-packages.appspot.com/dl';
/// Common functionality for pulling Fuchsia SDKs.
abstract class _FuchsiaSDKArtifacts extends CachedArtifact {
_FuchsiaSDKArtifacts(Cache cache, String platform) :
......@@ -593,7 +591,7 @@ abstract class _FuchsiaSDKArtifacts extends CachedArtifact {
Directory get location => cache.getArtifactDirectory('fuchsia');
Future<void> _doUpdate(ArtifactUpdater artifactUpdater) {
final String url = '$_cipdBaseUrl/$_path/+/$version';
final String url = '${cache.cipdBaseUrl}/$_path/+/$version';
return artifactUpdater.downloadZipArchive('Downloading package fuchsia SDK...',
Uri.parse(url), location);
}
......@@ -627,7 +625,7 @@ class FlutterRunnerSDKArtifacts extends CachedArtifact {
if (!_platform.isLinux && !_platform.isMacOS) {
return;
}
final String url = '$_cipdBaseUrl/flutter/fuchsia/+/git_revision:$version';
final String url = '${cache.cipdBaseUrl}/flutter/fuchsia/+/git_revision:$version';
await artifactUpdater.downloadZipArchive('Downloading package flutter runner...', Uri.parse(url), location);
}
}
......@@ -644,11 +642,13 @@ abstract class VersionedPackageResolver {
/// Resolves the CIPD archive URL for a given package and version.
class CipdArchiveResolver extends VersionedPackageResolver {
const CipdArchiveResolver();
const CipdArchiveResolver(this.cache);
final Cache cache;
@override
String resolveUrl(String packageName, String version) {
return '$_cipdBaseUrl/flutter/$packageName/+/git_revision:$version';
return '${cache.cipdBaseUrl}/flutter/$packageName/+/git_revision:$version';
}
}
......@@ -656,8 +656,9 @@ class CipdArchiveResolver extends VersionedPackageResolver {
class FlutterRunnerDebugSymbols extends CachedArtifact {
FlutterRunnerDebugSymbols(Cache cache, {
required Platform platform,
this.packageResolver = const CipdArchiveResolver(),
VersionedPackageResolver? packageResolver,
}) : _platform = platform,
packageResolver = packageResolver ?? CipdArchiveResolver(cache),
super('flutter_runner_debug_symbols', cache, DevelopmentArtifact.flutterRunner);
final VersionedPackageResolver packageResolver;
......
......@@ -730,14 +730,18 @@ void main() {
testWithoutContext('FlutterWebSdk fetches web artifacts and deletes previous directory contents', () async {
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final File canvasKitVersionFile = fileSystem.currentDirectory
final Directory internalDir = fileSystem.currentDirectory
.childDirectory('cache')
.childDirectory('bin')
.childDirectory('internal')
.childFile('canvaskit.version');
.childDirectory('internal');
final File canvasKitVersionFile = internalDir.childFile('canvaskit.version');
canvasKitVersionFile.createSync(recursive: true);
canvasKitVersionFile.writeAsStringSync('abcdefg');
final File engineVersionFile = internalDir.childFile('engine.version');
engineVersionFile.createSync(recursive: true);
engineVersionFile.writeAsStringSync('hijklmnop');
final Cache cache = Cache.test(processManager: FakeProcessManager.any(), fileSystem: fileSystem);
final Directory webCacheDirectory = cache.getWebSdkDirectory();
final FakeArtifactUpdater artifactUpdater = FakeArtifactUpdater();
......@@ -763,7 +767,7 @@ void main() {
]);
expect(downloads, <String>[
'https://storage.googleapis.com/flutter_infra_release/flutter/null/flutter-web-sdk-linux-x64.zip',
'https://storage.googleapis.com/flutter_infra_release/flutter/hijklmnop/flutter-web-sdk-linux-x64.zip',
'https://chrome-infra-packages.appspot.com/dl/flutter/web/canvaskit_bundle/+/abcdefg',
]);
......@@ -776,6 +780,51 @@ void main() {
expect(webCacheDirectory.childFile('bar'), isNot(exists));
});
testWithoutContext('FlutterWebSdk CanvasKit URL can be overridden via FLUTTER_STORAGE_BASE_URL', () async {
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final Directory internalDir = fileSystem.currentDirectory
.childDirectory('cache')
.childDirectory('bin')
.childDirectory('internal');
final File canvasKitVersionFile = internalDir.childFile('canvaskit.version');
canvasKitVersionFile.createSync(recursive: true);
canvasKitVersionFile.writeAsStringSync('abcdefg');
final File engineVersionFile = internalDir.childFile('engine.version');
engineVersionFile.createSync(recursive: true);
engineVersionFile.writeAsStringSync('hijklmnop');
final Cache cache = Cache.test(
processManager: FakeProcessManager.any(),
fileSystem: fileSystem,
platform: FakePlatform(
environment: <String, String>{
'FLUTTER_STORAGE_BASE_URL': 'https://flutter.storage.com/override'
},
),
);
final Directory webCacheDirectory = cache.getWebSdkDirectory();
final FakeArtifactUpdater artifactUpdater = FakeArtifactUpdater();
final FlutterWebSdk webSdk = FlutterWebSdk(cache, platform: FakePlatform());
final List<String> downloads = <String>[];
final List<String> locations = <String>[];
artifactUpdater.onDownloadZipArchive = (String message, Uri uri, Directory location) {
downloads.add(uri.toString());
locations.add(location.path);
location.createSync(recursive: true);
location.childFile('foo').createSync();
};
webCacheDirectory.childFile('bar').createSync(recursive: true);
await webSdk.updateInner(artifactUpdater, fileSystem, FakeOperatingSystemUtils());
expect(downloads, <String>[
'https://flutter.storage.com/override/flutter_infra_release/flutter/hijklmnop/flutter-web-sdk-linux-x64.zip',
'https://flutter.storage.com/override/flutter_infra_release/cipd/flutter/web/canvaskit_bundle/+/abcdefg'
]);
});
testWithoutContext('FlutterWebSdk uses tryToDelete to handle directory edge cases', () async {
final FileExceptionHandler handler = FileExceptionHandler();
final MemoryFileSystem fileSystem = MemoryFileSystem.test(opHandle: handler.opHandle);
......
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