mirror of
https://github.com/flutter/flutter
synced 2024-10-12 19:23:02 +00:00
Migrate flutter_cache to null safety (#85242)
This commit is contained in:
parent
4bd47ce60c
commit
d145938406
|
@ -2,8 +2,6 @@
|
|||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart = 2.8
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:meta/meta.dart';
|
||||
|
@ -20,17 +18,17 @@ import 'base/process.dart';
|
|||
import 'cache.dart';
|
||||
import 'dart/package_map.dart';
|
||||
import 'dart/pub.dart';
|
||||
import 'globals.dart' as globals;
|
||||
import 'globals_null_migrated.dart' as globals;
|
||||
|
||||
/// An implementation of the [Cache] which provides all of Flutter's default artifacts.
|
||||
class FlutterCache extends Cache {
|
||||
/// [rootOverride] is configurable for testing.
|
||||
/// [artifacts] is configurable for testing.
|
||||
FlutterCache({
|
||||
@required Logger logger,
|
||||
@required FileSystem fileSystem,
|
||||
@required Platform platform,
|
||||
@required OperatingSystemUtils osUtils,
|
||||
required Logger logger,
|
||||
required FileSystem fileSystem,
|
||||
required Platform platform,
|
||||
required OperatingSystemUtils osUtils,
|
||||
}) : super(logger: logger, fileSystem: fileSystem, platform: platform, osUtils: osUtils, artifacts: <ArtifactSet>[]) {
|
||||
registerArtifact(MaterialFonts(this));
|
||||
registerArtifact(GradleWrapper(this));
|
||||
|
@ -55,7 +53,7 @@ class FlutterCache extends Cache {
|
|||
logger: logger,
|
||||
// flutter root and pub must be lazily initialized to avoid accessing
|
||||
// before the version is determined.
|
||||
flutterRoot: () => Cache.flutterRoot,
|
||||
flutterRoot: () => Cache.flutterRoot!,
|
||||
pub: () => pub,
|
||||
));
|
||||
}
|
||||
|
@ -70,9 +68,9 @@ class FlutterCache extends Cache {
|
|||
class PubDependencies extends ArtifactSet {
|
||||
PubDependencies({
|
||||
// Needs to be lazy to avoid reading from the cache before the root is initialized.
|
||||
@required String Function() flutterRoot,
|
||||
@required Logger logger,
|
||||
@required Pub Function() pub,
|
||||
required String Function() flutterRoot,
|
||||
required Logger logger,
|
||||
required Pub Function() pub,
|
||||
}) : _logger = logger,
|
||||
_flutterRoot = flutterRoot,
|
||||
_pub = pub,
|
||||
|
@ -139,8 +137,8 @@ class MaterialFonts extends CachedArtifact {
|
|||
ArtifactUpdater artifactUpdater,
|
||||
FileSystem fileSystem,
|
||||
OperatingSystemUtils operatingSystemUtils,
|
||||
) {
|
||||
final Uri archiveUri = _toStorageUri(version);
|
||||
) async {
|
||||
final Uri archiveUri = _toStorageUri(version!);
|
||||
return artifactUpdater.downloadZipArchive('Downloading Material fonts...', archiveUri, location);
|
||||
}
|
||||
|
||||
|
@ -152,7 +150,7 @@ class MaterialFonts extends CachedArtifact {
|
|||
///
|
||||
/// This SDK references code within the regular Dart sdk to reduce download size.
|
||||
class FlutterWebSdk extends CachedArtifact {
|
||||
FlutterWebSdk(Cache cache, {@required Platform platform})
|
||||
FlutterWebSdk(Cache cache, {required Platform platform})
|
||||
: _platform = platform,
|
||||
super(
|
||||
'flutter_web_sdk',
|
||||
|
@ -166,7 +164,7 @@ class FlutterWebSdk extends CachedArtifact {
|
|||
Directory get location => cache.getWebSdkDirectory();
|
||||
|
||||
@override
|
||||
String get version => cache.getVersionFor('engine');
|
||||
String? get version => cache.getVersionFor('engine');
|
||||
|
||||
@override
|
||||
Future<void> updateInner(
|
||||
|
@ -205,7 +203,7 @@ class FlutterWebSdk extends CachedArtifact {
|
|||
/// A cached artifact containing the dart:ui source code.
|
||||
class FlutterSdk extends EngineCachedArtifact {
|
||||
FlutterSdk(Cache cache, {
|
||||
@required Platform platform,
|
||||
required Platform platform,
|
||||
}) : _platform = platform,
|
||||
super(
|
||||
'flutter_sdk',
|
||||
|
@ -245,7 +243,7 @@ class FlutterSdk extends EngineCachedArtifact {
|
|||
|
||||
class MacOSEngineArtifacts extends EngineCachedArtifact {
|
||||
MacOSEngineArtifacts(Cache cache, {
|
||||
@required Platform platform,
|
||||
required Platform platform,
|
||||
}) : _platform = platform,
|
||||
super(
|
||||
'macos-sdk',
|
||||
|
@ -273,7 +271,7 @@ class MacOSEngineArtifacts extends EngineCachedArtifact {
|
|||
/// Artifacts required for desktop Windows builds.
|
||||
class WindowsEngineArtifacts extends EngineCachedArtifact {
|
||||
WindowsEngineArtifacts(Cache cache, {
|
||||
@required Platform platform,
|
||||
required Platform platform,
|
||||
}) : _platform = platform,
|
||||
super(
|
||||
'windows-sdk',
|
||||
|
@ -300,7 +298,7 @@ class WindowsEngineArtifacts extends EngineCachedArtifact {
|
|||
|
||||
class WindowsUwpEngineArtifacts extends EngineCachedArtifact {
|
||||
WindowsUwpEngineArtifacts(Cache cache, {
|
||||
@required Platform platform,
|
||||
required Platform platform,
|
||||
}) : _platform = platform,
|
||||
super(
|
||||
'windows-uwp-sdk',
|
||||
|
@ -328,7 +326,7 @@ class WindowsUwpEngineArtifacts extends EngineCachedArtifact {
|
|||
/// Artifacts required for desktop Linux builds.
|
||||
class LinuxEngineArtifacts extends EngineCachedArtifact {
|
||||
LinuxEngineArtifacts(Cache cache, {
|
||||
@required Platform platform
|
||||
required Platform platform
|
||||
}) : _platform = platform,
|
||||
super(
|
||||
'linux-sdk',
|
||||
|
@ -361,7 +359,7 @@ class LinuxEngineArtifacts extends EngineCachedArtifact {
|
|||
/// The artifact used to generate snapshots for Android builds.
|
||||
class AndroidGenSnapshotArtifacts extends EngineCachedArtifact {
|
||||
AndroidGenSnapshotArtifacts(Cache cache, {
|
||||
@required Platform platform,
|
||||
required Platform platform,
|
||||
}) : _platform = platform,
|
||||
super(
|
||||
'android-sdk',
|
||||
|
@ -400,7 +398,7 @@ class AndroidGenSnapshotArtifacts extends EngineCachedArtifact {
|
|||
/// This is a no-op if the android SDK is not available.
|
||||
class AndroidMavenArtifacts extends ArtifactSet {
|
||||
AndroidMavenArtifacts(this.cache, {
|
||||
@required Platform platform,
|
||||
required Platform platform,
|
||||
}) : _platform = platform,
|
||||
super(DevelopmentArtifact.androidMaven);
|
||||
|
||||
|
@ -418,7 +416,7 @@ class AndroidMavenArtifacts extends ArtifactSet {
|
|||
return;
|
||||
}
|
||||
final Directory tempDir = cache.getRoot().createTempSync('flutter_gradle_wrapper.');
|
||||
globals.gradleUtils.injectGradleWrapperIfNeeded(tempDir);
|
||||
globals.gradleUtils?.injectGradleWrapperIfNeeded(tempDir);
|
||||
|
||||
final Status status = logger.startProgress('Downloading Android Maven dependencies...');
|
||||
final File gradle = tempDir.childFile(
|
||||
|
@ -426,7 +424,7 @@ class AndroidMavenArtifacts extends ArtifactSet {
|
|||
);
|
||||
try {
|
||||
final String gradleExecutable = gradle.absolute.path;
|
||||
final String flutterSdk = globals.fsUtils.escapePath(Cache.flutterRoot);
|
||||
final String flutterSdk = globals.fsUtils.escapePath(Cache.flutterRoot!);
|
||||
final RunResult processResult = await globals.processUtils.run(
|
||||
<String>[
|
||||
gradleExecutable,
|
||||
|
@ -436,7 +434,7 @@ class AndroidMavenArtifacts extends ArtifactSet {
|
|||
],
|
||||
environment: <String, String>{
|
||||
if (javaPath != null)
|
||||
'JAVA_HOME': javaPath,
|
||||
'JAVA_HOME': javaPath!,
|
||||
},
|
||||
);
|
||||
if (processResult.exitCode != 0) {
|
||||
|
@ -484,7 +482,7 @@ class AndroidInternalBuildArtifacts extends EngineCachedArtifact {
|
|||
|
||||
class IOSEngineArtifacts extends EngineCachedArtifact {
|
||||
IOSEngineArtifacts(Cache cache, {
|
||||
@required Platform platform,
|
||||
required Platform platform,
|
||||
}) : _platform = platform,
|
||||
super(
|
||||
'ios-sdk',
|
||||
|
@ -537,7 +535,7 @@ class GradleWrapper extends CachedArtifact {
|
|||
FileSystem fileSystem,
|
||||
OperatingSystemUtils operatingSystemUtils,
|
||||
) async {
|
||||
final Uri archiveUri = _toStorageUri(version);
|
||||
final Uri archiveUri = _toStorageUri(version!);
|
||||
await artifactUpdater.downloadZippedTarball('Downloading Gradle Wrapper...', archiveUri, location);
|
||||
// Delete property file, allowing templates to provide it.
|
||||
// Remove NOTICE file. Should not be part of the template.
|
||||
|
@ -597,7 +595,7 @@ abstract class _FuchsiaSDKArtifacts extends CachedArtifact {
|
|||
/// The pre-built flutter runner for Fuchsia development.
|
||||
class FlutterRunnerSDKArtifacts extends CachedArtifact {
|
||||
FlutterRunnerSDKArtifacts(Cache cache, {
|
||||
@required Platform platform,
|
||||
required Platform platform,
|
||||
}) : _platform = platform,
|
||||
super(
|
||||
'flutter_runner',
|
||||
|
@ -611,7 +609,7 @@ class FlutterRunnerSDKArtifacts extends CachedArtifact {
|
|||
Directory get location => cache.getArtifactDirectory('flutter_runner');
|
||||
|
||||
@override
|
||||
String get version => cache.getVersionFor('engine');
|
||||
String? get version => cache.getVersionFor('engine');
|
||||
|
||||
@override
|
||||
Future<void> updateInner(
|
||||
|
@ -650,7 +648,7 @@ class CipdArchiveResolver extends VersionedPackageResolver {
|
|||
/// The debug symbols for flutter runner for Fuchsia development.
|
||||
class FlutterRunnerDebugSymbols extends CachedArtifact {
|
||||
FlutterRunnerDebugSymbols(Cache cache, {
|
||||
@required Platform platform,
|
||||
required Platform platform,
|
||||
this.packageResolver = const CipdArchiveResolver(),
|
||||
}) : _platform = platform,
|
||||
super('flutter_runner_debug_symbols', cache, DevelopmentArtifact.flutterRunner);
|
||||
|
@ -662,11 +660,11 @@ class FlutterRunnerDebugSymbols extends CachedArtifact {
|
|||
Directory get location => cache.getArtifactDirectory(name);
|
||||
|
||||
@override
|
||||
String get version => cache.getVersionFor('engine');
|
||||
String? get version => cache.getVersionFor('engine');
|
||||
|
||||
Future<void> _downloadDebugSymbols(String targetArch, ArtifactUpdater artifactUpdater) async {
|
||||
final String packageName = 'fuchsia-debug-symbols-$targetArch';
|
||||
final String url = packageResolver.resolveUrl(packageName, version);
|
||||
final String url = packageResolver.resolveUrl(packageName, version!);
|
||||
await artifactUpdater.downloadZipArchive(
|
||||
'Downloading debug symbols for flutter runner - arch:$targetArch...',
|
||||
Uri.parse(url),
|
||||
|
@ -691,7 +689,7 @@ class FlutterRunnerDebugSymbols extends CachedArtifact {
|
|||
/// The Fuchsia core SDK for Linux.
|
||||
class LinuxFuchsiaSDKArtifacts extends _FuchsiaSDKArtifacts {
|
||||
LinuxFuchsiaSDKArtifacts(Cache cache, {
|
||||
@required Platform platform,
|
||||
required Platform platform,
|
||||
}) : _platform = platform,
|
||||
super(cache, 'linux');
|
||||
|
||||
|
@ -713,7 +711,7 @@ class LinuxFuchsiaSDKArtifacts extends _FuchsiaSDKArtifacts {
|
|||
/// The Fuchsia core SDK for MacOS.
|
||||
class MacOSFuchsiaSDKArtifacts extends _FuchsiaSDKArtifacts {
|
||||
MacOSFuchsiaSDKArtifacts(Cache cache, {
|
||||
@required Platform platform,
|
||||
required Platform platform,
|
||||
}) : _platform = platform,
|
||||
super(cache, 'mac');
|
||||
|
||||
|
@ -735,7 +733,7 @@ class MacOSFuchsiaSDKArtifacts extends _FuchsiaSDKArtifacts {
|
|||
/// Cached artifacts for font subsetting.
|
||||
class FontSubsetArtifacts extends EngineCachedArtifact {
|
||||
FontSubsetArtifacts(Cache cache, {
|
||||
@required Platform platform,
|
||||
required Platform platform,
|
||||
}) : _platform = platform,
|
||||
super(artifactName, cache, DevelopmentArtifact.universal);
|
||||
|
||||
|
@ -755,7 +753,7 @@ class FontSubsetArtifacts extends EngineCachedArtifact {
|
|||
if (cache.includeAllPlatforms) {
|
||||
return artifacts.values.toList();
|
||||
} else {
|
||||
final List<String> binaryDirs = artifacts[_platform.operatingSystem];
|
||||
final List<String>? binaryDirs = artifacts[_platform.operatingSystem];
|
||||
if (binaryDirs == null) {
|
||||
throwToolExit('Unsupported operating system: ${_platform.operatingSystem}');
|
||||
}
|
||||
|
@ -773,7 +771,7 @@ class FontSubsetArtifacts extends EngineCachedArtifact {
|
|||
/// Cached iOS/USB binary artifacts.
|
||||
class IosUsbArtifacts extends CachedArtifact {
|
||||
IosUsbArtifacts(String name, Cache cache, {
|
||||
@required Platform platform,
|
||||
required Platform platform,
|
||||
}) : _platform = platform,
|
||||
super(
|
||||
name,
|
||||
|
@ -814,7 +812,7 @@ class IosUsbArtifacts extends CachedArtifact {
|
|||
|
||||
@override
|
||||
bool isUpToDateInner(FileSystem fileSystem) {
|
||||
final List<String> executables =_kExecutables[name];
|
||||
final List<String>? executables =_kExecutables[name];
|
||||
if (executables == null) {
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -11,15 +11,12 @@ import 'fuchsia/fuchsia_sdk.dart';
|
|||
import 'ios/simulators.dart';
|
||||
import 'macos/xcdevice.dart';
|
||||
import 'reporting/crash_reporting.dart';
|
||||
import 'runner/local_engine.dart';
|
||||
|
||||
export 'globals_null_migrated.dart';
|
||||
|
||||
CrashReporter get crashReporter => context.get<CrashReporter>();
|
||||
Doctor get doctor => context.get<Doctor>();
|
||||
DeviceManager get deviceManager => context.get<DeviceManager>();
|
||||
|
||||
LocalEngineLocator get localEngineLocator => context.get<LocalEngineLocator>();
|
||||
FuchsiaArtifacts get fuchsiaArtifacts => context.get<FuchsiaArtifacts>();
|
||||
IOSSimulatorUtils get iosSimulatorUtils => context.get<IOSSimulatorUtils>();
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ import 'macos/xcode.dart';
|
|||
import 'persistent_tool_state.dart';
|
||||
import 'project.dart';
|
||||
import 'reporting/reporting.dart';
|
||||
import 'runner/local_engine.dart';
|
||||
import 'version.dart';
|
||||
|
||||
/// The flutter GitHub repository.
|
||||
|
@ -56,6 +57,7 @@ Usage get flutterUsage => context.get<Usage>()!;
|
|||
XcodeProjectInterpreter? get xcodeProjectInterpreter => context.get<XcodeProjectInterpreter>();
|
||||
Xcode? get xcode => context.get<Xcode>();
|
||||
IOSWorkflow? get iosWorkflow => context.get<IOSWorkflow>();
|
||||
LocalEngineLocator? get localEngineLocator => context.get<LocalEngineLocator>();
|
||||
|
||||
PersistentToolState? get persistentToolState => PersistentToolState.instance;
|
||||
|
||||
|
|
|
@ -159,7 +159,11 @@ void main() {
|
|||
|
||||
testWithoutContext('Gradle wrapper will delete .properties/NOTICES if they exist', () async {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
final Cache cache = Cache.test(fileSystem: fileSystem, processManager: FakeProcessManager.any());
|
||||
final Directory artifactDir = fileSystem.systemTempDirectory.createTempSync('flutter_cache_test_artifact.');
|
||||
final FakeSecondaryCache cache = FakeSecondaryCache()
|
||||
..artifactDirectory = artifactDir
|
||||
..version = '123456';
|
||||
|
||||
final OperatingSystemUtils operatingSystemUtils = OperatingSystemUtils(
|
||||
processManager: FakeProcessManager.any(),
|
||||
platform: FakePlatform(),
|
||||
|
@ -167,10 +171,9 @@ void main() {
|
|||
fileSystem: fileSystem,
|
||||
);
|
||||
final GradleWrapper gradleWrapper = GradleWrapper(cache);
|
||||
final Directory directory = cache.getCacheDir(fileSystem.path.join('artifacts', 'gradle_wrapper'));
|
||||
final File propertiesFile = fileSystem.file(fileSystem.path.join(directory.path, 'gradle', 'wrapper', 'gradle-wrapper.properties'))
|
||||
final File propertiesFile = fileSystem.file(fileSystem.path.join(artifactDir.path, 'gradle', 'wrapper', 'gradle-wrapper.properties'))
|
||||
..createSync(recursive: true);
|
||||
final File noticeFile = fileSystem.file(fileSystem.path.join(directory.path, 'NOTICE'))
|
||||
final File noticeFile = fileSystem.file(fileSystem.path.join(artifactDir.path, 'NOTICE'))
|
||||
..createSync(recursive: true);
|
||||
|
||||
await gradleWrapper.updateInner(FakeArtifactUpdater(), fileSystem, operatingSystemUtils);
|
||||
|
@ -429,10 +432,9 @@ void main() {
|
|||
|
||||
testWithoutContext('FlutterRunnerDebugSymbols downloads Flutter runner debug symbols', () async {
|
||||
final FileSystem fileSystem = MemoryFileSystem.test();
|
||||
final Cache cache = Cache.test(
|
||||
fileSystem: fileSystem,
|
||||
processManager: FakeProcessManager.any(),
|
||||
);
|
||||
final Cache cache = FakeSecondaryCache()
|
||||
..version = '123456';
|
||||
|
||||
final FakeVersionedPackageResolver packageResolver = FakeVersionedPackageResolver();
|
||||
final FlutterRunnerDebugSymbols flutterRunnerDebugSymbols = FlutterRunnerDebugSymbols(
|
||||
cache,
|
||||
|
@ -443,8 +445,8 @@ void main() {
|
|||
await flutterRunnerDebugSymbols.updateInner(FakeArtifactUpdater(), fileSystem, FakeOperatingSystemUtils());
|
||||
|
||||
expect(packageResolver.resolved, <List<String>>[
|
||||
<String>['fuchsia-debug-symbols-x64', null],
|
||||
<String>['fuchsia-debug-symbols-arm64', null],
|
||||
<String>['fuchsia-debug-symbols-x64', '123456'],
|
||||
<String>['fuchsia-debug-symbols-arm64', '123456'],
|
||||
]);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue