Unverified Commit b891adb4 authored by Jonah Williams's avatar Jonah Williams Committed by GitHub

[flutter_tools] migrate artifacts to null safety (#83073)

parent 31e75545
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
...@@ -114,7 +112,31 @@ String _enginePlatformDirectoryName(TargetPlatform platform) { ...@@ -114,7 +112,31 @@ String _enginePlatformDirectoryName(TargetPlatform platform) {
return getNameForTargetPlatform(platform); return getNameForTargetPlatform(platform);
} }
bool _isWindows(TargetPlatform platform) { // Remove android target platform type.
TargetPlatform? _mapTargetPlatform(TargetPlatform? targetPlatform) {
switch (targetPlatform) {
case TargetPlatform.android:
return TargetPlatform.android_arm64;
case TargetPlatform.ios:
case TargetPlatform.darwin:
case TargetPlatform.linux_x64:
case TargetPlatform.linux_arm64:
case TargetPlatform.windows_x64:
case TargetPlatform.windows_uwp_x64:
case TargetPlatform.fuchsia_arm64:
case TargetPlatform.fuchsia_x64:
case TargetPlatform.tester:
case TargetPlatform.web_javascript:
case TargetPlatform.android_arm:
case TargetPlatform.android_arm64:
case TargetPlatform.android_x64:
case TargetPlatform.android_x86:
case null:
return targetPlatform;
}
}
bool _isWindows(TargetPlatform? platform) {
switch (platform) { switch (platform) {
case TargetPlatform.windows_x64: case TargetPlatform.windows_x64:
case TargetPlatform.windows_uwp_x64: case TargetPlatform.windows_uwp_x64:
...@@ -132,12 +154,12 @@ bool _isWindows(TargetPlatform platform) { ...@@ -132,12 +154,12 @@ bool _isWindows(TargetPlatform platform) {
case TargetPlatform.linux_x64: case TargetPlatform.linux_x64:
case TargetPlatform.tester: case TargetPlatform.tester:
case TargetPlatform.web_javascript: case TargetPlatform.web_javascript:
case null:
return false; return false;
} }
return false;
} }
String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMode mode ]) { String? _artifactToFileName(Artifact artifact, [ TargetPlatform? platform, BuildMode? mode ]) {
final String exe = _isWindows(platform) ? '.exe' : ''; final String exe = _isWindows(platform) ? '.exe' : '';
switch (artifact) { switch (artifact) {
case Artifact.genSnapshot: case Artifact.genSnapshot:
...@@ -181,7 +203,7 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo ...@@ -181,7 +203,7 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo
case Artifact.fuchsiaKernelCompiler: case Artifact.fuchsiaKernelCompiler:
return 'kernel_compiler.snapshot'; return 'kernel_compiler.snapshot';
case Artifact.fuchsiaFlutterRunner: case Artifact.fuchsiaFlutterRunner:
final String jitOrAot = mode.isJit ? '_jit' : '_aot'; final String jitOrAot = mode!.isJit ? '_jit' : '_aot';
final String productOrNo = mode.isRelease ? '_product' : ''; final String productOrNo = mode.isRelease ? '_product' : '';
return 'flutter$jitOrAot${productOrNo}_runner-0.far'; return 'flutter$jitOrAot${productOrNo}_runner-0.far';
case Artifact.fontSubset: case Artifact.fontSubset:
...@@ -191,8 +213,6 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo ...@@ -191,8 +213,6 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo
case Artifact.uwptool: case Artifact.uwptool:
return 'uwptool$exe'; return 'uwptool$exe';
} }
assert(false, 'Invalid artifact $artifact.');
return null;
} }
String _hostArtifactToFileName(HostArtifact artifact, bool windows) { String _hostArtifactToFileName(HostArtifact artifact, bool windows) {
...@@ -246,14 +266,12 @@ String _hostArtifactToFileName(HostArtifact artifact, bool windows) { ...@@ -246,14 +266,12 @@ String _hostArtifactToFileName(HostArtifact artifact, bool windows) {
} }
return 'pub'; return 'pub';
} }
assert(false, 'Invalid artifact $artifact.');
return null;
} }
class EngineBuildPaths { class EngineBuildPaths {
const EngineBuildPaths({ const EngineBuildPaths({
@required this.targetEngine, required this.targetEngine,
@required this.hostEngine, required this.hostEngine,
}) : assert(targetEngine != null), }) : assert(targetEngine != null),
assert(hostEngine != null); assert(hostEngine != null);
...@@ -270,7 +288,7 @@ abstract class Artifacts { ...@@ -270,7 +288,7 @@ abstract class Artifacts {
/// ///
/// Creates a [LocalEngineArtifacts] if `localEngine` is non-null /// Creates a [LocalEngineArtifacts] if `localEngine` is non-null
@visibleForTesting @visibleForTesting
factory Artifacts.test({String localEngine, FileSystem fileSystem}) { factory Artifacts.test({String? localEngine, FileSystem? fileSystem}) {
fileSystem ??= MemoryFileSystem.test(); fileSystem ??= MemoryFileSystem.test();
if (localEngine != null) { if (localEngine != null) {
return _TestLocalEngine(localEngine, fileSystem); return _TestLocalEngine(localEngine, fileSystem);
...@@ -293,9 +311,9 @@ abstract class Artifacts { ...@@ -293,9 +311,9 @@ abstract class Artifacts {
/// Returns the requested [artifact] for the [platform], [mode], and [environmentType] combination. /// Returns the requested [artifact] for the [platform], [mode], and [environmentType] combination.
String getArtifactPath( String getArtifactPath(
Artifact artifact, { Artifact artifact, {
TargetPlatform platform, TargetPlatform? platform,
BuildMode mode, BuildMode? mode,
EnvironmentType environmentType, EnvironmentType? environmentType,
}); });
/// Retrieve a host specific artifact that does not depend on the /// Retrieve a host specific artifact that does not depend on the
...@@ -306,7 +324,7 @@ abstract class Artifacts { ...@@ -306,7 +324,7 @@ abstract class Artifacts {
// Returns which set of engine artifacts is currently used for the [platform] // Returns which set of engine artifacts is currently used for the [platform]
// and [mode] combination. // and [mode] combination.
String getEngineType(TargetPlatform platform, [ BuildMode mode ]); String getEngineType(TargetPlatform platform, [ BuildMode? mode ]);
/// Whether these artifacts correspond to a non-versioned local engine. /// Whether these artifacts correspond to a non-versioned local engine.
bool get isLocalEngine; bool get isLocalEngine;
...@@ -315,10 +333,10 @@ abstract class Artifacts { ...@@ -315,10 +333,10 @@ abstract class Artifacts {
/// Manages the engine artifacts downloaded to the local cache. /// Manages the engine artifacts downloaded to the local cache.
class CachedArtifacts implements Artifacts { class CachedArtifacts implements Artifacts {
CachedArtifacts({ CachedArtifacts({
@required FileSystem fileSystem, required FileSystem fileSystem,
@required Platform platform, required Platform platform,
@required Cache cache, required Cache cache,
@required OperatingSystemUtils operatingSystemUtils, required OperatingSystemUtils operatingSystemUtils,
}) : _fileSystem = fileSystem, }) : _fileSystem = fileSystem,
_platform = platform, _platform = platform,
_cache = cache, _cache = cache,
...@@ -380,7 +398,6 @@ class CachedArtifacts implements Artifacts { ...@@ -380,7 +398,6 @@ class CachedArtifacts implements Artifacts {
case HostArtifact.idevicescreenshot: case HostArtifact.idevicescreenshot:
final String artifactFileName = _hostArtifactToFileName(artifact, _platform.isWindows); final String artifactFileName = _hostArtifactToFileName(artifact, _platform.isWindows);
return _cache.getArtifactDirectory('libimobiledevice').childFile(artifactFileName); return _cache.getArtifactDirectory('libimobiledevice').childFile(artifactFileName);
break;
case HostArtifact.skyEnginePath: case HostArtifact.skyEnginePath:
final Directory dartPackageDirectory = _cache.getCacheDir('pkg'); final Directory dartPackageDirectory = _cache.getCacheDir('pkg');
final String path = _fileSystem.path.join(dartPackageDirectory.path, _hostArtifactToFileName(artifact, _platform.isWindows)); final String path = _fileSystem.path.join(dartPackageDirectory.path, _hostArtifactToFileName(artifact, _platform.isWindows));
...@@ -400,25 +417,24 @@ class CachedArtifacts implements Artifacts { ...@@ -400,25 +417,24 @@ class CachedArtifacts implements Artifacts {
final String artifactFileName = _hostArtifactToFileName(artifact, _platform.isWindows); final String artifactFileName = _hostArtifactToFileName(artifact, _platform.isWindows);
return _cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName); return _cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName);
} }
assert(false);
return null;
} }
@override @override
String getArtifactPath( String getArtifactPath(
Artifact artifact, { Artifact artifact, {
TargetPlatform platform, TargetPlatform? platform,
BuildMode mode, BuildMode? mode,
EnvironmentType environmentType, EnvironmentType? environmentType,
}) { }) {
platform = _mapTargetPlatform(platform);
switch (platform) { switch (platform) {
case TargetPlatform.android_arm: case TargetPlatform.android_arm:
case TargetPlatform.android_arm64: case TargetPlatform.android_arm64:
case TargetPlatform.android_x64: case TargetPlatform.android_x64:
case TargetPlatform.android_x86: case TargetPlatform.android_x86:
return _getAndroidArtifactPath(artifact, platform, mode); return _getAndroidArtifactPath(artifact, platform!, mode!);
case TargetPlatform.ios: case TargetPlatform.ios:
return _getIosArtifactPath(artifact, platform, mode, environmentType); return _getIosArtifactPath(artifact, platform!, mode, environmentType);
case TargetPlatform.darwin: case TargetPlatform.darwin:
case TargetPlatform.linux_x64: case TargetPlatform.linux_x64:
case TargetPlatform.linux_arm64: case TargetPlatform.linux_arm64:
...@@ -427,7 +443,7 @@ class CachedArtifacts implements Artifacts { ...@@ -427,7 +443,7 @@ class CachedArtifacts implements Artifacts {
return _getDesktopArtifactPath(artifact, platform, mode); return _getDesktopArtifactPath(artifact, platform, mode);
case TargetPlatform.fuchsia_arm64: case TargetPlatform.fuchsia_arm64:
case TargetPlatform.fuchsia_x64: case TargetPlatform.fuchsia_x64:
return _getFuchsiaArtifactPath(artifact, platform, mode); return _getFuchsiaArtifactPath(artifact, platform!, mode!);
case TargetPlatform.tester: case TargetPlatform.tester:
case TargetPlatform.web_javascript: case TargetPlatform.web_javascript:
default: // could be null, but that can't be specified as a case. default: // could be null, but that can't be specified as a case.
...@@ -436,22 +452,22 @@ class CachedArtifacts implements Artifacts { ...@@ -436,22 +452,22 @@ class CachedArtifacts implements Artifacts {
} }
@override @override
String getEngineType(TargetPlatform platform, [ BuildMode mode ]) { String getEngineType(TargetPlatform platform, [ BuildMode? mode ]) {
return _fileSystem.path.basename(_getEngineArtifactsPath(platform, mode)); return _fileSystem.path.basename(_getEngineArtifactsPath(platform, mode)!);
} }
String _getDesktopArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) { String _getDesktopArtifactPath(Artifact artifact, TargetPlatform? platform, BuildMode? mode) {
// When platform is null, a generic host platform artifact is being requested // When platform is null, a generic host platform artifact is being requested
// and not the gen_snapshot for darwin as a target platform. // and not the gen_snapshot for darwin as a target platform.
if (platform != null && artifact == Artifact.genSnapshot) { if (platform != null && artifact == Artifact.genSnapshot) {
final String engineDir = _getEngineArtifactsPath(platform, mode); final String engineDir = _getEngineArtifactsPath(platform, mode)!;
return _fileSystem.path.join(engineDir, _artifactToFileName(artifact)); return _fileSystem.path.join(engineDir, _artifactToFileName(artifact));
} }
return _getHostArtifactPath(artifact, platform ?? _currentHostPlatform(_platform, _operatingSystemUtils), mode); return _getHostArtifactPath(artifact, platform ?? _currentHostPlatform(_platform, _operatingSystemUtils), mode);
} }
String _getAndroidArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) { String _getAndroidArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
final String engineDir = _getEngineArtifactsPath(platform, mode); final String engineDir = _getEngineArtifactsPath(platform, mode)!;
switch (artifact) { switch (artifact) {
case Artifact.frontendServerSnapshotForEngineDartSdk: case Artifact.frontendServerSnapshotForEngineDartSdk:
assert(mode != BuildMode.debug, 'Artifact $artifact only available in non-debug mode.'); assert(mode != BuildMode.debug, 'Artifact $artifact only available in non-debug mode.');
...@@ -465,17 +481,16 @@ class CachedArtifacts implements Artifacts { ...@@ -465,17 +481,16 @@ class CachedArtifacts implements Artifacts {
} }
} }
String _getIosArtifactPath(Artifact artifact, TargetPlatform platform, String _getIosArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode? mode, EnvironmentType? environmentType) {
BuildMode mode, EnvironmentType environmentType) {
switch (artifact) { switch (artifact) {
case Artifact.genSnapshot: case Artifact.genSnapshot:
case Artifact.flutterXcframework: case Artifact.flutterXcframework:
case Artifact.frontendServerSnapshotForEngineDartSdk: case Artifact.frontendServerSnapshotForEngineDartSdk:
final String artifactFileName = _artifactToFileName(artifact); final String artifactFileName = _artifactToFileName(artifact)!;
final String engineDir = _getEngineArtifactsPath(platform, mode); final String engineDir = _getEngineArtifactsPath(platform, mode)!;
return _fileSystem.path.join(engineDir, artifactFileName); return _fileSystem.path.join(engineDir, artifactFileName);
case Artifact.flutterFramework: case Artifact.flutterFramework:
final String engineDir = _getEngineArtifactsPath(platform, mode); final String engineDir = _getEngineArtifactsPath(platform, mode)!;
return _getIosEngineArtifactPath(engineDir, environmentType, _fileSystem); return _getIosEngineArtifactPath(engineDir, environmentType, _fileSystem);
default: default:
return _getHostArtifactPath(artifact, platform, mode); return _getHostArtifactPath(artifact, platform, mode);
...@@ -498,20 +513,20 @@ class CachedArtifacts implements Artifacts { ...@@ -498,20 +513,20 @@ class CachedArtifacts implements Artifacts {
const String artifactFileName = 'flutter_runner_patched_sdk'; const String artifactFileName = 'flutter_runner_patched_sdk';
return _fileSystem.path.join(root, runtime, artifactFileName); return _fileSystem.path.join(root, runtime, artifactFileName);
case Artifact.platformKernelDill: case Artifact.platformKernelDill:
final String artifactFileName = _artifactToFileName(artifact, platform, mode); final String artifactFileName = _artifactToFileName(artifact, platform, mode)!;
return _fileSystem.path.join(root, runtime, 'flutter_runner_patched_sdk', artifactFileName); return _fileSystem.path.join(root, runtime, 'flutter_runner_patched_sdk', artifactFileName);
case Artifact.fuchsiaKernelCompiler: case Artifact.fuchsiaKernelCompiler:
final String artifactFileName = _artifactToFileName(artifact, platform, mode); final String artifactFileName = _artifactToFileName(artifact, platform, mode)!;
return _fileSystem.path.join(root, runtime, 'dart_binaries', artifactFileName); return _fileSystem.path.join(root, runtime, 'dart_binaries', artifactFileName);
case Artifact.fuchsiaFlutterRunner: case Artifact.fuchsiaFlutterRunner:
final String artifactFileName = _artifactToFileName(artifact, platform, mode); final String artifactFileName = _artifactToFileName(artifact, platform, mode)!;
return _fileSystem.path.join(root, runtime, artifactFileName); return _fileSystem.path.join(root, runtime, artifactFileName);
default: default:
return _getHostArtifactPath(artifact, platform, mode); return _getHostArtifactPath(artifact, platform, mode);
} }
} }
String _getFlutterPatchedSdkPath(BuildMode mode) { String _getFlutterPatchedSdkPath(BuildMode? mode) {
final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path; final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
return _fileSystem.path.join(engineArtifactsPath, 'common', return _fileSystem.path.join(engineArtifactsPath, 'common',
mode == BuildMode.release ? 'flutter_patched_sdk_product' : 'flutter_patched_sdk'); mode == BuildMode.release ? 'flutter_patched_sdk_product' : 'flutter_patched_sdk');
...@@ -521,7 +536,7 @@ class CachedArtifacts implements Artifacts { ...@@ -521,7 +536,7 @@ class CachedArtifacts implements Artifacts {
return _cache.getWebSdkDirectory().path; return _cache.getWebSdkDirectory().path;
} }
String _getHostArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) { String _getHostArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode? mode) {
assert(platform != null); assert(platform != null);
switch (artifact) { switch (artifact) {
case Artifact.genSnapshot: case Artifact.genSnapshot:
...@@ -552,13 +567,13 @@ class CachedArtifacts implements Artifacts { ...@@ -552,13 +567,13 @@ class CachedArtifacts implements Artifacts {
// https://github.com/flutter/flutter/issues/38935 // https://github.com/flutter/flutter/issues/38935
String platformDirName = _enginePlatformDirectoryName(platform); String platformDirName = _enginePlatformDirectoryName(platform);
if (mode == BuildMode.profile || mode == BuildMode.release) { if (mode == BuildMode.profile || mode == BuildMode.release) {
platformDirName = '$platformDirName-${getNameForBuildMode(mode)}'; platformDirName = '$platformDirName-${getNameForBuildMode(mode!)}';
} }
final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path; final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
return _fileSystem.path.join(engineArtifactsPath, platformDirName, _artifactToFileName(artifact, platform, mode)); return _fileSystem.path.join(engineArtifactsPath, platformDirName, _artifactToFileName(artifact, platform, mode));
case Artifact.windowsUwpDesktopPath: case Artifact.windowsUwpDesktopPath:
final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path; final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
return _fileSystem.path.join(engineArtifactsPath, 'windows-uwp-x64-${getNameForBuildMode(mode)}', _artifactToFileName(artifact, platform, mode)); return _fileSystem.path.join(engineArtifactsPath, 'windows-uwp-x64-${getNameForBuildMode(mode!)}', _artifactToFileName(artifact, platform, mode));
case Artifact.windowsCppClientWrapper: case Artifact.windowsCppClientWrapper:
final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path; final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
return _fileSystem.path.join(engineArtifactsPath, 'windows-x64', _artifactToFileName(artifact, platform, mode)); return _fileSystem.path.join(engineArtifactsPath, 'windows-x64', _artifactToFileName(artifact, platform, mode));
...@@ -569,20 +584,19 @@ class CachedArtifacts implements Artifacts { ...@@ -569,20 +584,19 @@ class CachedArtifacts implements Artifacts {
case Artifact.constFinder: case Artifact.constFinder:
return _cache.getArtifactDirectory('engine') return _cache.getArtifactDirectory('engine')
.childDirectory(_enginePlatformDirectoryName(platform)) .childDirectory(_enginePlatformDirectoryName(platform))
.childFile(_artifactToFileName(artifact, platform, mode)) .childFile(_artifactToFileName(artifact, platform, mode)!)
.path; .path;
case Artifact.uwptool: case Artifact.uwptool:
return _cache.getArtifactDirectory('engine') return _cache.getArtifactDirectory('engine')
.childDirectory('windows-uwp-x64-${getNameForBuildMode(mode ?? BuildMode.debug)}') .childDirectory('windows-uwp-x64-${getNameForBuildMode(mode ?? BuildMode.debug)}')
.childFile(_artifactToFileName(artifact, platform, mode)) .childFile(_artifactToFileName(artifact, platform, mode)!)
.path; .path;
default: default:
assert(false, 'Artifact $artifact not available for platform $platform.'); throw StateError('Artifact $artifact not available for platform $platform.');
return null;
} }
} }
String _getEngineArtifactsPath(TargetPlatform platform, [ BuildMode mode ]) { String? _getEngineArtifactsPath(TargetPlatform platform, [ BuildMode? mode ]) {
final String engineDir = _cache.getArtifactDirectory('engine').path; final String engineDir = _cache.getArtifactDirectory('engine').path;
final String platformName = _enginePlatformDirectoryName(platform); final String platformName = _enginePlatformDirectoryName(platform);
switch (platform) { switch (platform) {
...@@ -611,14 +625,12 @@ class CachedArtifacts implements Artifacts { ...@@ -611,14 +625,12 @@ class CachedArtifacts implements Artifacts {
case TargetPlatform.android_x86: case TargetPlatform.android_x86:
case TargetPlatform.windows_uwp_x64: case TargetPlatform.windows_uwp_x64:
assert(mode != null, 'Need to specify a build mode for platform $platform.'); assert(mode != null, 'Need to specify a build mode for platform $platform.');
final String suffix = mode != BuildMode.debug ? '-${snakeCase(getModeName(mode), '-')}' : ''; final String suffix = mode != BuildMode.debug ? '-${snakeCase(getModeName(mode!), '-')}' : '';
return _fileSystem.path.join(engineDir, platformName + suffix); return _fileSystem.path.join(engineDir, platformName + suffix);
case TargetPlatform.android: case TargetPlatform.android:
assert(false, 'cannot use TargetPlatform.android to look up artifacts'); assert(false, 'cannot use TargetPlatform.android to look up artifacts');
return null; return null;
} }
assert(false, 'Invalid platform $platform.');
return null;
} }
@override @override
...@@ -640,15 +652,15 @@ TargetPlatform _currentHostPlatform(Platform platform, OperatingSystemUtils oper ...@@ -640,15 +652,15 @@ TargetPlatform _currentHostPlatform(Platform platform, OperatingSystemUtils oper
} }
String _getIosEngineArtifactPath(String engineDirectory, String _getIosEngineArtifactPath(String engineDirectory,
EnvironmentType environmentType, FileSystem fileSystem) { EnvironmentType? environmentType, FileSystem fileSystem) {
final Directory xcframeworkDirectory = fileSystem final Directory xcframeworkDirectory = fileSystem
.directory(engineDirectory) .directory(engineDirectory)
.childDirectory(_artifactToFileName(Artifact.flutterXcframework)); .childDirectory(_artifactToFileName(Artifact.flutterXcframework)!);
if (!xcframeworkDirectory.existsSync()) { if (!xcframeworkDirectory.existsSync()) {
throwToolExit('No xcframework found at ${xcframeworkDirectory.path}. Try running "flutter precache --ios".'); throwToolExit('No xcframework found at ${xcframeworkDirectory.path}. Try running "flutter precache --ios".');
} }
Directory flutterFrameworkSource; Directory? flutterFrameworkSource;
for (final Directory platformDirectory for (final Directory platformDirectory
in xcframeworkDirectory.listSync().whereType<Directory>()) { in xcframeworkDirectory.listSync().whereType<Directory>()) {
if (!platformDirectory.basename.startsWith('ios-')) { if (!platformDirectory.basename.startsWith('ios-')) {
...@@ -667,17 +679,17 @@ String _getIosEngineArtifactPath(String engineDirectory, ...@@ -667,17 +679,17 @@ String _getIosEngineArtifactPath(String engineDirectory,
} }
return flutterFrameworkSource return flutterFrameworkSource
.childDirectory(_artifactToFileName(Artifact.flutterFramework)) .childDirectory(_artifactToFileName(Artifact.flutterFramework)!)
.path; .path;
} }
abstract class LocalEngineArtifacts implements Artifacts { abstract class LocalEngineArtifacts implements Artifacts {
factory LocalEngineArtifacts(String engineOutPath, String hostEngineOutPath, { factory LocalEngineArtifacts(String engineOutPath, String hostEngineOutPath, {
@required FileSystem fileSystem, required FileSystem fileSystem,
@required Cache cache, required Cache cache,
@required ProcessManager processManager, required ProcessManager processManager,
@required Platform platform, required Platform platform,
@required OperatingSystemUtils operatingSystemUtils, required OperatingSystemUtils operatingSystemUtils,
}) = CachedLocalEngineArtifacts; }) = CachedLocalEngineArtifacts;
String get engineOutPath; String get engineOutPath;
...@@ -688,11 +700,11 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts { ...@@ -688,11 +700,11 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts {
CachedLocalEngineArtifacts( CachedLocalEngineArtifacts(
this.engineOutPath, this.engineOutPath,
this._hostEngineOutPath, { this._hostEngineOutPath, {
@required FileSystem fileSystem, required FileSystem fileSystem,
@required Cache cache, required Cache cache,
@required ProcessManager processManager, required ProcessManager processManager,
@required Platform platform, required Platform platform,
@required OperatingSystemUtils operatingSystemUtils, required OperatingSystemUtils operatingSystemUtils,
}) : _fileSystem = fileSystem, }) : _fileSystem = fileSystem,
_cache = cache, _cache = cache,
_processManager = processManager, _processManager = processManager,
...@@ -770,7 +782,6 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts { ...@@ -770,7 +782,6 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts {
case HostArtifact.idevicescreenshot: case HostArtifact.idevicescreenshot:
final String artifactFileName = _hostArtifactToFileName(artifact, _platform.isWindows); final String artifactFileName = _hostArtifactToFileName(artifact, _platform.isWindows);
return _cache.getArtifactDirectory('libimobiledevice').childFile(artifactFileName); return _cache.getArtifactDirectory('libimobiledevice').childFile(artifactFileName);
break;
case HostArtifact.skyEnginePath: case HostArtifact.skyEnginePath:
final Directory dartPackageDirectory = _cache.getCacheDir('pkg'); final Directory dartPackageDirectory = _cache.getCacheDir('pkg');
final String path = _fileSystem.path.join(dartPackageDirectory.path, _hostArtifactToFileName(artifact, _platform.isWindows)); final String path = _fileSystem.path.join(dartPackageDirectory.path, _hostArtifactToFileName(artifact, _platform.isWindows));
...@@ -785,25 +796,24 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts { ...@@ -785,25 +796,24 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts {
final String artifactFileName = _hostArtifactToFileName(artifact, _platform.isWindows); final String artifactFileName = _hostArtifactToFileName(artifact, _platform.isWindows);
return _cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName); return _cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName);
} }
assert(false);
return null;
} }
@override @override
String getArtifactPath( String getArtifactPath(
Artifact artifact, { Artifact artifact, {
TargetPlatform platform, TargetPlatform? platform,
BuildMode mode, BuildMode? mode,
EnvironmentType environmentType, EnvironmentType? environmentType,
}) { }) {
platform ??= _currentHostPlatform(_platform, _operatingSystemUtils); platform ??= _currentHostPlatform(_platform, _operatingSystemUtils);
platform = _mapTargetPlatform(platform);
final bool isDirectoryArtifact = artifact == Artifact.flutterPatchedSdkPath; final bool isDirectoryArtifact = artifact == Artifact.flutterPatchedSdkPath;
final String artifactFileName = isDirectoryArtifact ? null : _artifactToFileName(artifact, platform, mode); final String? artifactFileName = isDirectoryArtifact ? null : _artifactToFileName(artifact, platform, mode);
switch (artifact) { switch (artifact) {
case Artifact.genSnapshot: case Artifact.genSnapshot:
return _genSnapshotPath(); return _genSnapshotPath();
case Artifact.flutterTester: case Artifact.flutterTester:
return _flutterTesterPath(platform); return _flutterTesterPath(platform!);
case Artifact.isolateSnapshotData: case Artifact.isolateSnapshotData:
case Artifact.vmSnapshotData: case Artifact.vmSnapshotData:
return _fileSystem.path.join(engineOutPath, 'gen', 'flutter', 'lib', 'snapshot', artifactFileName); return _fileSystem.path.join(engineOutPath, 'gen', 'flutter', 'lib', 'snapshot', artifactFileName);
...@@ -830,18 +840,17 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts { ...@@ -830,18 +840,17 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts {
return _fileSystem.path.join(engineOutPath, 'flutter_runner_patched_sdk'); return _fileSystem.path.join(engineOutPath, 'flutter_runner_patched_sdk');
} }
return _getFlutterPatchedSdkPath(BuildMode.debug); return _getFlutterPatchedSdkPath(BuildMode.debug);
return _fileSystem.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', 'snapshots', artifactFileName);
case Artifact.skyEnginePath: case Artifact.skyEnginePath:
return _fileSystem.path.join(_hostEngineOutPath, 'gen', 'dart-pkg', artifactFileName); return _fileSystem.path.join(_hostEngineOutPath, 'gen', 'dart-pkg', artifactFileName);
case Artifact.flutterMacOSPodspec: case Artifact.flutterMacOSPodspec:
return _fileSystem.path.join(_hostEngineOutPath, _artifactToFileName(artifact)); return _fileSystem.path.join(_hostEngineOutPath, _artifactToFileName(artifact));
case Artifact.fuchsiaKernelCompiler: case Artifact.fuchsiaKernelCompiler:
final String hostPlatform = getNameForHostPlatform(getCurrentHostPlatform()); final String hostPlatform = getNameForHostPlatform(getCurrentHostPlatform());
final String modeName = mode.isRelease ? 'release' : mode.toString(); final String modeName = mode!.isRelease ? 'release' : mode.toString();
final String dartBinaries = 'dart_binaries-$modeName-$hostPlatform'; final String dartBinaries = 'dart_binaries-$modeName-$hostPlatform';
return _fileSystem.path.join(engineOutPath, 'host_bundle', dartBinaries, 'kernel_compiler.dart.snapshot'); return _fileSystem.path.join(engineOutPath, 'host_bundle', dartBinaries, 'kernel_compiler.dart.snapshot');
case Artifact.fuchsiaFlutterRunner: case Artifact.fuchsiaFlutterRunner:
final String jitOrAot = mode.isJit ? '_jit' : '_aot'; final String jitOrAot = mode!.isJit ? '_jit' : '_aot';
final String productOrNo = mode.isRelease ? '_product' : ''; final String productOrNo = mode.isRelease ? '_product' : '';
return _fileSystem.path.join(engineOutPath, 'flutter$jitOrAot${productOrNo}_runner-0.far'); return _fileSystem.path.join(engineOutPath, 'flutter$jitOrAot${productOrNo}_runner-0.far');
case Artifact.fontSubset: case Artifact.fontSubset:
...@@ -856,20 +865,17 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts { ...@@ -856,20 +865,17 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts {
return _fileSystem.path.join(_hostEngineOutPath, artifactFileName); return _fileSystem.path.join(_hostEngineOutPath, artifactFileName);
case Artifact.frontendServerSnapshotForEngineDartSdk: case Artifact.frontendServerSnapshotForEngineDartSdk:
return _fileSystem.path.join(_hostEngineOutPath, 'gen', artifactFileName); return _fileSystem.path.join(_hostEngineOutPath, 'gen', artifactFileName);
break;
case Artifact.uwptool: case Artifact.uwptool:
return _fileSystem.path.join(_hostEngineOutPath, artifactFileName); return _fileSystem.path.join(_hostEngineOutPath, artifactFileName);
} }
assert(false, 'Invalid artifact $artifact.');
return null;
} }
@override @override
String getEngineType(TargetPlatform platform, [ BuildMode mode ]) { String getEngineType(TargetPlatform platform, [ BuildMode? mode ]) {
return _fileSystem.path.basename(engineOutPath); return _fileSystem.path.basename(engineOutPath);
} }
String _getFlutterPatchedSdkPath(BuildMode buildMode) { String _getFlutterPatchedSdkPath(BuildMode? buildMode) {
return _fileSystem.path.join(engineOutPath, return _fileSystem.path.join(engineOutPath,
buildMode == BuildMode.release ? 'flutter_patched_sdk_product' : 'flutter_patched_sdk'); buildMode == BuildMode.release ? 'flutter_patched_sdk_product' : 'flutter_patched_sdk');
} }
...@@ -880,7 +886,7 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts { ...@@ -880,7 +886,7 @@ class CachedLocalEngineArtifacts implements LocalEngineArtifacts {
String _genSnapshotPath() { String _genSnapshotPath() {
const List<String> clangDirs = <String>['.', 'clang_x64', 'clang_x86', 'clang_i386', 'clang_arm64']; const List<String> clangDirs = <String>['.', 'clang_x64', 'clang_x86', 'clang_i386', 'clang_arm64'];
final String genSnapshotName = _artifactToFileName(Artifact.genSnapshot); final String genSnapshotName = _artifactToFileName(Artifact.genSnapshot)!;
for (final String clangDir in clangDirs) { for (final String clangDir in clangDirs) {
final String genSnapshotPath = _fileSystem.path.join(engineOutPath, clangDir, genSnapshotName); final String genSnapshotPath = _fileSystem.path.join(engineOutPath, clangDir, genSnapshotName);
if (_processManager.canRun(genSnapshotPath)) { if (_processManager.canRun(genSnapshotPath)) {
...@@ -913,7 +919,7 @@ class OverrideArtifacts implements Artifacts { ...@@ -913,7 +919,7 @@ class OverrideArtifacts implements Artifacts {
/// ///
/// [parent] must be provided. /// [parent] must be provided.
OverrideArtifacts({ OverrideArtifacts({
@required this.parent, required this.parent,
this.frontendServer, this.frontendServer,
this.engineDartBinary, this.engineDartBinary,
this.platformKernelDill, this.platformKernelDill,
...@@ -921,26 +927,26 @@ class OverrideArtifacts implements Artifacts { ...@@ -921,26 +927,26 @@ class OverrideArtifacts implements Artifacts {
}) : assert(parent != null); }) : assert(parent != null);
final Artifacts parent; final Artifacts parent;
final File frontendServer; final File? frontendServer;
final File engineDartBinary; final File? engineDartBinary;
final File platformKernelDill; final File? platformKernelDill;
final File flutterPatchedSdk; final File? flutterPatchedSdk;
@override @override
String getArtifactPath( String getArtifactPath(
Artifact artifact, { Artifact artifact, {
TargetPlatform platform, TargetPlatform? platform,
BuildMode mode, BuildMode? mode,
EnvironmentType environmentType, EnvironmentType? environmentType,
}) { }) {
if (artifact == Artifact.frontendServerSnapshotForEngineDartSdk && frontendServer != null) { if (artifact == Artifact.frontendServerSnapshotForEngineDartSdk && frontendServer != null) {
return frontendServer.path; return frontendServer!.path;
} }
if (artifact == Artifact.platformKernelDill && platformKernelDill != null) { if (artifact == Artifact.platformKernelDill && platformKernelDill != null) {
return platformKernelDill.path; return platformKernelDill!.path;
} }
if (artifact == Artifact.flutterPatchedSdkPath && flutterPatchedSdk != null) { if (artifact == Artifact.flutterPatchedSdkPath && flutterPatchedSdk != null) {
return flutterPatchedSdk.path; return flutterPatchedSdk!.path;
} }
return parent.getArtifactPath( return parent.getArtifactPath(
artifact, artifact,
...@@ -951,7 +957,7 @@ class OverrideArtifacts implements Artifacts { ...@@ -951,7 +957,7 @@ class OverrideArtifacts implements Artifacts {
} }
@override @override
String getEngineType(TargetPlatform platform, [ BuildMode mode ]) => parent.getEngineType(platform, mode); String getEngineType(TargetPlatform platform, [ BuildMode? mode ]) => parent.getEngineType(platform, mode);
@override @override
bool get isLocalEngine => parent.isLocalEngine; bool get isLocalEngine => parent.isLocalEngine;
...@@ -959,7 +965,7 @@ class OverrideArtifacts implements Artifacts { ...@@ -959,7 +965,7 @@ class OverrideArtifacts implements Artifacts {
@override @override
FileSystemEntity getHostArtifact(HostArtifact artifact) { FileSystemEntity getHostArtifact(HostArtifact artifact) {
if (artifact == HostArtifact.engineDartBinary && engineDartBinary != null) { if (artifact == HostArtifact.engineDartBinary && engineDartBinary != null) {
return engineDartBinary; return engineDartBinary!;
} }
return parent.getHostArtifact( return parent.getHostArtifact(
artifact, artifact,
...@@ -969,7 +975,7 @@ class OverrideArtifacts implements Artifacts { ...@@ -969,7 +975,7 @@ class OverrideArtifacts implements Artifacts {
/// Locate the Dart SDK. /// Locate the Dart SDK.
String _dartSdkPath(FileSystem fileSystem) { String _dartSdkPath(FileSystem fileSystem) {
return fileSystem.path.join(Cache.flutterRoot, 'bin', 'cache', 'dart-sdk'); return fileSystem.path.join(Cache.flutterRoot!, 'bin', 'cache', 'dart-sdk');
} }
class _TestArtifacts implements Artifacts { class _TestArtifacts implements Artifacts {
...@@ -980,9 +986,9 @@ class _TestArtifacts implements Artifacts { ...@@ -980,9 +986,9 @@ class _TestArtifacts implements Artifacts {
@override @override
String getArtifactPath( String getArtifactPath(
Artifact artifact, { Artifact artifact, {
TargetPlatform platform, TargetPlatform? platform,
BuildMode mode, BuildMode? mode,
EnvironmentType environmentType, EnvironmentType? environmentType,
}) { }) {
final StringBuffer buffer = StringBuffer(); final StringBuffer buffer = StringBuffer();
buffer.write(artifact); buffer.write(artifact);
...@@ -999,7 +1005,7 @@ class _TestArtifacts implements Artifacts { ...@@ -999,7 +1005,7 @@ class _TestArtifacts implements Artifacts {
} }
@override @override
String getEngineType(TargetPlatform platform, [ BuildMode mode ]) { String getEngineType(TargetPlatform platform, [ BuildMode? mode ]) {
return 'test-engine'; return 'test-engine';
} }
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// @dart = 2.8
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/artifacts.dart'; import 'package:flutter_tools/src/artifacts.dart';
import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/file_system.dart';
...@@ -18,10 +16,10 @@ import '../src/fakes.dart'; ...@@ -18,10 +16,10 @@ import '../src/fakes.dart';
void main() { void main() {
group('CachedArtifacts', () { group('CachedArtifacts', () {
CachedArtifacts artifacts; late CachedArtifacts artifacts;
Cache cache; late Cache cache;
FileSystem fileSystem; late FileSystem fileSystem;
Platform platform; late Platform platform;
setUp(() { setUp(() {
fileSystem = MemoryFileSystem.test(); fileSystem = MemoryFileSystem.test();
...@@ -185,10 +183,10 @@ void main() { ...@@ -185,10 +183,10 @@ void main() {
}); });
group('LocalEngineArtifacts', () { group('LocalEngineArtifacts', () {
LocalEngineArtifacts artifacts; late LocalEngineArtifacts artifacts;
Cache cache; late Cache cache;
FileSystem fileSystem; late FileSystem fileSystem;
Platform platform; late Platform platform;
setUp(() { setUp(() {
fileSystem = MemoryFileSystem.test(); fileSystem = MemoryFileSystem.test();
......
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