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

[flutter_tools] Remove context from Artifacts class (#48776)

parent 3e634112
...@@ -108,7 +108,11 @@ Future<void> main(List<String> args) async { ...@@ -108,7 +108,11 @@ Future<void> main(List<String> args) async {
DeviceManager: () => _FuchsiaDeviceManager(), DeviceManager: () => _FuchsiaDeviceManager(),
FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig, devFinder: devFinder), FuchsiaArtifacts: () => FuchsiaArtifacts(sshConfig: sshConfig, devFinder: devFinder),
Artifacts: () => OverrideArtifacts( Artifacts: () => OverrideArtifacts(
parent: CachedArtifacts(), parent: CachedArtifacts(
fileSystem: globals.fs,
cache: globals.cache,
platform: globals.platform,
),
frontendServer: frontendServer, frontendServer: frontendServer,
engineDartBinary: dartSdk, engineDartBinary: dartSdk,
platformKernelDill: platformKernelDill, platformKernelDill: platformKernelDill,
......
...@@ -3,10 +3,13 @@ ...@@ -3,10 +3,13 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:platform/platform.dart';
import 'package:process/process.dart';
import 'base/file_system.dart'; import 'base/file_system.dart';
import 'base/utils.dart'; import 'base/utils.dart';
import 'build_info.dart'; import 'build_info.dart';
import 'cache.dart';
import 'dart/sdk.dart'; import 'dart/sdk.dart';
import 'globals.dart' as globals; import 'globals.dart' as globals;
...@@ -156,7 +159,15 @@ class EngineBuildPaths { ...@@ -156,7 +159,15 @@ class EngineBuildPaths {
// Manages the engine artifacts of Flutter. // Manages the engine artifacts of Flutter.
abstract class Artifacts { abstract class Artifacts {
static LocalEngineArtifacts getLocalEngine(String engineSrcPath, EngineBuildPaths engineBuildPaths) { static LocalEngineArtifacts getLocalEngine(String engineSrcPath, EngineBuildPaths engineBuildPaths) {
return LocalEngineArtifacts(engineSrcPath, engineBuildPaths.targetEngine, engineBuildPaths.hostEngine); return LocalEngineArtifacts(
engineSrcPath,
engineBuildPaths.targetEngine,
engineBuildPaths.hostEngine,
cache: globals.cache,
fileSystem: globals.fs,
processManager: globals.processManager,
platform: globals.platform,
);
} }
// Returns the requested [artifact] for the [platform] and [mode] combination. // Returns the requested [artifact] for the [platform] and [mode] combination.
...@@ -167,21 +178,20 @@ abstract class Artifacts { ...@@ -167,21 +178,20 @@ abstract class Artifacts {
String getEngineType(TargetPlatform platform, [ BuildMode mode ]); String getEngineType(TargetPlatform platform, [ BuildMode mode ]);
} }
TargetPlatform get _currentHostPlatform {
if (globals.platform.isMacOS) {
return TargetPlatform.darwin_x64;
}
if (globals.platform.isLinux) {
return TargetPlatform.linux_x64;
}
if (globals.platform.isWindows) {
return TargetPlatform.windows_x64;
}
throw UnimplementedError('Host OS not supported.');
}
/// Manages the engine artifacts downloaded to the local cache. /// Manages the engine artifacts downloaded to the local cache.
class CachedArtifacts extends Artifacts { class CachedArtifacts extends Artifacts {
CachedArtifacts({
@required FileSystem fileSystem,
@required Platform platform,
@required Cache cache,
}) : _fileSystem = fileSystem,
_platform = platform,
_cache = cache;
final FileSystem _fileSystem;
final Platform _platform;
final Cache _cache;
@override @override
String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode }) { String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode }) {
...@@ -203,13 +213,13 @@ class CachedArtifacts extends Artifacts { ...@@ -203,13 +213,13 @@ class CachedArtifacts extends Artifacts {
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.
return _getHostArtifactPath(artifact, platform ?? _currentHostPlatform, mode); return _getHostArtifactPath(artifact, platform ?? _currentHostPlatform(_platform), mode);
} }
} }
@override @override
String getEngineType(TargetPlatform platform, [ BuildMode mode ]) { String getEngineType(TargetPlatform platform, [ BuildMode mode ]) {
return globals.fs.path.basename(_getEngineArtifactsPath(platform, mode)); return _fileSystem.path.basename(_getEngineArtifactsPath(platform, mode));
} }
String _getDarwinArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) { String _getDarwinArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
...@@ -217,9 +227,9 @@ class CachedArtifacts extends Artifacts { ...@@ -217,9 +227,9 @@ class CachedArtifacts extends Artifacts {
// 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 globals.fs.path.join(engineDir, _artifactToFileName(artifact)); return _fileSystem.path.join(engineDir, _artifactToFileName(artifact));
} }
return _getHostArtifactPath(artifact, platform ?? _currentHostPlatform, mode); return _getHostArtifactPath(artifact, platform ?? _currentHostPlatform(_platform), mode);
} }
String _getAndroidArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) { String _getAndroidArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
...@@ -227,11 +237,11 @@ class CachedArtifacts extends Artifacts { ...@@ -227,11 +237,11 @@ class CachedArtifacts extends Artifacts {
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.');
return globals.fs.path.join(engineDir, _artifactToFileName(artifact)); return _fileSystem.path.join(engineDir, _artifactToFileName(artifact));
case Artifact.genSnapshot: case Artifact.genSnapshot:
assert(mode != BuildMode.debug, 'Artifact $artifact only available in non-debug mode.'); assert(mode != BuildMode.debug, 'Artifact $artifact only available in non-debug mode.');
final String hostPlatform = getNameForHostPlatform(getCurrentHostPlatform()); final String hostPlatform = getNameForHostPlatform(getCurrentHostPlatform());
return globals.fs.path.join(engineDir, hostPlatform, _artifactToFileName(artifact)); return _fileSystem.path.join(engineDir, hostPlatform, _artifactToFileName(artifact));
default: default:
return _getHostArtifactPath(artifact, platform, mode); return _getHostArtifactPath(artifact, platform, mode);
} }
...@@ -245,31 +255,31 @@ class CachedArtifacts extends Artifacts { ...@@ -245,31 +255,31 @@ class CachedArtifacts extends Artifacts {
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 globals.fs.path.join(engineDir, artifactFileName); return _fileSystem.path.join(engineDir, artifactFileName);
case Artifact.ideviceId: case Artifact.ideviceId:
case Artifact.ideviceinfo: case Artifact.ideviceinfo:
case Artifact.idevicescreenshot: case Artifact.idevicescreenshot:
case Artifact.idevicesyslog: case Artifact.idevicesyslog:
case Artifact.idevicename: case Artifact.idevicename:
final String artifactFileName = _artifactToFileName(artifact); final String artifactFileName = _artifactToFileName(artifact);
return globals.cache.getArtifactDirectory('libimobiledevice').childFile(artifactFileName).path; return _cache.getArtifactDirectory('libimobiledevice').childFile(artifactFileName).path;
case Artifact.iosDeploy: case Artifact.iosDeploy:
final String artifactFileName = _artifactToFileName(artifact); final String artifactFileName = _artifactToFileName(artifact);
return globals.cache.getArtifactDirectory('ios-deploy').childFile(artifactFileName).path; return _cache.getArtifactDirectory('ios-deploy').childFile(artifactFileName).path;
case Artifact.ideviceinstaller: case Artifact.ideviceinstaller:
final String artifactFileName = _artifactToFileName(artifact); final String artifactFileName = _artifactToFileName(artifact);
return globals.cache.getArtifactDirectory('ideviceinstaller').childFile(artifactFileName).path; return _cache.getArtifactDirectory('ideviceinstaller').childFile(artifactFileName).path;
case Artifact.iproxy: case Artifact.iproxy:
final String artifactFileName = _artifactToFileName(artifact); final String artifactFileName = _artifactToFileName(artifact);
return globals.cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName).path; return _cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName).path;
default: default:
return _getHostArtifactPath(artifact, platform, mode); return _getHostArtifactPath(artifact, platform, mode);
} }
} }
String _getFuchsiaArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) { String _getFuchsiaArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
final String root = globals.fs.path.join( final String root = _fileSystem.path.join(
globals.cache.getArtifactDirectory('flutter_runner').path, _cache.getArtifactDirectory('flutter_runner').path,
'flutter', 'flutter',
fuchsiaArchForTargetPlatform(platform), fuchsiaArchForTargetPlatform(platform),
mode.isRelease ? 'release' : mode.toString(), mode.isRelease ? 'release' : mode.toString(),
...@@ -278,32 +288,32 @@ class CachedArtifacts extends Artifacts { ...@@ -278,32 +288,32 @@ class CachedArtifacts extends Artifacts {
switch (artifact) { switch (artifact) {
case Artifact.genSnapshot: case Artifact.genSnapshot:
final String genSnapshot = mode.isRelease ? 'gen_snapshot_product' : 'gen_snapshot'; final String genSnapshot = mode.isRelease ? 'gen_snapshot_product' : 'gen_snapshot';
return globals.fs.path.join(root, runtime, 'dart_binaries', genSnapshot); return _fileSystem.path.join(root, runtime, 'dart_binaries', genSnapshot);
case Artifact.flutterPatchedSdkPath: case Artifact.flutterPatchedSdkPath:
const String artifactFileName = 'flutter_runner_patched_sdk'; const String artifactFileName = 'flutter_runner_patched_sdk';
return globals.fs.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 globals.fs.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 globals.fs.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 globals.fs.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 = globals.cache.getArtifactDirectory('engine').path; final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
return globals.fs.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');
} }
String _getFlutterWebSdkPath() { String _getFlutterWebSdkPath() {
return globals.cache.getWebSdkDirectory().path; return _cache.getWebSdkDirectory().path;
} }
String _getHostArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) { String _getHostArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) {
...@@ -317,29 +327,29 @@ class CachedArtifacts extends Artifacts { ...@@ -317,29 +327,29 @@ class CachedArtifacts extends Artifacts {
case Artifact.vmSnapshotData: case Artifact.vmSnapshotData:
case Artifact.isolateSnapshotData: case Artifact.isolateSnapshotData:
case Artifact.frontendServerSnapshotForEngineDartSdk: case Artifact.frontendServerSnapshotForEngineDartSdk:
final String engineArtifactsPath = globals.cache.getArtifactDirectory('engine').path; final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
final String platformDirName = getNameForTargetPlatform(platform); final String platformDirName = getNameForTargetPlatform(platform);
return globals.fs.path.join(engineArtifactsPath, platformDirName, _artifactToFileName(artifact, platform, mode)); return _fileSystem.path.join(engineArtifactsPath, platformDirName, _artifactToFileName(artifact, platform, mode));
case Artifact.engineDartSdkPath: case Artifact.engineDartSdkPath:
return dartSdkPath; return dartSdkPath;
case Artifact.engineDartBinary: case Artifact.engineDartBinary:
return globals.fs.path.join(dartSdkPath, 'bin', _artifactToFileName(artifact, platform)); return _fileSystem.path.join(dartSdkPath, 'bin', _artifactToFileName(artifact, platform));
case Artifact.platformKernelDill: case Artifact.platformKernelDill:
return globals.fs.path.join(_getFlutterPatchedSdkPath(mode), _artifactToFileName(artifact)); return _fileSystem.path.join(_getFlutterPatchedSdkPath(mode), _artifactToFileName(artifact));
case Artifact.platformLibrariesJson: case Artifact.platformLibrariesJson:
return globals.fs.path.join(_getFlutterPatchedSdkPath(mode), 'lib', _artifactToFileName(artifact)); return _fileSystem.path.join(_getFlutterPatchedSdkPath(mode), 'lib', _artifactToFileName(artifact));
case Artifact.flutterPatchedSdkPath: case Artifact.flutterPatchedSdkPath:
return _getFlutterPatchedSdkPath(mode); return _getFlutterPatchedSdkPath(mode);
case Artifact.flutterWebSdk: case Artifact.flutterWebSdk:
return _getFlutterWebSdkPath(); return _getFlutterWebSdkPath();
case Artifact.webPlatformKernelDill: case Artifact.webPlatformKernelDill:
return globals.fs.path.join(_getFlutterWebSdkPath(), 'kernel', _artifactToFileName(artifact)); return _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', _artifactToFileName(artifact));
case Artifact.dart2jsSnapshot: case Artifact.dart2jsSnapshot:
return globals.fs.path.join(dartSdkPath, 'bin', 'snapshots', _artifactToFileName(artifact)); return _fileSystem.path.join(dartSdkPath, 'bin', 'snapshots', _artifactToFileName(artifact));
case Artifact.dartdevcSnapshot: case Artifact.dartdevcSnapshot:
return globals.fs.path.join(dartSdkPath, 'bin', 'snapshots', _artifactToFileName(artifact)); return _fileSystem.path.join(dartSdkPath, 'bin', 'snapshots', _artifactToFileName(artifact));
case Artifact.kernelWorkerSnapshot: case Artifact.kernelWorkerSnapshot:
return globals.fs.path.join(dartSdkPath, 'bin', 'snapshots', _artifactToFileName(artifact)); return _fileSystem.path.join(dartSdkPath, 'bin', 'snapshots', _artifactToFileName(artifact));
case Artifact.flutterMacOSFramework: case Artifact.flutterMacOSFramework:
case Artifact.linuxDesktopPath: case Artifact.linuxDesktopPath:
case Artifact.windowsDesktopPath: case Artifact.windowsDesktopPath:
...@@ -351,11 +361,11 @@ class CachedArtifacts extends Artifacts { ...@@ -351,11 +361,11 @@ class CachedArtifacts extends Artifacts {
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 = globals.cache.getArtifactDirectory('engine').path; final String engineArtifactsPath = _cache.getArtifactDirectory('engine').path;
return globals.fs.path.join(engineArtifactsPath, platformDirName, _artifactToFileName(artifact, platform, mode)); return _fileSystem.path.join(engineArtifactsPath, platformDirName, _artifactToFileName(artifact, platform, mode));
case Artifact.skyEnginePath: case Artifact.skyEnginePath:
final Directory dartPackageDirectory = globals.cache.getCacheDir('pkg'); final Directory dartPackageDirectory = _cache.getCacheDir('pkg');
return globals.fs.path.join(dartPackageDirectory.path, _artifactToFileName(artifact)); return _fileSystem.path.join(dartPackageDirectory.path, _artifactToFileName(artifact));
default: default:
assert(false, 'Artifact $artifact not available for platform $platform.'); assert(false, 'Artifact $artifact not available for platform $platform.');
return null; return null;
...@@ -363,7 +373,7 @@ class CachedArtifacts extends Artifacts { ...@@ -363,7 +373,7 @@ class CachedArtifacts extends Artifacts {
} }
String _getEngineArtifactsPath(TargetPlatform platform, [ BuildMode mode ]) { String _getEngineArtifactsPath(TargetPlatform platform, [ BuildMode mode ]) {
final String engineDir = globals.cache.getArtifactDirectory('engine').path; final String engineDir = _cache.getArtifactDirectory('engine').path;
final String platformName = getNameForTargetPlatform(platform); final String platformName = getNameForTargetPlatform(platform);
switch (platform) { switch (platform) {
case TargetPlatform.linux_x64: case TargetPlatform.linux_x64:
...@@ -373,16 +383,16 @@ class CachedArtifacts extends Artifacts { ...@@ -373,16 +383,16 @@ class CachedArtifacts extends Artifacts {
// under a separate directory from the host artifacts. // under a separate directory from the host artifacts.
// https://github.com/flutter/flutter/issues/38935 // https://github.com/flutter/flutter/issues/38935
if (mode == BuildMode.debug || mode == null) { if (mode == BuildMode.debug || mode == null) {
return globals.fs.path.join(engineDir, platformName); return _fileSystem.path.join(engineDir, platformName);
} }
final String suffix = mode != BuildMode.debug ? '-${snakeCase(getModeName(mode), '-')}' : ''; final String suffix = mode != BuildMode.debug ? '-${snakeCase(getModeName(mode), '-')}' : '';
return globals.fs.path.join(engineDir, platformName + suffix); return _fileSystem.path.join(engineDir, platformName + suffix);
case TargetPlatform.fuchsia_arm64: case TargetPlatform.fuchsia_arm64:
case TargetPlatform.fuchsia_x64: case TargetPlatform.fuchsia_x64:
case TargetPlatform.tester: case TargetPlatform.tester:
case TargetPlatform.web_javascript: case TargetPlatform.web_javascript:
assert(mode == null, 'Platform $platform does not support different build modes.'); assert(mode == null, 'Platform $platform does not support different build modes.');
return globals.fs.path.join(engineDir, platformName); return _fileSystem.path.join(engineDir, platformName);
case TargetPlatform.ios: case TargetPlatform.ios:
case TargetPlatform.android_arm: case TargetPlatform.android_arm:
case TargetPlatform.android_arm64: case TargetPlatform.android_arm64:
...@@ -390,7 +400,7 @@ class CachedArtifacts extends Artifacts { ...@@ -390,7 +400,7 @@ class CachedArtifacts extends Artifacts {
case TargetPlatform.android_x86: case TargetPlatform.android_x86:
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 globals.fs.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;
...@@ -400,93 +410,134 @@ class CachedArtifacts extends Artifacts { ...@@ -400,93 +410,134 @@ class CachedArtifacts extends Artifacts {
} }
} }
TargetPlatform _currentHostPlatform(Platform platform) {
if (platform.isMacOS) {
return TargetPlatform.darwin_x64;
}
if (platform.isLinux) {
return TargetPlatform.linux_x64;
}
if (platform.isWindows) {
return TargetPlatform.windows_x64;
}
throw UnimplementedError('Host OS not supported.');
}
HostPlatform _currentHostPlatformAsHost(Platform platform) {
if (platform.isMacOS) {
return HostPlatform.darwin_x64;
}
if (platform.isLinux) {
return HostPlatform.linux_x64;
}
if (platform.isWindows) {
return HostPlatform.windows_x64;
}
throw UnimplementedError('Host OS not supported.');
}
/// Manages the artifacts of a locally built engine. /// Manages the artifacts of a locally built engine.
class LocalEngineArtifacts extends Artifacts { class LocalEngineArtifacts extends Artifacts {
LocalEngineArtifacts(this._engineSrcPath, this.engineOutPath, this._hostEngineOutPath); LocalEngineArtifacts(
this._engineSrcPath,
this.engineOutPath,
this._hostEngineOutPath, {
@required FileSystem fileSystem,
@required Cache cache,
@required ProcessManager processManager,
@required Platform platform,
}) : _fileSystem = fileSystem,
_cache = cache,
_processManager = processManager,
_platform = platform;
final String _engineSrcPath; final String _engineSrcPath;
final String engineOutPath; // TODO(goderbauer): This should be private. final String engineOutPath; // TODO(goderbauer): This should be private.
final String _hostEngineOutPath; final String _hostEngineOutPath;
final FileSystem _fileSystem;
final Cache _cache;
final ProcessManager _processManager;
final Platform _platform;
@override @override
String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode }) { String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode }) {
platform ??= _currentHostPlatform; platform ??= _currentHostPlatform(_platform);
final String artifactFileName = _artifactToFileName(artifact, platform, mode); final String artifactFileName = _artifactToFileName(artifact, platform, mode);
switch (artifact) { switch (artifact) {
case Artifact.snapshotDart: case Artifact.snapshotDart:
return globals.fs.path.join(_engineSrcPath, 'flutter', 'lib', 'snapshot', artifactFileName); return _fileSystem.path.join(_engineSrcPath, 'flutter', 'lib', 'snapshot', artifactFileName);
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 globals.fs.path.join(engineOutPath, 'gen', 'flutter', 'lib', 'snapshot', artifactFileName); return _fileSystem.path.join(engineOutPath, 'gen', 'flutter', 'lib', 'snapshot', artifactFileName);
case Artifact.platformKernelDill: case Artifact.platformKernelDill:
if (platform == TargetPlatform.fuchsia_x64 || platform == TargetPlatform.fuchsia_arm64) { if (platform == TargetPlatform.fuchsia_x64 || platform == TargetPlatform.fuchsia_arm64) {
return globals.fs.path.join(engineOutPath, 'flutter_runner_patched_sdk', artifactFileName); return _fileSystem.path.join(engineOutPath, 'flutter_runner_patched_sdk', artifactFileName);
} }
return globals.fs.path.join(_getFlutterPatchedSdkPath(mode), artifactFileName); return _fileSystem.path.join(_getFlutterPatchedSdkPath(mode), artifactFileName);
case Artifact.platformLibrariesJson: case Artifact.platformLibrariesJson:
return globals.fs.path.join(_getFlutterPatchedSdkPath(mode), 'lib', artifactFileName); return _fileSystem.path.join(_getFlutterPatchedSdkPath(mode), 'lib', artifactFileName);
case Artifact.flutterFramework: case Artifact.flutterFramework:
return globals.fs.path.join(engineOutPath, artifactFileName); return _fileSystem.path.join(engineOutPath, artifactFileName);
case Artifact.flutterMacOSFramework: case Artifact.flutterMacOSFramework:
return globals.fs.path.join(engineOutPath, artifactFileName); return _fileSystem.path.join(engineOutPath, artifactFileName);
case Artifact.flutterPatchedSdkPath: case Artifact.flutterPatchedSdkPath:
// When using local engine always use [BuildMode.debug] regardless of // When using local engine always use [BuildMode.debug] regardless of
// what was specified in [mode] argument because local engine will // what was specified in [mode] argument because local engine will
// have only one flutter_patched_sdk in standard location, that // have only one flutter_patched_sdk in standard location, that
// is happen to be what debug(non-release) mode is using. // is happen to be what debug(non-release) mode is using.
if (platform == TargetPlatform.fuchsia_x64 || platform == TargetPlatform.fuchsia_arm64) { if (platform == TargetPlatform.fuchsia_x64 || platform == TargetPlatform.fuchsia_arm64) {
return globals.fs.path.join(engineOutPath, 'flutter_runner_patched_sdk'); return _fileSystem.path.join(engineOutPath, 'flutter_runner_patched_sdk');
} }
return _getFlutterPatchedSdkPath(BuildMode.debug); return _getFlutterPatchedSdkPath(BuildMode.debug);
case Artifact.flutterWebSdk: case Artifact.flutterWebSdk:
return _getFlutterWebSdkPath(); return _getFlutterWebSdkPath();
case Artifact.frontendServerSnapshotForEngineDartSdk: case Artifact.frontendServerSnapshotForEngineDartSdk:
return globals.fs.path.join(_hostEngineOutPath, 'gen', artifactFileName); return _fileSystem.path.join(_hostEngineOutPath, 'gen', artifactFileName);
case Artifact.engineDartSdkPath: case Artifact.engineDartSdkPath:
return globals.fs.path.join(_hostEngineOutPath, 'dart-sdk'); return _fileSystem.path.join(_hostEngineOutPath, 'dart-sdk');
case Artifact.engineDartBinary: case Artifact.engineDartBinary:
return globals.fs.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', artifactFileName); return _fileSystem.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', artifactFileName);
case Artifact.dart2jsSnapshot: case Artifact.dart2jsSnapshot:
return globals.fs.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', 'snapshots', artifactFileName); return _fileSystem.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', 'snapshots', artifactFileName);
case Artifact.dartdevcSnapshot: case Artifact.dartdevcSnapshot:
return globals.fs.path.join(dartSdkPath, 'bin', 'snapshots', artifactFileName); return _fileSystem.path.join(dartSdkPath, 'bin', 'snapshots', artifactFileName);
case Artifact.kernelWorkerSnapshot: case Artifact.kernelWorkerSnapshot:
return globals.fs.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', 'snapshots', artifactFileName); return _fileSystem.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', 'snapshots', artifactFileName);
case Artifact.ideviceId: case Artifact.ideviceId:
case Artifact.ideviceinfo: case Artifact.ideviceinfo:
case Artifact.idevicename: case Artifact.idevicename:
case Artifact.idevicescreenshot: case Artifact.idevicescreenshot:
case Artifact.idevicesyslog: case Artifact.idevicesyslog:
return globals.cache.getArtifactDirectory('libimobiledevice').childFile(artifactFileName).path; return _cache.getArtifactDirectory('libimobiledevice').childFile(artifactFileName).path;
case Artifact.ideviceinstaller: case Artifact.ideviceinstaller:
return globals.cache.getArtifactDirectory('ideviceinstaller').childFile(artifactFileName).path; return _cache.getArtifactDirectory('ideviceinstaller').childFile(artifactFileName).path;
case Artifact.iosDeploy: case Artifact.iosDeploy:
return globals.cache.getArtifactDirectory('ios-deploy').childFile(artifactFileName).path; return _cache.getArtifactDirectory('ios-deploy').childFile(artifactFileName).path;
case Artifact.iproxy: case Artifact.iproxy:
return globals.cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName).path; return _cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName).path;
case Artifact.linuxDesktopPath: case Artifact.linuxDesktopPath:
return globals.fs.path.join(_hostEngineOutPath, artifactFileName); return _fileSystem.path.join(_hostEngineOutPath, artifactFileName);
case Artifact.windowsDesktopPath: case Artifact.windowsDesktopPath:
return globals.fs.path.join(_hostEngineOutPath, artifactFileName); return _fileSystem.path.join(_hostEngineOutPath, artifactFileName);
case Artifact.skyEnginePath: case Artifact.skyEnginePath:
return globals.fs.path.join(_hostEngineOutPath, 'gen', 'dart-pkg', artifactFileName); return _fileSystem.path.join(_hostEngineOutPath, 'gen', 'dart-pkg', artifactFileName);
case Artifact.flutterMacOSPodspec: case Artifact.flutterMacOSPodspec:
return globals.fs.path.join(_hostEngineOutPath, _artifactToFileName(artifact)); return _fileSystem.path.join(_hostEngineOutPath, _artifactToFileName(artifact));
case Artifact.webPlatformKernelDill: case Artifact.webPlatformKernelDill:
return globals.fs.path.join(_getFlutterWebSdkPath(), 'kernel', _artifactToFileName(artifact)); return _fileSystem.path.join(_getFlutterWebSdkPath(), 'kernel', _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 globals.fs.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 globals.fs.path.join(engineOutPath, 'flutter$jitOrAot${productOrNo}_runner-0.far'); return _fileSystem.path.join(engineOutPath, 'flutter$jitOrAot${productOrNo}_runner-0.far');
} }
assert(false, 'Invalid artifact $artifact.'); assert(false, 'Invalid artifact $artifact.');
return null; return null;
...@@ -494,24 +545,24 @@ class LocalEngineArtifacts extends Artifacts { ...@@ -494,24 +545,24 @@ class LocalEngineArtifacts extends Artifacts {
@override @override
String getEngineType(TargetPlatform platform, [ BuildMode mode ]) { String getEngineType(TargetPlatform platform, [ BuildMode mode ]) {
return globals.fs.path.basename(engineOutPath); return _fileSystem.path.basename(engineOutPath);
} }
String _getFlutterPatchedSdkPath(BuildMode buildMode) { String _getFlutterPatchedSdkPath(BuildMode buildMode) {
return globals.fs.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');
} }
String _getFlutterWebSdkPath() { String _getFlutterWebSdkPath() {
return globals.fs.path.join(engineOutPath, 'flutter_web_sdk'); return _fileSystem.path.join(engineOutPath, 'flutter_web_sdk');
} }
String _genSnapshotPath() { String _genSnapshotPath() {
const List<String> clangDirs = <String>['.', 'clang_x64', 'clang_x86', 'clang_i386']; const List<String> clangDirs = <String>['.', 'clang_x64', 'clang_x86', 'clang_i386'];
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 = globals.fs.path.join(engineOutPath, clangDir, genSnapshotName); final String genSnapshotPath = _fileSystem.path.join(engineOutPath, clangDir, genSnapshotName);
if (globals.processManager.canRun(genSnapshotPath)) { if (_processManager.canRun(genSnapshotPath)) {
return genSnapshotPath; return genSnapshotPath;
} }
} }
...@@ -519,12 +570,13 @@ class LocalEngineArtifacts extends Artifacts { ...@@ -519,12 +570,13 @@ class LocalEngineArtifacts extends Artifacts {
} }
String _flutterTesterPath(TargetPlatform platform) { String _flutterTesterPath(TargetPlatform platform) {
if (getCurrentHostPlatform() == HostPlatform.linux_x64) { final HostPlatform hostPlatform = _currentHostPlatformAsHost(_platform);
return globals.fs.path.join(engineOutPath, _artifactToFileName(Artifact.flutterTester)); if (hostPlatform == HostPlatform.linux_x64) {
} else if (getCurrentHostPlatform() == HostPlatform.darwin_x64) { return _fileSystem.path.join(engineOutPath, _artifactToFileName(Artifact.flutterTester));
return globals.fs.path.join(engineOutPath, 'flutter_tester'); } else if (hostPlatform == HostPlatform.darwin_x64) {
} else if (getCurrentHostPlatform() == HostPlatform.windows_x64) { return _fileSystem.path.join(engineOutPath, 'flutter_tester');
return globals.fs.path.join(engineOutPath, 'flutter_tester.exe'); } else if (hostPlatform == HostPlatform.windows_x64) {
return _fileSystem.path.join(engineOutPath, 'flutter_tester.exe');
} }
throw Exception('Unsupported platform $platform.'); throw Exception('Unsupported platform $platform.');
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:async'; import 'dart:async';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:platform/platform.dart';
import 'android/gradle_utils.dart'; import 'android/gradle_utils.dart';
import 'base/common.dart'; import 'base/common.dart';
...@@ -89,7 +90,19 @@ class DevelopmentArtifact { ...@@ -89,7 +90,19 @@ class DevelopmentArtifact {
class Cache { class Cache {
/// [rootOverride] is configurable for testing. /// [rootOverride] is configurable for testing.
/// [artifacts] is configurable for testing. /// [artifacts] is configurable for testing.
Cache({ Directory rootOverride, List<ArtifactSet> artifacts }) : _rootOverride = rootOverride { Cache({
Directory rootOverride,
List<ArtifactSet> artifacts,
// TODO(jonahwilliams): make required once migrated to context-free.
Logger logger,
FileSystem fileSystem,
Platform platform,
OperatingSystemUtils osUtils,
}) : _rootOverride = rootOverride,
_logger = logger ?? globals.logger,
_fileSystem = fileSystem ?? globals.fs,
_platform = platform ?? globals.platform ,
_osUtils = osUtils ?? os {
if (artifacts == null) { if (artifacts == null) {
_artifacts.add(MaterialFonts(this)); _artifacts.add(MaterialFonts(this));
...@@ -116,6 +129,11 @@ class Cache { ...@@ -116,6 +129,11 @@ class Cache {
} }
} }
final Logger _logger;
final Platform _platform;
final FileSystem _fileSystem;
final OperatingSystemUtils _osUtils;
static const List<String> _hostsBlockedInChina = <String> [ static const List<String> _hostsBlockedInChina = <String> [
'storage.googleapis.com', 'storage.googleapis.com',
]; ];
...@@ -217,7 +235,7 @@ class Cache { ...@@ -217,7 +235,7 @@ class Cache {
if (_dartSdkVersion == null) { if (_dartSdkVersion == null) {
// Make the version string more customer-friendly. // Make the version string more customer-friendly.
// Changes '2.1.0-dev.8.0.flutter-4312ae32' to '2.1.0 (build 2.1.0-dev.8.0 4312ae32)' // Changes '2.1.0-dev.8.0.flutter-4312ae32' to '2.1.0 (build 2.1.0-dev.8.0 4312ae32)'
final String justVersion = globals.platform.version.split(' ')[0]; final String justVersion = _platform.version.split(' ')[0];
_dartSdkVersion = justVersion.replaceFirstMapped(RegExp(r'(\d+\.\d+\.\d+)(.+)'), (Match match) { _dartSdkVersion = justVersion.replaceFirstMapped(RegExp(r'(\d+\.\d+\.\d+)(.+)'), (Match match) {
final String noFlutter = match[2].replaceAll('.flutter-', ' '); final String noFlutter = match[2].replaceAll('.flutter-', ' ');
return '${match[1]} (build ${match[1]}$noFlutter)'; return '${match[1]} (build ${match[1]}$noFlutter)';
...@@ -234,7 +252,7 @@ class Cache { ...@@ -234,7 +252,7 @@ class Cache {
String _engineRevision; String _engineRevision;
String get storageBaseUrl { String get storageBaseUrl {
final String overrideUrl = globals.platform.environment['FLUTTER_STORAGE_BASE_URL']; final String overrideUrl = _platform.environment['FLUTTER_STORAGE_BASE_URL'];
if (overrideUrl == null) { if (overrideUrl == null) {
return 'https://storage.googleapis.com'; return 'https://storage.googleapis.com';
} }
...@@ -254,7 +272,7 @@ class Cache { ...@@ -254,7 +272,7 @@ class Cache {
if (_hasWarnedAboutStorageOverride) { if (_hasWarnedAboutStorageOverride) {
return; return;
} }
globals.logger.printStatus( _logger.printStatus(
'Flutter assets will be downloaded from $overrideUrl. Make sure you trust this source!', 'Flutter assets will be downloaded from $overrideUrl. Make sure you trust this source!',
emphasis: true, emphasis: true,
); );
...@@ -264,18 +282,18 @@ class Cache { ...@@ -264,18 +282,18 @@ class Cache {
/// Return the top-level directory in the cache; this is `bin/cache`. /// Return the top-level directory in the cache; this is `bin/cache`.
Directory getRoot() { Directory getRoot() {
if (_rootOverride != null) { if (_rootOverride != null) {
return globals.fs.directory(globals.fs.path.join(_rootOverride.path, 'bin', 'cache')); return _fileSystem.directory(_fileSystem.path.join(_rootOverride.path, 'bin', 'cache'));
} else { } else {
return globals.fs.directory(globals.fs.path.join(flutterRoot, 'bin', 'cache')); return _fileSystem.directory(_fileSystem.path.join(flutterRoot, 'bin', 'cache'));
} }
} }
/// Return a directory in the cache dir. For `pkg`, this will return `bin/cache/pkg`. /// Return a directory in the cache dir. For `pkg`, this will return `bin/cache/pkg`.
Directory getCacheDir(String name) { Directory getCacheDir(String name) {
final Directory dir = globals.fs.directory(globals.fs.path.join(getRoot().path, name)); final Directory dir = _fileSystem.directory(_fileSystem.path.join(getRoot().path, name));
if (!dir.existsSync()) { if (!dir.existsSync()) {
dir.createSync(recursive: true); dir.createSync(recursive: true);
os.chmod(dir, '755'); _osUtils.chmod(dir, '755');
} }
return dir; return dir;
} }
...@@ -287,7 +305,7 @@ class Cache { ...@@ -287,7 +305,7 @@ class Cache {
Directory getCacheArtifacts() => getCacheDir('artifacts'); Directory getCacheArtifacts() => getCacheDir('artifacts');
/// Location of LICENSE file. /// Location of LICENSE file.
File getLicenseFile() => globals.fs.file(globals.fs.path.join(flutterRoot, 'LICENSE')); File getLicenseFile() => _fileSystem.file(_fileSystem.path.join(flutterRoot, 'LICENSE'));
/// Get a named directory from with the cache's artifact directory; for example, /// Get a named directory from with the cache's artifact directory; for example,
/// `material_fonts` would return `bin/cache/artifacts/material_fonts`. /// `material_fonts` would return `bin/cache/artifacts/material_fonts`.
...@@ -323,7 +341,7 @@ class Cache { ...@@ -323,7 +341,7 @@ class Cache {
} }
String getVersionFor(String artifactName) { String getVersionFor(String artifactName) {
final File versionFile = globals.fs.file(globals.fs.path.join( final File versionFile = _fileSystem.file(globals.fs.path.join(
_rootOverride?.path ?? flutterRoot, 'bin', 'internal', _rootOverride?.path ?? flutterRoot, 'bin', 'internal',
'$artifactName.version')); '$artifactName.version'));
return versionFile.existsSync() ? versionFile.readAsStringSync().trim() : null; return versionFile.existsSync() ? versionFile.readAsStringSync().trim() : null;
...@@ -339,7 +357,7 @@ class Cache { ...@@ -339,7 +357,7 @@ class Cache {
} }
File getStampFileFor(String artifactName) { File getStampFileFor(String artifactName) {
return globals.fs.file(globals.fs.path.join(getRoot().path, '$artifactName.stamp')); return _fileSystem.file(_fileSystem.path.join(getRoot().path, '$artifactName.stamp'));
} }
/// Returns `true` if either [entity] is older than the tools stamp or if /// Returns `true` if either [entity] is older than the tools stamp or if
...@@ -358,13 +376,13 @@ class Cache { ...@@ -358,13 +376,13 @@ class Cache {
final Uri url = Uri.parse(urlStr); final Uri url = Uri.parse(urlStr);
final Directory thirdPartyDir = getArtifactDirectory('third_party'); final Directory thirdPartyDir = getArtifactDirectory('third_party');
final Directory serviceDir = globals.fs.directory(globals.fs.path.join(thirdPartyDir.path, serviceName)); final Directory serviceDir = _fileSystem.directory(_fileSystem.path.join(thirdPartyDir.path, serviceName));
if (!serviceDir.existsSync()) { if (!serviceDir.existsSync()) {
serviceDir.createSync(recursive: true); serviceDir.createSync(recursive: true);
os.chmod(serviceDir, '755'); _osUtils.chmod(serviceDir, '755');
} }
final File cachedFile = globals.fs.file(globals.fs.path.join(serviceDir.path, url.pathSegments.last)); final File cachedFile = _fileSystem.file(_fileSystem.path.join(serviceDir.path, url.pathSegments.last));
if (!cachedFile.existsSync()) { if (!cachedFile.existsSync()) {
try { try {
await _downloadFile(url, cachedFile); await _downloadFile(url, cachedFile);
...@@ -383,7 +401,7 @@ class Cache { ...@@ -383,7 +401,7 @@ class Cache {
} }
for (final ArtifactSet artifact in _artifacts) { for (final ArtifactSet artifact in _artifacts) {
if (!requiredArtifacts.contains(artifact.developmentArtifact)) { if (!requiredArtifacts.contains(artifact.developmentArtifact)) {
globals.printTrace('Artifact $artifact is not required, skipping update.'); _logger.printTrace('Artifact $artifact is not required, skipping update.');
continue; continue;
} }
if (artifact.isUpToDate()) { if (artifact.isUpToDate()) {
...@@ -393,7 +411,7 @@ class Cache { ...@@ -393,7 +411,7 @@ class Cache {
await artifact.update(); await artifact.update();
} on SocketException catch (e) { } on SocketException catch (e) {
if (_hostsBlockedInChina.contains(e.address?.host)) { if (_hostsBlockedInChina.contains(e.address?.host)) {
globals.printError( _logger.printError(
'Failed to retrieve Flutter tool dependencies: ${e.message}.\n' 'Failed to retrieve Flutter tool dependencies: ${e.message}.\n'
'If you\'re in China, please see this page: ' 'If you\'re in China, please see this page: '
'https://flutter.dev/community/china', 'https://flutter.dev/community/china',
...@@ -409,15 +427,15 @@ class Cache { ...@@ -409,15 +427,15 @@ class Cache {
String engineVersion, String engineVersion,
bool includeAllPlatforms = true, bool includeAllPlatforms = true,
}) async { }) async {
final bool includeAllPlatformsState = globals.cache.includeAllPlatforms; final bool includeAllPlatformsState = this.includeAllPlatforms;
bool allAvailible = true; bool allAvailible = true;
globals.cache.includeAllPlatforms = includeAllPlatforms; this.includeAllPlatforms = includeAllPlatforms;
for (final ArtifactSet cachedArtifact in _artifacts) { for (final ArtifactSet cachedArtifact in _artifacts) {
if (cachedArtifact is EngineCachedArtifact) { if (cachedArtifact is EngineCachedArtifact) {
allAvailible &= await cachedArtifact.checkForArtifacts(engineVersion); allAvailible &= await cachedArtifact.checkForArtifacts(engineVersion);
} }
} }
globals.cache.includeAllPlatforms = includeAllPlatformsState; this.includeAllPlatforms = includeAllPlatformsState;
return allAvailible; return allAvailible;
} }
} }
......
...@@ -72,10 +72,18 @@ Future<T> runInContext<T>( ...@@ -72,10 +72,18 @@ Future<T> runInContext<T>(
AndroidValidator: () => AndroidValidator(), AndroidValidator: () => AndroidValidator(),
AndroidWorkflow: () => AndroidWorkflow(), AndroidWorkflow: () => AndroidWorkflow(),
ApplicationPackageFactory: () => ApplicationPackageFactory(), ApplicationPackageFactory: () => ApplicationPackageFactory(),
Artifacts: () => CachedArtifacts(), Artifacts: () => CachedArtifacts(
fileSystem: globals.fs,
cache: globals.cache,
platform: globals.platform,
),
AssetBundleFactory: () => AssetBundleFactory.defaultInstance, AssetBundleFactory: () => AssetBundleFactory.defaultInstance,
BuildSystem: () => const BuildSystem(), BuildSystem: () => const BuildSystem(),
Cache: () => Cache(), Cache: () => Cache(
fileSystem: globals.fs,
logger: globals.logger,
platform: globals.platform,
),
ChromeLauncher: () => const ChromeLauncher(), ChromeLauncher: () => const ChromeLauncher(),
CocoaPods: () => CocoaPods(), CocoaPods: () => CocoaPods(),
CocoaPodsValidator: () => const CocoaPodsValidator(), CocoaPodsValidator: () => const CocoaPodsValidator(),
......
...@@ -1054,21 +1054,24 @@ plugin1=${plugin1.path} ...@@ -1054,21 +1054,24 @@ plugin1=${plugin1.path}
MockLocalEngineArtifacts mockArtifacts; MockLocalEngineArtifacts mockArtifacts;
MockProcessManager mockProcessManager; MockProcessManager mockProcessManager;
FakePlatform android; FakePlatform android;
FileSystem fs; FileSystem fileSystem;
Cache cache; Cache cache;
setUp(() { setUp(() {
fs = MemoryFileSystem(); fileSystem = MemoryFileSystem();
mockAndroidSdk = MockAndroidSdk(); mockAndroidSdk = MockAndroidSdk();
mockAndroidStudio = MockAndroidStudio(); mockAndroidStudio = MockAndroidStudio();
mockArtifacts = MockLocalEngineArtifacts(); mockArtifacts = MockLocalEngineArtifacts();
mockProcessManager = MockProcessManager(); mockProcessManager = MockProcessManager();
android = fakePlatform('android'); android = fakePlatform('android');
final Directory tempDir = fs.systemTempDirectory.createTempSync('flutter_artifacts_test.'); final Directory rootDirectory = fileSystem.currentDirectory;
cache = Cache(rootOverride: tempDir); cache = Cache(
rootOverride: rootDirectory,
fileSystem: fileSystem,
);
final Directory gradleWrapperDirectory = tempDir final Directory gradleWrapperDirectory = rootDirectory
.childDirectory('bin') .childDirectory('bin')
.childDirectory('cache') .childDirectory('cache')
.childDirectory('artifacts') .childDirectory('artifacts')
...@@ -1098,15 +1101,15 @@ plugin1=${plugin1.path} ...@@ -1098,15 +1101,15 @@ plugin1=${plugin1.path}
environment: anyNamed('environment'))) environment: anyNamed('environment')))
.thenAnswer((_) => Future<Process>.value(process)); .thenAnswer((_) => Future<Process>.value(process));
globals.fs.directory('android') fileSystem.directory('android')
.childFile('build.gradle') .childFile('build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childFile('gradle.properties') .childFile('gradle.properties')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childDirectory('app') .childDirectory('app')
.childFile('build.gradle') .childFile('build.gradle')
..createSync(recursive: true) ..createSync(recursive: true)
...@@ -1160,7 +1163,7 @@ plugin1=${plugin1.path} ...@@ -1160,7 +1163,7 @@ plugin1=${plugin1.path}
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fs, FileSystem: () => fileSystem,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Usage: () => mockUsage, Usage: () => mockUsage,
}); });
...@@ -1177,15 +1180,15 @@ plugin1=${plugin1.path} ...@@ -1177,15 +1180,15 @@ plugin1=${plugin1.path}
return Future<Process>.value(process); return Future<Process>.value(process);
}); });
globals.fs.directory('android') fileSystem.directory('android')
.childFile('build.gradle') .childFile('build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childFile('gradle.properties') .childFile('gradle.properties')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childDirectory('app') .childDirectory('app')
.childFile('build.gradle') .childFile('build.gradle')
..createSync(recursive: true) ..createSync(recursive: true)
...@@ -1241,7 +1244,7 @@ plugin1=${plugin1.path} ...@@ -1241,7 +1244,7 @@ plugin1=${plugin1.path}
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fs, FileSystem: () => fileSystem,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Usage: () => mockUsage, Usage: () => mockUsage,
}); });
...@@ -1252,15 +1255,15 @@ plugin1=${plugin1.path} ...@@ -1252,15 +1255,15 @@ plugin1=${plugin1.path}
environment: anyNamed('environment'))) environment: anyNamed('environment')))
.thenThrow(const ProcessException('', <String>[], 'Some gradle message')); .thenThrow(const ProcessException('', <String>[], 'Some gradle message'));
globals.fs.directory('android') fileSystem.directory('android')
.childFile('build.gradle') .childFile('build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childFile('gradle.properties') .childFile('gradle.properties')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childDirectory('app') .childDirectory('app')
.childFile('build.gradle') .childFile('build.gradle')
..createSync(recursive: true) ..createSync(recursive: true)
...@@ -1314,7 +1317,7 @@ plugin1=${plugin1.path} ...@@ -1314,7 +1317,7 @@ plugin1=${plugin1.path}
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fs, FileSystem: () => fileSystem,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Usage: () => mockUsage, Usage: () => mockUsage,
}); });
...@@ -1325,15 +1328,15 @@ plugin1=${plugin1.path} ...@@ -1325,15 +1328,15 @@ plugin1=${plugin1.path}
environment: anyNamed('environment'))) environment: anyNamed('environment')))
.thenThrow(const ProcessException('', <String>[], 'Unrecognized')); .thenThrow(const ProcessException('', <String>[], 'Unrecognized'));
globals.fs.directory('android') fileSystem.directory('android')
.childFile('build.gradle') .childFile('build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childFile('gradle.properties') .childFile('gradle.properties')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childDirectory('app') .childDirectory('app')
.childFile('build.gradle') .childFile('build.gradle')
..createSync(recursive: true) ..createSync(recursive: true)
...@@ -1359,7 +1362,7 @@ plugin1=${plugin1.path} ...@@ -1359,7 +1362,7 @@ plugin1=${plugin1.path}
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fs, FileSystem: () => fileSystem,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
}); });
...@@ -1385,21 +1388,21 @@ plugin1=${plugin1.path} ...@@ -1385,21 +1388,21 @@ plugin1=${plugin1.path}
return Future<Process>.value(process); return Future<Process>.value(process);
}); });
globals.fs.directory('android') fileSystem.directory('android')
.childFile('build.gradle') .childFile('build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childFile('gradle.properties') .childFile('gradle.properties')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childDirectory('app') .childDirectory('app')
.childFile('build.gradle') .childFile('build.gradle')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync('apply from: irrelevant/flutter.gradle'); ..writeAsStringSync('apply from: irrelevant/flutter.gradle');
globals.fs.directory('build') fileSystem.directory('build')
.childDirectory('app') .childDirectory('app')
.childDirectory('outputs') .childDirectory('outputs')
.childDirectory('apk') .childDirectory('apk')
...@@ -1445,7 +1448,7 @@ plugin1=${plugin1.path} ...@@ -1445,7 +1448,7 @@ plugin1=${plugin1.path}
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
Cache: () => cache, Cache: () => cache,
FileSystem: () => fs, FileSystem: () => fileSystem,
Platform: () => android, Platform: () => android,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Usage: () => mockUsage, Usage: () => mockUsage,
...@@ -1463,15 +1466,15 @@ plugin1=${plugin1.path} ...@@ -1463,15 +1466,15 @@ plugin1=${plugin1.path}
return Future<Process>.value(process); return Future<Process>.value(process);
}); });
globals.fs.directory('android') fileSystem.directory('android')
.childFile('build.gradle') .childFile('build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childFile('gradle.properties') .childFile('gradle.properties')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childDirectory('app') .childDirectory('app')
.childFile('build.gradle') .childFile('build.gradle')
..createSync(recursive: true) ..createSync(recursive: true)
...@@ -1532,7 +1535,7 @@ plugin1=${plugin1.path} ...@@ -1532,7 +1535,7 @@ plugin1=${plugin1.path}
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fs, FileSystem: () => fileSystem,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Usage: () => mockUsage, Usage: () => mockUsage,
}); });
...@@ -1549,21 +1552,21 @@ plugin1=${plugin1.path} ...@@ -1549,21 +1552,21 @@ plugin1=${plugin1.path}
)); ));
}); });
globals.fs.directory('android') fileSystem.directory('android')
.childFile('build.gradle') .childFile('build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childFile('gradle.properties') .childFile('gradle.properties')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childDirectory('app') .childDirectory('app')
.childFile('build.gradle') .childFile('build.gradle')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync('apply from: irrelevant/flutter.gradle'); ..writeAsStringSync('apply from: irrelevant/flutter.gradle');
globals.fs.directory('build') fileSystem.directory('build')
.childDirectory('app') .childDirectory('app')
.childDirectory('outputs') .childDirectory('outputs')
.childDirectory('apk') .childDirectory('apk')
...@@ -1592,13 +1595,13 @@ plugin1=${plugin1.path} ...@@ -1592,13 +1595,13 @@ plugin1=${plugin1.path}
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
AndroidSdk: () => mockAndroidSdk, AndroidSdk: () => mockAndroidSdk,
Cache: () => cache, Cache: () => cache,
FileSystem: () => fs, FileSystem: () => fileSystem,
Platform: () => android, Platform: () => android,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
}); });
testUsingContext('doesn\'t indicate how to consume an AAR when printHowToConsumeAaar is false', () async { testUsingContext('doesn\'t indicate how to consume an AAR when printHowToConsumeAaar is false', () async {
final File manifestFile = globals.fs.file('pubspec.yaml'); final File manifestFile = fileSystem.file('pubspec.yaml');
manifestFile.createSync(recursive: true); manifestFile.createSync(recursive: true);
manifestFile.writeAsStringSync(''' manifestFile.writeAsStringSync('''
flutter: flutter:
...@@ -1607,12 +1610,12 @@ plugin1=${plugin1.path} ...@@ -1607,12 +1610,12 @@ plugin1=${plugin1.path}
''' '''
); );
globals.fs.file('.android/gradlew').createSync(recursive: true); fileSystem.file('.android/gradlew').createSync(recursive: true);
globals.fs.file('.android/gradle.properties') fileSystem.file('.android/gradle.properties')
.writeAsStringSync('irrelevant'); .writeAsStringSync('irrelevant');
globals.fs.file('.android/build.gradle') fileSystem.file('.android/build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
// Let any process start. Assert after. // Let any process start. Assert after.
...@@ -1622,12 +1625,12 @@ plugin1=${plugin1.path} ...@@ -1622,12 +1625,12 @@ plugin1=${plugin1.path}
workingDirectory: anyNamed('workingDirectory'), workingDirectory: anyNamed('workingDirectory'),
)).thenAnswer((_) async => ProcessResult(1, 0, '', '')); )).thenAnswer((_) async => ProcessResult(1, 0, '', ''));
globals.fs.directory('build/outputs/repo').createSync(recursive: true); fileSystem.directory('build/outputs/repo').createSync(recursive: true);
await buildGradleAar( await buildGradleAar(
androidBuildInfo: const AndroidBuildInfo(BuildInfo(BuildMode.release, null)), androidBuildInfo: const AndroidBuildInfo(BuildInfo(BuildMode.release, null)),
project: FlutterProject.current(), project: FlutterProject.current(),
outputDirectory: globals.fs.directory('build/'), outputDirectory: fileSystem.directory('build/'),
target: '', target: '',
buildNumber: '1.0', buildNumber: '1.0',
); );
...@@ -1646,16 +1649,16 @@ plugin1=${plugin1.path} ...@@ -1646,16 +1649,16 @@ plugin1=${plugin1.path}
AndroidStudio: () => mockAndroidStudio, AndroidStudio: () => mockAndroidStudio,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fs, FileSystem: () => fileSystem,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
}); });
testUsingContext('build apk uses selected local engine', () async { testUsingContext('build apk uses selected local engine', () async {
when(mockArtifacts.getArtifactPath(Artifact.flutterFramework, when(mockArtifacts.getArtifactPath(Artifact.flutterFramework,
platform: TargetPlatform.android_arm, mode: anyNamed('mode'))).thenReturn('engine'); platform: TargetPlatform.android_arm, mode: anyNamed('mode'))).thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(globals.fs.path.join('out', 'android_arm')); when(mockArtifacts.engineOutPath).thenReturn(fileSystem.path.join('out', 'android_arm'));
globals.fs.file('out/android_arm/flutter_embedding_release.pom') fileSystem.file('out/android_arm/flutter_embedding_release.pom')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync( ..writeAsStringSync(
'''<?xml version="1.0" encoding="UTF-8"?> '''<?xml version="1.0" encoding="UTF-8"?>
...@@ -1665,21 +1668,21 @@ plugin1=${plugin1.path} ...@@ -1665,21 +1668,21 @@ plugin1=${plugin1.path}
</dependencies> </dependencies>
</project> </project>
'''); ''');
globals.fs.file('out/android_arm/armeabi_v7a_release.pom').createSync(recursive: true); fileSystem.file('out/android_arm/armeabi_v7a_release.pom').createSync(recursive: true);
globals.fs.file('out/android_arm/armeabi_v7a_release.jar').createSync(recursive: true); fileSystem.file('out/android_arm/armeabi_v7a_release.jar').createSync(recursive: true);
globals.fs.file('out/android_arm/flutter_embedding_release.jar').createSync(recursive: true); fileSystem.file('out/android_arm/flutter_embedding_release.jar').createSync(recursive: true);
globals.fs.file('out/android_arm/flutter_embedding_release.pom').createSync(recursive: true); fileSystem.file('out/android_arm/flutter_embedding_release.pom').createSync(recursive: true);
globals.fs.file('android/gradlew').createSync(recursive: true); fileSystem.file('android/gradlew').createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childFile('gradle.properties') .childFile('gradle.properties')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.file('android/build.gradle') fileSystem.file('android/build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
globals.fs.directory('android') fileSystem.directory('android')
.childDirectory('app') .childDirectory('app')
.childFile('build.gradle') .childFile('build.gradle')
..createSync(recursive: true) ..createSync(recursive: true)
...@@ -1737,16 +1740,16 @@ plugin1=${plugin1.path} ...@@ -1737,16 +1740,16 @@ plugin1=${plugin1.path}
Artifacts: () => mockArtifacts, Artifacts: () => mockArtifacts,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fs, FileSystem: () => fileSystem,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
}); });
testUsingContext('build aar uses selected local engine', () async { testUsingContext('build aar uses selected local engine', () async {
when(mockArtifacts.getArtifactPath(Artifact.flutterFramework, when(mockArtifacts.getArtifactPath(Artifact.flutterFramework,
platform: TargetPlatform.android_arm, mode: anyNamed('mode'))).thenReturn('engine'); platform: TargetPlatform.android_arm, mode: anyNamed('mode'))).thenReturn('engine');
when(mockArtifacts.engineOutPath).thenReturn(globals.fs.path.join('out', 'android_arm')); when(mockArtifacts.engineOutPath).thenReturn(fileSystem.path.join('out', 'android_arm'));
globals.fs.file('out/android_arm/flutter_embedding_release.pom') fileSystem.file('out/android_arm/flutter_embedding_release.pom')
..createSync(recursive: true) ..createSync(recursive: true)
..writeAsStringSync( ..writeAsStringSync(
'''<?xml version="1.0" encoding="UTF-8"?> '''<?xml version="1.0" encoding="UTF-8"?>
...@@ -1756,12 +1759,12 @@ plugin1=${plugin1.path} ...@@ -1756,12 +1759,12 @@ plugin1=${plugin1.path}
</dependencies> </dependencies>
</project> </project>
'''); ''');
globals.fs.file('out/android_arm/armeabi_v7a_release.pom').createSync(recursive: true); fileSystem.file('out/android_arm/armeabi_v7a_release.pom').createSync(recursive: true);
globals.fs.file('out/android_arm/armeabi_v7a_release.jar').createSync(recursive: true); fileSystem.file('out/android_arm/armeabi_v7a_release.jar').createSync(recursive: true);
globals.fs.file('out/android_arm/flutter_embedding_release.jar').createSync(recursive: true); fileSystem.file('out/android_arm/flutter_embedding_release.jar').createSync(recursive: true);
globals.fs.file('out/android_arm/flutter_embedding_release.pom').createSync(recursive: true); fileSystem.file('out/android_arm/flutter_embedding_release.pom').createSync(recursive: true);
final File manifestFile = globals.fs.file('pubspec.yaml'); final File manifestFile = fileSystem.file('pubspec.yaml');
manifestFile.createSync(recursive: true); manifestFile.createSync(recursive: true);
manifestFile.writeAsStringSync(''' manifestFile.writeAsStringSync('''
flutter: flutter:
...@@ -1770,12 +1773,12 @@ plugin1=${plugin1.path} ...@@ -1770,12 +1773,12 @@ plugin1=${plugin1.path}
''' '''
); );
globals.fs.file('.android/gradlew').createSync(recursive: true); fileSystem.file('.android/gradlew').createSync(recursive: true);
globals.fs.file('.android/gradle.properties') fileSystem.file('.android/gradle.properties')
.writeAsStringSync('irrelevant'); .writeAsStringSync('irrelevant');
globals.fs.file('.android/build.gradle') fileSystem.file('.android/build.gradle')
.createSync(recursive: true); .createSync(recursive: true);
// Let any process start. Assert after. // Let any process start. Assert after.
...@@ -1785,12 +1788,12 @@ plugin1=${plugin1.path} ...@@ -1785,12 +1788,12 @@ plugin1=${plugin1.path}
workingDirectory: anyNamed('workingDirectory'), workingDirectory: anyNamed('workingDirectory'),
)).thenAnswer((_) async => ProcessResult(1, 0, '', '')); )).thenAnswer((_) async => ProcessResult(1, 0, '', ''));
globals.fs.directory('build/outputs/repo').createSync(recursive: true); fileSystem.directory('build/outputs/repo').createSync(recursive: true);
await buildGradleAar( await buildGradleAar(
androidBuildInfo: const AndroidBuildInfo(BuildInfo(BuildMode.release, null)), androidBuildInfo: const AndroidBuildInfo(BuildInfo(BuildMode.release, null)),
project: FlutterProject.current(), project: FlutterProject.current(),
outputDirectory: globals.fs.directory('build/'), outputDirectory: fileSystem.directory('build/'),
target: '', target: '',
buildNumber: '2.0', buildNumber: '2.0',
); );
...@@ -1815,7 +1818,7 @@ plugin1=${plugin1.path} ...@@ -1815,7 +1818,7 @@ plugin1=${plugin1.path}
Artifacts: () => mockArtifacts, Artifacts: () => mockArtifacts,
Cache: () => cache, Cache: () => cache,
Platform: () => android, Platform: () => android,
FileSystem: () => fs, FileSystem: () => fileSystem,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
}); });
}); });
......
...@@ -3,55 +3,57 @@ ...@@ -3,55 +3,57 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/logger.dart';
import 'package:flutter_tools/src/base/os.dart';
import 'package:mockito/mockito.dart';
import 'package:platform/platform.dart'; import 'package:platform/platform.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';
import 'package:flutter_tools/src/build_info.dart'; import 'package:flutter_tools/src/build_info.dart';
import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/cache.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import '../src/common.dart'; import '../src/common.dart';
import '../src/context.dart'; import '../src/context.dart';
void main() { void main() {
group('Artifacts', () {
MemoryFileSystem memoryFileSystem;
Directory tempDir;
setUp(() {
memoryFileSystem = MemoryFileSystem();
tempDir = memoryFileSystem.systemTempDirectory.createTempSync('flutter_artifacts_test.');
});
tearDown(() {
tryToDelete(tempDir);
});
group('CachedArtifacts', () { group('CachedArtifacts', () {
CachedArtifacts artifacts; CachedArtifacts artifacts;
Cache cache;
FileSystem fileSystem;
Platform platform;
setUp(() { setUp(() {
artifacts = CachedArtifacts(); fileSystem = MemoryFileSystem();
final Directory cacheRoot = fileSystem.directory('root')
..createSync();
platform = FakePlatform(operatingSystem: 'linux');
cache = Cache(
rootOverride: cacheRoot,
fileSystem: fileSystem,
platform: platform,
logger: MockLogger(),
osUtils: MockOperatingSystemUtils(),
);
artifacts = CachedArtifacts(
fileSystem: fileSystem,
cache: cache,
platform: platform,
);
}); });
testUsingContext('getArtifactPath', () { testWithoutContext('getArtifactPath', () {
expect( expect(
artifacts.getArtifactPath(Artifact.flutterFramework, platform: TargetPlatform.ios, mode: BuildMode.release), artifacts.getArtifactPath(Artifact.flutterFramework, platform: TargetPlatform.ios, mode: BuildMode.release),
globals.fs.path.join(tempDir.path, 'bin', 'cache', 'artifacts', 'engine', 'ios-release', 'Flutter.framework'), fileSystem.path.join('root', 'bin', 'cache', 'artifacts', 'engine', 'ios-release', 'Flutter.framework'),
); );
expect( expect(
artifacts.getArtifactPath(Artifact.flutterTester), artifacts.getArtifactPath(Artifact.flutterTester),
globals.fs.path.join(tempDir.path, 'bin', 'cache', 'artifacts', 'engine', 'linux-x64', 'flutter_tester'), fileSystem.path.join('root', 'bin', 'cache', 'artifacts', 'engine', 'linux-x64', 'flutter_tester'),
); );
}, overrides: <Type, Generator>{
Cache: () => Cache(rootOverride: tempDir),
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'linux'),
}); });
testUsingContext('getEngineType', () { testWithoutContext('getEngineType', () {
expect( expect(
artifacts.getEngineType(TargetPlatform.android_arm, BuildMode.debug), artifacts.getEngineType(TargetPlatform.android_arm, BuildMode.debug),
'android-arm', 'android-arm',
...@@ -64,44 +66,53 @@ void main() { ...@@ -64,44 +66,53 @@ void main() {
artifacts.getEngineType(TargetPlatform.darwin_x64), artifacts.getEngineType(TargetPlatform.darwin_x64),
'darwin-x64', 'darwin-x64',
); );
}, overrides: <Type, Generator>{
Cache: () => Cache(rootOverride: tempDir),
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'linux'),
}); });
}); });
group('LocalEngineArtifacts', () { group('LocalEngineArtifacts', () {
LocalEngineArtifacts artifacts; LocalEngineArtifacts artifacts;
Cache cache;
FileSystem fileSystem;
Platform platform;
setUp(() { setUp(() {
artifacts = LocalEngineArtifacts(tempDir.path, fileSystem = MemoryFileSystem();
memoryFileSystem.path.join(tempDir.path, 'out', 'android_debug_unopt'), final Directory cacheRoot = fileSystem.directory('root')
memoryFileSystem.path.join(tempDir.path, 'out', 'host_debug_unopt'), ..createSync();
platform = FakePlatform(operatingSystem: 'linux');
cache = Cache(
rootOverride: cacheRoot,
fileSystem: fileSystem,
platform: platform,
logger: MockLogger(),
osUtils: MockOperatingSystemUtils(),
);
artifacts = LocalEngineArtifacts(fileSystem.currentDirectory.path,
fileSystem.path.join(fileSystem.currentDirectory.path, 'out', 'android_debug_unopt'),
fileSystem.path.join(fileSystem.currentDirectory.path, 'out', 'host_debug_unopt'),
cache: cache,
fileSystem: fileSystem,
platform: platform,
processManager: FakeProcessManager.any(),
); );
}); });
testUsingContext('getArtifactPath', () { testWithoutContext('getArtifactPath', () {
expect( expect(
artifacts.getArtifactPath(Artifact.flutterFramework, platform: TargetPlatform.ios, mode: BuildMode.release), artifacts.getArtifactPath(Artifact.flutterFramework, platform: TargetPlatform.ios, mode: BuildMode.release),
globals.fs.path.join(tempDir.path, 'out', 'android_debug_unopt', 'Flutter.framework'), fileSystem.path.join('/out', 'android_debug_unopt', 'Flutter.framework'),
); );
expect( expect(
artifacts.getArtifactPath(Artifact.flutterTester), artifacts.getArtifactPath(Artifact.flutterTester),
globals.fs.path.join(tempDir.path, 'out', 'android_debug_unopt', 'flutter_tester'), fileSystem.path.join('/out', 'android_debug_unopt', 'flutter_tester'),
); );
expect( expect(
artifacts.getArtifactPath(Artifact.engineDartSdkPath), artifacts.getArtifactPath(Artifact.engineDartSdkPath),
globals.fs.path.join(tempDir.path, 'out', 'host_debug_unopt', 'dart-sdk'), fileSystem.path.join('/out', 'host_debug_unopt', 'dart-sdk'),
); );
}, overrides: <Type, Generator>{
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'linux'),
}); });
testUsingContext('getEngineType', () { testWithoutContext('getEngineType', () {
expect( expect(
artifacts.getEngineType(TargetPlatform.android_arm, BuildMode.debug), artifacts.getEngineType(TargetPlatform.android_arm, BuildMode.debug),
'android_debug_unopt', 'android_debug_unopt',
...@@ -114,27 +125,26 @@ void main() { ...@@ -114,27 +125,26 @@ void main() {
artifacts.getEngineType(TargetPlatform.darwin_x64), artifacts.getEngineType(TargetPlatform.darwin_x64),
'android_debug_unopt', 'android_debug_unopt',
); );
}, overrides: <Type, Generator>{
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'linux'),
}); });
testUsingContext('Looks up dart.exe on windows platforms', () async { testWithoutContext('Looks up dart.exe on windows platforms', () async {
artifacts = LocalEngineArtifacts(fileSystem.currentDirectory.path,
fileSystem.path.join(fileSystem.currentDirectory.path, 'out', 'android_debug_unopt'),
fileSystem.path.join(fileSystem.currentDirectory.path, 'out', 'host_debug_unopt'),
cache: cache,
fileSystem: fileSystem,
platform: FakePlatform(operatingSystem: 'windows'),
processManager: FakeProcessManager.any(),
);
expect(artifacts.getArtifactPath(Artifact.engineDartBinary), contains('.exe')); expect(artifacts.getArtifactPath(Artifact.engineDartBinary), contains('.exe'));
}, overrides: <Type, Generator>{
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'windows'),
}); });
testUsingContext('Looks up dart on linux platforms', () async { testWithoutContext('Looks up dart on linux platforms', () async {
expect(artifacts.getArtifactPath(Artifact.engineDartBinary), isNot(contains('.exe'))); expect(artifacts.getArtifactPath(Artifact.engineDartBinary), isNot(contains('.exe')));
}, overrides: <Type, Generator>{
FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(),
Platform: () => FakePlatform(operatingSystem: 'linux'),
});
}); });
}); });
} }
class MockLogger extends Mock implements Logger {}
class MockOperatingSystemUtils extends Mock implements OperatingSystemUtils {}
...@@ -12,6 +12,7 @@ import 'package:flutter_tools/src/ios/plist_parser.dart'; ...@@ -12,6 +12,7 @@ import 'package:flutter_tools/src/ios/plist_parser.dart';
import 'package:flutter_tools/src/macos/xcode.dart'; import 'package:flutter_tools/src/macos/xcode.dart';
import 'package:mockito/mockito.dart'; import 'package:mockito/mockito.dart';
import 'package:process/process.dart'; import 'package:process/process.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import '../../src/common.dart'; import '../../src/common.dart';
import '../../src/context.dart'; import '../../src/context.dart';
...@@ -36,7 +37,12 @@ void main() { ...@@ -36,7 +37,12 @@ void main() {
equals('Flutter.framework not found at ios_profile/Flutter.framework'), equals('Flutter.framework not found at ios_profile/Flutter.framework'),
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => LocalEngineArtifacts('/engine', 'ios_profile', 'host_profile'), Artifacts: () => LocalEngineArtifacts('/engine', 'ios_profile', 'host_profile',
fileSystem: memoryFileSystem,
cache: globals.cache,
platform: globals.platform,
processManager: mockProcessManager,
),
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => FakeProcessManager.any(), ProcessManager: () => FakeProcessManager.any(),
}); });
...@@ -60,7 +66,12 @@ void main() { ...@@ -60,7 +66,12 @@ void main() {
'Expected a string like "Apple (LLVM|clang) #.#.# (clang-####.#.##.#)".'), 'Expected a string like "Apple (LLVM|clang) #.#.# (clang-####.#.##.#)".'),
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => LocalEngineArtifacts('/engine', 'ios_profile', 'host_profile'), Artifacts: () => LocalEngineArtifacts('/engine', 'ios_profile', 'host_profile',
fileSystem: memoryFileSystem,
cache: globals.cache,
platform: globals.platform,
processManager: mockProcessManager,
),
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Xcode: () => mockXcode, Xcode: () => mockXcode,
...@@ -83,7 +94,12 @@ void main() { ...@@ -83,7 +94,12 @@ void main() {
await validateBitcode(BuildMode.profile, TargetPlatform.ios); await validateBitcode(BuildMode.profile, TargetPlatform.ios);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => LocalEngineArtifacts('/engine', 'ios_profile', 'host_profile'), Artifacts: () => LocalEngineArtifacts('/engine', 'ios_profile', 'host_profile',
fileSystem: memoryFileSystem,
cache: globals.cache,
platform: globals.platform,
processManager: mockProcessManager,
),
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Xcode: () => mockXcode, Xcode: () => mockXcode,
...@@ -105,7 +121,12 @@ void main() { ...@@ -105,7 +121,12 @@ void main() {
await validateBitcode(BuildMode.profile, TargetPlatform.ios); await validateBitcode(BuildMode.profile, TargetPlatform.ios);
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => LocalEngineArtifacts('/engine', 'ios_profile', 'host_profile'), Artifacts: () => LocalEngineArtifacts('/engine', 'ios_profile', 'host_profile',
fileSystem: memoryFileSystem,
cache: globals.cache,
platform: globals.platform,
processManager: mockProcessManager,
),
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Xcode: () => mockXcode, Xcode: () => mockXcode,
...@@ -133,7 +154,12 @@ void main() { ...@@ -133,7 +154,12 @@ void main() {
'of Xcode to at least 10.0.1.'), 'of Xcode to at least 10.0.1.'),
); );
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => LocalEngineArtifacts('/engine', 'ios_profile', 'host_profile'), Artifacts: () => LocalEngineArtifacts('/engine', 'ios_profile', 'host_profile',
fileSystem: memoryFileSystem,
cache: globals.cache,
platform: globals.platform,
processManager: mockProcessManager,
),
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Xcode: () => mockXcode, Xcode: () => mockXcode,
...@@ -157,7 +183,12 @@ void main() { ...@@ -157,7 +183,12 @@ void main() {
expect(testLogger.statusText, ''); expect(testLogger.statusText, '');
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => LocalEngineArtifacts('/engine', 'ios_profile', 'host_profile'), Artifacts: () => LocalEngineArtifacts('/engine', 'ios_profile', 'host_profile',
fileSystem: memoryFileSystem,
cache: globals.cache,
platform: globals.platform,
processManager: mockProcessManager,
),
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Xcode: () => mockXcode, Xcode: () => mockXcode,
...@@ -181,7 +212,12 @@ void main() { ...@@ -181,7 +212,12 @@ void main() {
expect(testLogger.statusText, ''); expect(testLogger.statusText, '');
}, overrides: <Type, Generator>{ }, overrides: <Type, Generator>{
Artifacts: () => LocalEngineArtifacts('/engine', 'ios_profile', 'host_profile'), Artifacts: () => LocalEngineArtifacts('/engine', 'ios_profile', 'host_profile',
fileSystem: memoryFileSystem,
cache: globals.cache,
platform: globals.platform,
processManager: mockProcessManager,
),
FileSystem: () => memoryFileSystem, FileSystem: () => memoryFileSystem,
ProcessManager: () => mockProcessManager, ProcessManager: () => mockProcessManager,
Xcode: () => mockXcode, Xcode: () => mockXcode,
......
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