From e91822da24c013aa6f21d03ed3af3587923d9fd2 Mon Sep 17 00:00:00 2001 From: Christopher Fujino Date: Fri, 12 Jul 2019 09:03:34 -0700 Subject: [PATCH] Revert "Bundle ios dependencies (#34669)" (#36071) This reverts commit 14d489adc5d584490595790ca0deb29da7ee4470. --- .cirrus.yml | 4 +- bin/internal/ideviceinstaller.version | 1 - bin/internal/ios-deploy.version | 1 - bin/internal/libimobiledevice.version | 1 - bin/internal/libplist.version | 1 - bin/internal/openssl.version | 1 - bin/internal/usbmuxd.version | 1 - dev/devicelab/lib/framework/adb.dart | 27 +-- packages/flutter_tools/lib/src/artifacts.dart | 82 ++------ .../flutter_tools/lib/src/base/process.dart | 14 +- .../lib/src/base/user_messages.dart | 41 ++++ packages/flutter_tools/lib/src/cache.dart | 57 +----- .../flutter_tools/lib/src/context_runner.dart | 3 +- packages/flutter_tools/lib/src/doctor.dart | 2 + .../flutter_tools/lib/src/ios/devices.dart | 64 +++---- .../lib/src/ios/ios_workflow.dart | 91 +++++++++ packages/flutter_tools/lib/src/ios/mac.dart | 127 ++----------- .../lib/src/macos/cocoapods.dart | 4 +- .../lib/src/macos/cocoapods_validator.dart | 10 +- packages/flutter_tools/test/cache_test.dart | 16 -- .../test/ios/code_signing_test.dart | 2 +- .../test/ios/ios_workflow_test.dart | 178 ++++++++++++++++++ packages/flutter_tools/test/ios/mac_test.dart | 73 ++----- .../test/macos/cocoapods_validator_test.dart | 27 ++- 24 files changed, 431 insertions(+), 397 deletions(-) delete mode 100644 bin/internal/ideviceinstaller.version delete mode 100644 bin/internal/ios-deploy.version delete mode 100644 bin/internal/libimobiledevice.version delete mode 100644 bin/internal/libplist.version delete mode 100644 bin/internal/openssl.version delete mode 100644 bin/internal/usbmuxd.version create mode 100644 packages/flutter_tools/test/ios/ios_workflow_test.dart diff --git a/.cirrus.yml b/.cirrus.yml index 6674fcc1d8..204112cec3 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -21,7 +21,7 @@ task: fingerprint_script: echo $OS; cat bin/internal/engine.version artifacts_cache: folder: bin/cache/artifacts - fingerprint_script: echo $OS; cat bin/internal/*.version + fingerprint_script: echo $OS; cat bin/internal/engine.version setup_script: ./dev/bots/cirrus_setup.sh matrix: - name: docs @@ -298,7 +298,7 @@ task: fingerprint_script: echo %OS% & type bin\internal\engine.version artifacts_cache: folder: bin\cache\artifacts - fingerprint_script: echo %OS% & type bin\internal\*.version + fingerprint_script: echo %OS% & type bin\internal\engine.version setup_script: - flutter config --no-analytics - flutter doctor -v diff --git a/bin/internal/ideviceinstaller.version b/bin/internal/ideviceinstaller.version deleted file mode 100644 index 90f1492fb9..0000000000 --- a/bin/internal/ideviceinstaller.version +++ /dev/null @@ -1 +0,0 @@ -ab9352110092cf651b5602301371cd00691c7e13 diff --git a/bin/internal/ios-deploy.version b/bin/internal/ios-deploy.version deleted file mode 100644 index 768361896d..0000000000 --- a/bin/internal/ios-deploy.version +++ /dev/null @@ -1 +0,0 @@ -ea5583388ac0ca035f6b991fd7955bea6492c68c diff --git a/bin/internal/libimobiledevice.version b/bin/internal/libimobiledevice.version deleted file mode 100644 index 0fc801bd3c..0000000000 --- a/bin/internal/libimobiledevice.version +++ /dev/null @@ -1 +0,0 @@ -398c1208731cb887c64a31c2ae111048b079f80d diff --git a/bin/internal/libplist.version b/bin/internal/libplist.version deleted file mode 100644 index 973064be2b..0000000000 --- a/bin/internal/libplist.version +++ /dev/null @@ -1 +0,0 @@ -17546f53ac1377b0d4f45a800aaec7366ba5b6a0 diff --git a/bin/internal/openssl.version b/bin/internal/openssl.version deleted file mode 100644 index 400e36a8e9..0000000000 --- a/bin/internal/openssl.version +++ /dev/null @@ -1 +0,0 @@ -03da376ff7504c63a1d00d57cf41bd7b7e93ff65 diff --git a/bin/internal/usbmuxd.version b/bin/internal/usbmuxd.version deleted file mode 100644 index d77b5cf4e9..0000000000 --- a/bin/internal/usbmuxd.version +++ /dev/null @@ -1 +0,0 @@ -60109fdef47dfe0badfb558a6a2105e8fb23660a diff --git a/dev/devicelab/lib/framework/adb.dart b/dev/devicelab/lib/framework/adb.dart index f6db339c35..e6765c6ab2 100644 --- a/dev/devicelab/lib/framework/adb.dart +++ b/dev/devicelab/lib/framework/adb.dart @@ -392,34 +392,9 @@ class IosDeviceDiscovery implements DeviceDiscovery { _workingDevice = allDevices[math.Random().nextInt(allDevices.length)]; } - // Returns the path to cached binaries relative to devicelab directory - String get _artifactDirPath { - return path.normalize( - path.join( - path.current, - '../../bin/cache/artifacts', - ) - ); - } - - // Returns a colon-separated environment variable that contains the paths - // of linked libraries for idevice_id - Map get _ideviceIdEnvironment { - final String libPath = const [ - 'libimobiledevice', - 'usbmuxd', - 'libplist', - 'openssl', - 'ideviceinstaller', - 'ios-deploy', - ].map((String packageName) => path.join(_artifactDirPath, packageName)).join(':'); - return {'DYLD_LIBRARY_PATH': libPath}; - } - @override Future> discoverDevices() async { - final String ideviceIdPath = path.join(_artifactDirPath, 'libimobiledevice', 'idevice_id'); - final List iosDeviceIDs = LineSplitter.split(await eval(ideviceIdPath, ['-l'], environment: _ideviceIdEnvironment)) + final List iosDeviceIDs = LineSplitter.split(await eval('idevice_id', ['-l'])) .map((String line) => line.trim()) .where((String line) => line.isNotEmpty) .toList(); diff --git a/packages/flutter_tools/lib/src/artifacts.dart b/packages/flutter_tools/lib/src/artifacts.dart index 191fd15671..65a8b630f6 100644 --- a/packages/flutter_tools/lib/src/artifacts.dart +++ b/packages/flutter_tools/lib/src/artifacts.dart @@ -40,14 +40,6 @@ enum Artifact { kernelWorkerSnapshot, /// The root of the web implementation of the dart SDK. flutterWebSdk, - iosDeploy, - ideviceinfo, - ideviceId, - idevicename, - idevicesyslog, - idevicescreenshot, - ideviceinstaller, - iproxy, /// The root of the Linux desktop sources. linuxDesktopPath, /// The root of the Windows desktop sources. @@ -101,22 +93,6 @@ String _artifactToFileName(Artifact artifact, [ TargetPlatform platform, BuildMo return 'dartdevc.dart.snapshot'; case Artifact.kernelWorkerSnapshot: return 'kernel_worker.dart.snapshot'; - case Artifact.iosDeploy: - return 'ios-deploy'; - case Artifact.ideviceinfo: - return 'ideviceinfo'; - case Artifact.ideviceId: - return 'idevice_id'; - case Artifact.idevicename: - return 'idevicename'; - case Artifact.idevicesyslog: - return 'idevicesyslog'; - case Artifact.idevicescreenshot: - return 'idevicescreenshot'; - case Artifact.ideviceinstaller: - return 'ideviceinstaller'; - case Artifact.iproxy: - return 'iproxy'; case Artifact.linuxDesktopPath: if (platform != TargetPlatform.linux_x64) { throw Exception('${getNameForTargetPlatform(platform)} does not support' @@ -211,26 +187,13 @@ class CachedArtifacts extends Artifacts { } String _getIosArtifactPath(Artifact artifact, TargetPlatform platform, BuildMode mode) { - final String artifactFileName = _artifactToFileName(artifact); + final String engineDir = _getEngineArtifactsPath(platform, mode); switch (artifact) { case Artifact.genSnapshot: case Artifact.snapshotDart: case Artifact.flutterFramework: case Artifact.frontendServerSnapshotForEngineDartSdk: - final String engineDir = _getEngineArtifactsPath(platform, mode); - return fs.path.join(engineDir, artifactFileName); - case Artifact.ideviceId: - case Artifact.ideviceinfo: - case Artifact.idevicescreenshot: - case Artifact.idevicesyslog: - case Artifact.idevicename: - return cache.getArtifactDirectory('libimobiledevice').childFile(artifactFileName).path; - case Artifact.iosDeploy: - return cache.getArtifactDirectory('ios-deploy').childFile(artifactFileName).path; - case Artifact.ideviceinstaller: - return cache.getArtifactDirectory('ideviceinstaller').childFile(artifactFileName).path; - case Artifact.iproxy: - return cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName).path; + return fs.path.join(engineDir, _artifactToFileName(artifact)); default: assert(false, 'Artifact $artifact not available for platform $platform.'); return null; @@ -339,25 +302,24 @@ class LocalEngineArtifacts extends Artifacts { @override String getArtifactPath(Artifact artifact, { TargetPlatform platform, BuildMode mode }) { - final String artifactFileName = _artifactToFileName(artifact); switch (artifact) { case Artifact.snapshotDart: - return fs.path.join(_engineSrcPath, 'flutter', 'lib', 'snapshot', artifactFileName); + return fs.path.join(_engineSrcPath, 'flutter', 'lib', 'snapshot', _artifactToFileName(artifact)); case Artifact.genSnapshot: return _genSnapshotPath(); case Artifact.flutterTester: return _flutterTesterPath(platform); case Artifact.isolateSnapshotData: case Artifact.vmSnapshotData: - return fs.path.join(engineOutPath, 'gen', 'flutter', 'lib', 'snapshot', artifactFileName); + return fs.path.join(engineOutPath, 'gen', 'flutter', 'lib', 'snapshot', _artifactToFileName(artifact)); case Artifact.platformKernelDill: - return fs.path.join(_getFlutterPatchedSdkPath(mode), artifactFileName); + return fs.path.join(_getFlutterPatchedSdkPath(mode), _artifactToFileName(artifact)); case Artifact.platformLibrariesJson: - return fs.path.join(_getFlutterPatchedSdkPath(mode), 'lib', artifactFileName); + return fs.path.join(_getFlutterPatchedSdkPath(mode), 'lib', _artifactToFileName(artifact)); case Artifact.flutterFramework: - return fs.path.join(engineOutPath, artifactFileName); + return fs.path.join(engineOutPath, _artifactToFileName(artifact)); case Artifact.flutterMacOSFramework: - return fs.path.join(engineOutPath, artifactFileName); + return fs.path.join(engineOutPath, _artifactToFileName(artifact)); case Artifact.flutterPatchedSdkPath: // When using local engine always use [BuildMode.debug] regardless of // what was specified in [mode] argument because local engine will @@ -367,35 +329,23 @@ class LocalEngineArtifacts extends Artifacts { case Artifact.flutterWebSdk: return _getFlutterWebSdkPath(); case Artifact.frontendServerSnapshotForEngineDartSdk: - return fs.path.join(_hostEngineOutPath, 'gen', artifactFileName); + return fs.path.join(_hostEngineOutPath, 'gen', _artifactToFileName(artifact)); case Artifact.engineDartSdkPath: return fs.path.join(_hostEngineOutPath, 'dart-sdk'); case Artifact.engineDartBinary: - return fs.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', artifactFileName); + return fs.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', _artifactToFileName(artifact)); case Artifact.dart2jsSnapshot: - return fs.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', 'snapshots', artifactFileName); + return fs.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', 'snapshots', _artifactToFileName(artifact)); case Artifact.dartdevcSnapshot: - return fs.path.join(dartSdkPath, 'bin', 'snapshots', artifactFileName); + return fs.path.join(dartSdkPath, 'bin', 'snapshots', _artifactToFileName(artifact)); case Artifact.kernelWorkerSnapshot: - return fs.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', 'snapshots', artifactFileName); - case Artifact.ideviceId: - case Artifact.ideviceinfo: - case Artifact.idevicename: - case Artifact.idevicescreenshot: - case Artifact.idevicesyslog: - return cache.getArtifactDirectory('libimobiledevice').childFile(artifactFileName).path; - case Artifact.ideviceinstaller: - return cache.getArtifactDirectory('ideviceinstaller').childFile(artifactFileName).path; - case Artifact.iosDeploy: - return cache.getArtifactDirectory('ios-deploy').childFile(artifactFileName).path; - case Artifact.iproxy: - return cache.getArtifactDirectory('usbmuxd').childFile(artifactFileName).path; + return fs.path.join(_hostEngineOutPath, 'dart-sdk', 'bin', 'snapshots', _artifactToFileName(artifact)); case Artifact.linuxDesktopPath: - return fs.path.join(_hostEngineOutPath, artifactFileName); + return fs.path.join(_hostEngineOutPath, _artifactToFileName(artifact)); case Artifact.windowsDesktopPath: - return fs.path.join(_hostEngineOutPath, artifactFileName); + return fs.path.join(_hostEngineOutPath, _artifactToFileName(artifact)); case Artifact.skyEnginePath: - return fs.path.join(_hostEngineOutPath, 'gen', 'dart-pkg', artifactFileName); + return fs.path.join(_hostEngineOutPath, 'gen', 'dart-pkg', _artifactToFileName(artifact)); } assert(false, 'Invalid artifact $artifact.'); return null; diff --git a/packages/flutter_tools/lib/src/base/process.dart b/packages/flutter_tools/lib/src/base/process.dart index 1dd5765821..47b2949a17 100644 --- a/packages/flutter_tools/lib/src/base/process.dart +++ b/packages/flutter_tools/lib/src/base/process.dart @@ -263,26 +263,20 @@ Future runCheckedAsync( return result; } -bool exitsHappy( - List cli, { - Map environment, -}) { +bool exitsHappy(List cli) { _traceCommand(cli); try { - return processManager.runSync(cli, environment: environment).exitCode == 0; + return processManager.runSync(cli).exitCode == 0; } catch (error) { printTrace('$cli failed with $error'); return false; } } -Future exitsHappyAsync( - List cli, { - Map environment, -}) async { +Future exitsHappyAsync(List cli) async { _traceCommand(cli); try { - return (await processManager.run(cli, environment: environment)).exitCode == 0; + return (await processManager.run(cli)).exitCode == 0; } catch (error) { printTrace('$cli failed with $error'); return false; diff --git a/packages/flutter_tools/lib/src/base/user_messages.dart b/packages/flutter_tools/lib/src/base/user_messages.dart index 0f359b58be..09af158d94 100644 --- a/packages/flutter_tools/lib/src/base/user_messages.dart +++ b/packages/flutter_tools/lib/src/base/user_messages.dart @@ -145,6 +145,44 @@ class UserMessages { 'Once installed, run:\n' ' sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer'; + // Messages used in IOSValidator + String get iOSIMobileDeviceMissing => + 'libimobiledevice and ideviceinstaller are not installed. To install with Brew, run:\n' + ' brew update\n' + ' brew install --HEAD usbmuxd\n' + ' brew link usbmuxd\n' + ' brew install --HEAD libimobiledevice\n' + ' brew install ideviceinstaller'; + String get iOSIMobileDeviceBroken => + 'Verify that all connected devices have been paired with this computer in Xcode.\n' + 'If all devices have been paired, libimobiledevice and ideviceinstaller may require updating.\n' + 'To update with Brew, run:\n' + ' brew update\n' + ' brew uninstall --ignore-dependencies libimobiledevice\n' + ' brew uninstall --ignore-dependencies usbmuxd\n' + ' brew install --HEAD usbmuxd\n' + ' brew unlink usbmuxd\n' + ' brew link usbmuxd\n' + ' brew install --HEAD libimobiledevice\n' + ' brew install ideviceinstaller'; + String get iOSDeviceInstallerMissing => + 'ideviceinstaller is not installed; this is used to discover connected iOS devices.\n' + 'To install with Brew, run:\n' + ' brew install --HEAD usbmuxd\n' + ' brew link usbmuxd\n' + ' brew install --HEAD libimobiledevice\n' + ' brew install ideviceinstaller'; + String iOSDeployVersion(String version) => 'ios-deploy $version'; + String iOSDeployOutdated(String minVersion) => + 'ios-deploy out of date ($minVersion is required). To upgrade with Brew:\n' + ' brew upgrade ios-deploy'; + String get iOSDeployMissing => + 'ios-deploy not installed. To install:\n' + ' brew install ios-deploy'; + String get iOSBrewMissing => + 'Brew can be used to install tools for iOS device development.\n' + 'Download brew at https://brew.sh/.'; + // Messages used in CocoaPodsValidator String cocoaPodsVersion(String version) => 'CocoaPods version $version'; String cocoaPodsUninitialized(String consequence) => @@ -168,6 +206,9 @@ class UserMessages { '$consequence\n' 'To upgrade:\n' '$upgradeInstructions'; + String get cocoaPodsBrewMissing => + 'Brew can be used to install CocoaPods.\n' + 'Download brew at https://brew.sh/.'; // Messages used in VsCodeValidator String vsCodeVersion(String version) => 'version $version'; diff --git a/packages/flutter_tools/lib/src/cache.dart b/packages/flutter_tools/lib/src/cache.dart index 3a6039d85b..6d2d13e023 100644 --- a/packages/flutter_tools/lib/src/cache.dart +++ b/packages/flutter_tools/lib/src/cache.dart @@ -53,7 +53,7 @@ class DevelopmentArtifact { /// Artifacts required by all developments. static const DevelopmentArtifact universal = DevelopmentArtifact._('universal'); - /// The values of DevelopmentArtifacts. + /// The vaulues of DevelopmentArtifacts. static final List values = [ android, iOS, @@ -83,9 +83,6 @@ class Cache { _artifacts.add(LinuxEngineArtifacts(this)); _artifacts.add(LinuxFuchsiaSDKArtifacts(this)); _artifacts.add(MacOSFuchsiaSDKArtifacts(this)); - for (String artifactName in IosUsbArtifacts.artifactNames) { - _artifacts.add(IosUsbArtifacts(artifactName, this)); - } } else { _artifacts.addAll(artifacts); } @@ -224,22 +221,6 @@ class Cache { return getCacheArtifacts().childDirectory(name); } - MapEntry get dyLdLibEntry { - if (_dyLdLibEntry != null) { - return _dyLdLibEntry; - } - final List paths = []; - for (CachedArtifact artifact in _artifacts) { - final String currentPath = artifact.dyLdLibPath; - if (currentPath.isNotEmpty) { - paths.add(currentPath); - } - } - _dyLdLibEntry = MapEntry('DYLD_LIBARY_PATH', paths.join(':')); - return _dyLdLibEntry; - } - MapEntry _dyLdLibEntry; - /// The web sdk has to be co-located with the dart-sdk so that they can share source /// code. Directory getWebSdkDirectory() { @@ -347,9 +328,6 @@ abstract class CachedArtifact { // artifact name. String get stampName => name; - /// Returns a string to be set as environment DYLD_LIBARY_PATH variable - String get dyLdLibPath => ''; - /// All development artifacts this cache provides. final Set developmentArtifacts; @@ -912,39 +890,6 @@ class MacOSFuchsiaSDKArtifacts extends _FuchsiaSDKArtifacts { } } -/// Cached iOS/USB binary artifacts. -class IosUsbArtifacts extends CachedArtifact { - IosUsbArtifacts(String name, Cache cache) : super( - name, - cache, - // This is universal to ensure every command checks for them first - const { DevelopmentArtifact.universal }, - ); - - static const List artifactNames = [ - 'libimobiledevice', - 'usbmuxd', - 'libplist', - 'openssl', - 'ideviceinstaller', - 'ios-deploy', - ]; - - @override - String get dyLdLibPath { - return cache.getArtifactDirectory(name).path; - } - - @override - Future updateInner() { - if (!platform.isMacOS) { - return Future.value(); - } - final Uri archiveUri = Uri.parse('$_storageBaseUrl/flutter_infra/ios-usb-dependencies/$name/$version/$name.zip'); - return _downloadZipArchive('Downloading $name...', archiveUri, location); - } -} - // Many characters are problematic in filenames, especially on Windows. final Map> _flattenNameSubstitutions = >{ r'@'.codeUnitAt(0): '@@'.codeUnits, diff --git a/packages/flutter_tools/lib/src/context_runner.dart b/packages/flutter_tools/lib/src/context_runner.dart index ba5d910ad5..533cfc6fbd 100644 --- a/packages/flutter_tools/lib/src/context_runner.dart +++ b/packages/flutter_tools/lib/src/context_runner.dart @@ -87,8 +87,9 @@ Future runInContext( FuchsiaWorkflow: () => FuchsiaWorkflow(), GenSnapshot: () => const GenSnapshot(), HotRunnerConfig: () => HotRunnerConfig(), - IMobileDevice: () => IMobileDevice(), + IMobileDevice: () => const IMobileDevice(), IOSSimulatorUtils: () => IOSSimulatorUtils(), + IOSValidator: () => const IOSValidator(), IOSWorkflow: () => const IOSWorkflow(), KernelCompilerFactory: () => const KernelCompilerFactory(), LinuxWorkflow: () => const LinuxWorkflow(), diff --git a/packages/flutter_tools/lib/src/doctor.dart b/packages/flutter_tools/lib/src/doctor.dart index c4aa3a67bc..58ba4de796 100644 --- a/packages/flutter_tools/lib/src/doctor.dart +++ b/packages/flutter_tools/lib/src/doctor.dart @@ -72,6 +72,8 @@ class _DefaultDoctorValidatorsProvider implements DoctorValidatorsProvider { GroupedValidator([androidValidator, androidLicenseValidator]), if (iosWorkflow.appliesToHostPlatform || macOSWorkflow.appliesToHostPlatform) GroupedValidator([xcodeValidator, cocoapodsValidator]), + if (iosWorkflow.appliesToHostPlatform) + iosValidator, if (webWorkflow.appliesToHostPlatform) const WebValidator(), // Add desktop doctors to workflow if the flag is enabled. diff --git a/packages/flutter_tools/lib/src/ios/devices.dart b/packages/flutter_tools/lib/src/ios/devices.dart index 7007daf077..3ac80c57f4 100644 --- a/packages/flutter_tools/lib/src/ios/devices.dart +++ b/packages/flutter_tools/lib/src/ios/devices.dart @@ -7,7 +7,6 @@ import 'dart:async'; import 'package:meta/meta.dart'; import '../application_package.dart'; -import '../artifacts.dart'; import '../base/file_system.dart'; import '../base/io.dart'; import '../base/logger.dart'; @@ -24,6 +23,10 @@ import 'code_signing.dart'; import 'ios_workflow.dart'; import 'mac.dart'; +const String _kIdeviceinstallerInstructions = + 'To work with iOS devices, please install ideviceinstaller. To install, run:\n' + 'brew install ideviceinstaller.'; + class IOSDeploy { const IOSDeploy(); @@ -34,15 +37,9 @@ class IOSDeploy { @required String bundlePath, @required List launchArguments, }) async { - final String iosDeployPath = artifacts.getArtifactPath(Artifact.iosDeploy, platform: TargetPlatform.ios); - // TODO(fujino): remove fallback once g3 updated - const List fallbackIosDeployPath = [ + final List launchCommand = [ '/usr/bin/env', 'ios-deploy', - ]; - final List commandList = iosDeployPath != null ? [iosDeployPath] : fallbackIosDeployPath; - final List launchCommand = [ - ...commandList, '--id', deviceId, '--bundle', @@ -64,7 +61,6 @@ class IOSDeploy { // it. final Map iosDeployEnv = Map.from(platform.environment); iosDeployEnv['PATH'] = '/usr/bin:${iosDeployEnv['PATH']}'; - iosDeployEnv.addEntries(>[cache.dyLdLibEntry]); return await runCommandAndStreamOutput( launchCommand, @@ -124,20 +120,8 @@ class IOSDevice extends Device { platformType: PlatformType.ios, ephemeral: true, ) { - if (platform.isMacOS) { - printError('Cannot control iOS devices or simulators. ideviceinstaller and iproxy are not available on your platform.'); - _installerPath = null; - _iproxyPath = null; - return; - } - _installerPath = artifacts.getArtifactPath( - Artifact.ideviceinstaller, - platform: TargetPlatform.ios - ) ?? 'ideviceinstaller'; // TODO(fujino): remove fallback once g3 updated - _iproxyPath = artifacts.getArtifactPath( - Artifact.iproxy, - platform: TargetPlatform.ios - ) ?? 'iproxy'; // TODO(fujino): remove fallback once g3 updated + _installerPath = _checkForCommand('ideviceinstaller'); + _iproxyPath = _checkForCommand('iproxy'); } String _installerPath; @@ -189,6 +173,23 @@ class IOSDevice extends Device { return devices; } + static String _checkForCommand( + String command, [ + String macInstructions = _kIdeviceinstallerInstructions, + ]) { + try { + command = runCheckedSync(['which', command]).trim(); + } catch (e) { + if (platform.isMacOS) { + printError('$command not found. $macInstructions'); + } else { + printError('Cannot control iOS devices or simulators. $command is not available on your platform.'); + } + return null; + } + return command; + } + @override Future isAppInstalled(ApplicationPackage app) async { try { @@ -588,17 +589,12 @@ class _IOSDevicePortForwarder extends DevicePortForwarder { while (!connected) { printTrace('attempting to forward device port $devicePort to host port $hostPort'); // Usage: iproxy LOCAL_TCP_PORT DEVICE_TCP_PORT UDID - process = await runCommand( - [ - device._iproxyPath, - hostPort.toString(), - devicePort.toString(), - device.id, - ], - environment: Map.fromEntries( - >[cache.dyLdLibEntry], - ), - ); + process = await runCommand([ + device._iproxyPath, + hostPort.toString(), + devicePort.toString(), + device.id, + ]); // TODO(ianh): This is a flakey race condition, https://github.com/libimobiledevice/libimobiledevice/issues/674 connected = !await process.stdout.isEmpty.timeout(_kiProxyPortForwardTimeout, onTimeout: () => false); if (!connected) { diff --git a/packages/flutter_tools/lib/src/ios/ios_workflow.dart b/packages/flutter_tools/lib/src/ios/ios_workflow.dart index f21dffd814..cf95c30c8d 100644 --- a/packages/flutter_tools/lib/src/ios/ios_workflow.dart +++ b/packages/flutter_tools/lib/src/ios/ios_workflow.dart @@ -2,13 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:async'; + import '../base/context.dart'; +import '../base/os.dart'; import '../base/platform.dart'; +import '../base/process.dart'; +import '../base/user_messages.dart'; +import '../base/version.dart'; import '../doctor.dart'; import '../macos/xcode.dart'; +import 'mac.dart'; import 'plist_utils.dart' as plist; IOSWorkflow get iosWorkflow => context.get(); +IOSValidator get iosValidator => context.get(); class IOSWorkflow implements Workflow { const IOSWorkflow(); @@ -32,3 +40,86 @@ class IOSWorkflow implements Workflow { return plist.getValueFromFile(path, key); } } + +class IOSValidator extends DoctorValidator { + + const IOSValidator() : super('iOS tools - develop for iOS devices'); + + Future get hasIDeviceInstaller => exitsHappyAsync(['ideviceinstaller', '-h']); + + Future get hasIosDeploy => exitsHappyAsync(['ios-deploy', '--version']); + + String get iosDeployMinimumVersion => '1.9.4'; + + // ios-deploy <= v1.9.3 declares itself as v2.0.0 + List get iosDeployBadVersions => ['2.0.0']; + + Future get iosDeployVersionText async => (await runAsync(['ios-deploy', '--version'])).processResult.stdout.replaceAll('\n', ''); + + bool get hasHomebrew => os.which('brew') != null; + + Future get macDevMode async => (await runAsync(['DevToolsSecurity', '-status'])).processResult.stdout; + + Future get _iosDeployIsInstalledAndMeetsVersionCheck async { + if (!await hasIosDeploy) + return false; + try { + final Version version = Version.parse(await iosDeployVersionText); + return version >= Version.parse(iosDeployMinimumVersion) + && !iosDeployBadVersions.map((String v) => Version.parse(v)).contains(version); + } on FormatException catch (_) { + return false; + } + } + + // Change this value if the number of checks for packages needed for installation changes + static const int totalChecks = 4; + + @override + Future validate() async { + final List messages = []; + ValidationType packageManagerStatus = ValidationType.installed; + + int checksFailed = 0; + + if (!iMobileDevice.isInstalled) { + checksFailed += 3; + packageManagerStatus = ValidationType.partial; + messages.add(ValidationMessage.error(userMessages.iOSIMobileDeviceMissing)); + } else if (!await iMobileDevice.isWorking) { + checksFailed += 2; + packageManagerStatus = ValidationType.partial; + messages.add(ValidationMessage.error(userMessages.iOSIMobileDeviceBroken)); + } else if (!await hasIDeviceInstaller) { + checksFailed += 1; + packageManagerStatus = ValidationType.partial; + messages.add(ValidationMessage.error(userMessages.iOSDeviceInstallerMissing)); + } + + final bool iHasIosDeploy = await hasIosDeploy; + + // Check ios-deploy is installed at meets version requirements. + if (iHasIosDeploy) { + messages.add(ValidationMessage(userMessages.iOSDeployVersion(await iosDeployVersionText))); + } + if (!await _iosDeployIsInstalledAndMeetsVersionCheck) { + packageManagerStatus = ValidationType.partial; + if (iHasIosDeploy) { + messages.add(ValidationMessage.error(userMessages.iOSDeployOutdated(iosDeployMinimumVersion))); + } else { + checksFailed += 1; + messages.add(ValidationMessage.error(userMessages.iOSDeployMissing)); + } + } + + // If one of the checks for the packages failed, we may need brew so that we can install + // the necessary packages. If they're all there, however, we don't even need it. + if (checksFailed == totalChecks) + packageManagerStatus = ValidationType.missing; + if (checksFailed > 0 && !hasHomebrew) { + messages.add(ValidationMessage.hint(userMessages.iOSBrewMissing)); + } + + return ValidationResult(packageManagerStatus, messages); + } +} diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index 2bcdd59463..dcc7f5acdc 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -7,7 +7,6 @@ import 'dart:async'; import 'package:meta/meta.dart'; import '../application_package.dart'; -import '../artifacts.dart'; import '../base/common.dart'; import '../base/context.dart'; import '../base/file_system.dart'; @@ -43,99 +42,35 @@ class IOSDeviceNotFoundError implements Exception { } class IMobileDevice { - IMobileDevice() - : _ideviceIdPath = artifacts.getArtifactPath(Artifact.ideviceId, platform: TargetPlatform.ios) - ?? 'idevice_id', // TODO(fujino): remove fallback once g3 updated - _ideviceinfoPath = artifacts.getArtifactPath(Artifact.ideviceinfo, platform: TargetPlatform.ios) - ?? 'ideviceinfo', // TODO(fujino): remove fallback once g3 updated - _idevicenamePath = artifacts.getArtifactPath(Artifact.idevicename, platform: TargetPlatform.ios) - ?? 'idevicename', // TODO(fujino): remove fallback once g3 updated - _idevicesyslogPath = artifacts.getArtifactPath(Artifact.idevicesyslog, platform: TargetPlatform.ios) - ?? 'idevicesyslog', // TODO(fujino): remove fallback once g3 updated - _idevicescreenshotPath = artifacts.getArtifactPath(Artifact.idevicescreenshot, platform: TargetPlatform.ios) - ?? 'idevicescreenshot' { // TODO(fujino): remove fallback once g3 updated - } - final String _ideviceIdPath; - final String _ideviceinfoPath; - final String _idevicenamePath; - final String _idevicesyslogPath; - final String _idevicescreenshotPath; + const IMobileDevice(); - bool get isInstalled { - _isInstalled ??= exitsHappy( - [ - _ideviceIdPath, - '-h' - ], - environment: Map.fromEntries( - >[cache.dyLdLibEntry] - ), - ); - return _isInstalled; - } - bool _isInstalled; + bool get isInstalled => exitsHappy(['idevice_id', '-h']); /// Returns true if libimobiledevice is installed and working as expected. /// /// Older releases of libimobiledevice fail to work with iOS 10.3 and above. Future get isWorking async { - if (_isWorking != null) { - return _isWorking; - } - if (!isInstalled) { - _isWorking = false; - return _isWorking; - } + if (!isInstalled) + return false; // If usage info is printed in a hyphenated id, we need to update. const String fakeIphoneId = '00008020-001C2D903C42002E'; - final Map executionEnv = Map.fromEntries( - >[cache.dyLdLibEntry] - ); - final ProcessResult ideviceResult = (await runAsync( - [ - _ideviceinfoPath, - '-u', - fakeIphoneId - ], - environment: executionEnv, - )).processResult; + final ProcessResult ideviceResult = (await runAsync(['ideviceinfo', '-u', fakeIphoneId])).processResult; if (ideviceResult.stdout.contains('Usage: ideviceinfo')) { - _isWorking = false; - return _isWorking; + return false; } // If no device is attached, we're unable to detect any problems. Assume all is well. - final ProcessResult result = (await runAsync( - [ - _ideviceIdPath, - '-l', - ], - environment: executionEnv, - )).processResult; - if (result.exitCode == 0 && result.stdout.isEmpty) { - _isWorking = true; - } else { - // Check that we can look up the names of any attached devices. - _isWorking = await exitsHappyAsync( - [_idevicenamePath], - environment: executionEnv, - ); - } - return _isWorking; + final ProcessResult result = (await runAsync(['idevice_id', '-l'])).processResult; + if (result.exitCode == 0 && result.stdout.isEmpty) + return true; + + // Check that we can look up the names of any attached devices. + return await exitsHappyAsync(['idevicename']); } - bool _isWorking; Future getAvailableDeviceIDs() async { try { - final ProcessResult result = await processManager.run( - [ - _ideviceIdPath, - '-l' - ], - environment: Map.fromEntries( - >[cache.dyLdLibEntry] - ), - ); + final ProcessResult result = await processManager.run(['idevice_id', '-l']); if (result.exitCode != 0) throw ToolExit('idevice_id returned an error:\n${result.stderr}'); return result.stdout; @@ -146,18 +81,7 @@ class IMobileDevice { Future getInfoForDevice(String deviceID, String key) async { try { - final ProcessResult result = await processManager.run( - [ - _ideviceinfoPath, - '-u', - deviceID, - '-k', - key - ], - environment: Map.fromEntries( - >[cache.dyLdLibEntry] - ), - ); + final ProcessResult result = await processManager.run(['ideviceinfo', '-u', deviceID, '-k', key]); if (result.exitCode == 255 && result.stdout != null && result.stdout.contains('No device found')) throw IOSDeviceNotFoundError('ideviceinfo could not find device:\n${result.stdout}'); if (result.exitCode != 0) @@ -169,30 +93,11 @@ class IMobileDevice { } /// Starts `idevicesyslog` and returns the running process. - Future startLogger(String deviceID) { - return runCommand( - [ - _idevicesyslogPath, - '-u', - deviceID, - ], - environment: Map.fromEntries( - >[cache.dyLdLibEntry] - ), - ); - } + Future startLogger(String deviceID) => runCommand(['idevicesyslog', '-u', deviceID]); /// Captures a screenshot to the specified outputFile. Future takeScreenshot(File outputFile) { - return runCheckedAsync( - [ - _idevicescreenshotPath, - outputFile.path - ], - environment: Map.fromEntries( - >[cache.dyLdLibEntry] - ), - ); + return runCheckedAsync(['idevicescreenshot', outputFile.path]); } } diff --git a/packages/flutter_tools/lib/src/macos/cocoapods.dart b/packages/flutter_tools/lib/src/macos/cocoapods.dart index 9729387c9c..9462395b72 100644 --- a/packages/flutter_tools/lib/src/macos/cocoapods.dart +++ b/packages/flutter_tools/lib/src/macos/cocoapods.dart @@ -30,11 +30,11 @@ const String unknownCocoaPodsConsequence = ''' Ensure that the output of 'pod --version' contains only digits and . to be recognized by Flutter.'''; const String cocoaPodsInstallInstructions = ''' - sudo gem install cocoapods + brew install cocoapods pod setup'''; const String cocoaPodsUpgradeInstructions = ''' - sudo gem install cocoapods + brew upgrade cocoapods pod setup'''; CocoaPods get cocoaPods => context.get(); diff --git a/packages/flutter_tools/lib/src/macos/cocoapods_validator.dart b/packages/flutter_tools/lib/src/macos/cocoapods_validator.dart index aaee745572..615c3f54b3 100644 --- a/packages/flutter_tools/lib/src/macos/cocoapods_validator.dart +++ b/packages/flutter_tools/lib/src/macos/cocoapods_validator.dart @@ -5,6 +5,7 @@ import 'dart:async'; import '../base/context.dart'; +import '../base/os.dart'; import '../base/user_messages.dart'; import '../doctor.dart'; import 'cocoapods.dart'; @@ -14,6 +15,8 @@ CocoaPodsValidator get cocoapodsValidator => context.get(); class CocoaPodsValidator extends DoctorValidator { const CocoaPodsValidator() : super('CocoaPods subvalidator'); + bool get hasHomebrew => os.which('brew') != null; + @override Future validate() async { final List messages = []; @@ -45,6 +48,11 @@ class CocoaPodsValidator extends DoctorValidator { } } + // Only check/report homebrew status if CocoaPods isn't installed. + if (status == ValidationType.missing && !hasHomebrew) { + messages.add(ValidationMessage.hint(userMessages.cocoaPodsBrewMissing)); + } + return ValidationResult(status, messages); } -} +} \ No newline at end of file diff --git a/packages/flutter_tools/test/cache_test.dart b/packages/flutter_tools/test/cache_test.dart index 64a7e584a1..a95964a551 100644 --- a/packages/flutter_tools/test/cache_test.dart +++ b/packages/flutter_tools/test/cache_test.dart @@ -107,22 +107,6 @@ void main() { verifyNever(artifact1.update({})); verify(artifact2.update({})); }); - testUsingContext('getter dyLdLibEntry concatenates the output of each artifact\'s dyLdLibEntry getter', () async { - final CachedArtifact artifact1 = MockCachedArtifact(); - final CachedArtifact artifact2 = MockCachedArtifact(); - final CachedArtifact artifact3 = MockCachedArtifact(); - when(artifact1.dyLdLibPath).thenReturn('/path/to/alpha:/path/to/beta'); - when(artifact2.dyLdLibPath).thenReturn('/path/to/gamma:/path/to/delta:/path/to/epsilon'); - when(artifact3.dyLdLibPath).thenReturn(''); // Empty output - final Cache cache = Cache(artifacts: [artifact1, artifact2, artifact3]); - expect(cache.dyLdLibEntry.key, 'DYLD_LIBARY_PATH'); - expect( - cache.dyLdLibEntry.value, - '/path/to/alpha:/path/to/beta:/path/to/gamma:/path/to/delta:/path/to/epsilon', - ); - }, overrides: { - Cache: ()=> mockCache, - }); testUsingContext('failed storage.googleapis.com download shows China warning', () async { final CachedArtifact artifact1 = MockCachedArtifact(); final CachedArtifact artifact2 = MockCachedArtifact(); diff --git a/packages/flutter_tools/test/ios/code_signing_test.dart b/packages/flutter_tools/test/ios/code_signing_test.dart index ecea51fc71..9d381a054a 100644 --- a/packages/flutter_tools/test/ios/code_signing_test.dart +++ b/packages/flutter_tools/test/ios/code_signing_test.dart @@ -425,7 +425,7 @@ void main() { final Map signingConfigs = await getCodeSigningIdentityDevelopmentTeam(iosApp: app); expect( - testLogger.errorText.replaceAll('\n', ' '), + testLogger.errorText, contains('Saved signing certificate "iPhone Developer: Invalid Profile" is not a valid development certificate'), ); expect( diff --git a/packages/flutter_tools/test/ios/ios_workflow_test.dart b/packages/flutter_tools/test/ios/ios_workflow_test.dart new file mode 100644 index 0000000000..a2e3745306 --- /dev/null +++ b/packages/flutter_tools/test/ios/ios_workflow_test.dart @@ -0,0 +1,178 @@ +// Copyright 2017 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:file/memory.dart'; +import 'package:flutter_tools/src/base/file_system.dart'; +import 'package:flutter_tools/src/base/io.dart'; +import 'package:flutter_tools/src/doctor.dart'; +import 'package:flutter_tools/src/ios/ios_workflow.dart'; +import 'package:flutter_tools/src/ios/mac.dart'; +import 'package:mockito/mockito.dart'; +import 'package:process/process.dart'; + +import '../src/common.dart'; +import '../src/context.dart'; + +void main() { + group('iOS Workflow validation', () { + MockIMobileDevice iMobileDevice; + MockIMobileDevice iMobileDeviceUninstalled; + MockProcessManager processManager; + FileSystem fs; + + setUp(() { + iMobileDevice = MockIMobileDevice(); + iMobileDeviceUninstalled = MockIMobileDevice(isInstalled: false); + processManager = MockProcessManager(); + fs = MemoryFileSystem(); + }); + + testUsingContext('Emit missing status when nothing is installed', () async { + final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget( + hasHomebrew: false, + hasIosDeploy: false, + hasIDeviceInstaller: false, + iosDeployVersionText: '0.0.0', + ); + final ValidationResult result = await workflow.validate(); + expect(result.type, ValidationType.missing); + }, overrides: { + IMobileDevice: () => iMobileDeviceUninstalled, + }); + + testUsingContext('Emits installed status when homebrew not installed, but not needed', () async { + final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget(hasHomebrew: false); + final ValidationResult result = await workflow.validate(); + expect(result.type, ValidationType.installed); + }, overrides: { + IMobileDevice: () => iMobileDevice, + }); + + testUsingContext('Emits partial status when libimobiledevice is not installed', () async { + final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget(); + final ValidationResult result = await workflow.validate(); + expect(result.type, ValidationType.partial); + }, overrides: { + IMobileDevice: () => MockIMobileDevice(isInstalled: false, isWorking: false), + }); + + testUsingContext('Emits partial status when libimobiledevice is installed but not working', () async { + final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget(); + final ValidationResult result = await workflow.validate(); + expect(result.type, ValidationType.partial); + }, overrides: { + IMobileDevice: () => MockIMobileDevice(isWorking: false), + }); + + testUsingContext('Emits partial status when libimobiledevice is installed but not working', () async { + when(processManager.run( + ['ideviceinfo', '-u', '00008020-001C2D903C42002E'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment')), + ).thenAnswer((Invocation _) async { + final MockProcessResult result = MockProcessResult(); + when(result.stdout).thenReturn(r''' +Usage: ideviceinfo [OPTIONS] +Show information about a connected device. + + -d, --debug enable communication debugging + -s, --simple use a simple connection to avoid auto-pairing with the device + -u, --udid UDID target specific device by its 40-digit device UDID + -q, --domain NAME set domain of query to NAME. Default: None + -k, --key NAME only query key specified by NAME. Default: All keys. + -x, --xml output information as xml plist instead of key/value pairs + -h, --help prints usage information + '''); + return null; + }); + final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget(); + final ValidationResult result = await workflow.validate(); + expect(result.type, ValidationType.partial); + }, overrides: { + ProcessManager: () => processManager, + }); + + + testUsingContext('Emits partial status when ios-deploy is not installed', () async { + final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget(hasIosDeploy: false); + final ValidationResult result = await workflow.validate(); + expect(result.type, ValidationType.partial); + }, overrides: { + IMobileDevice: () => iMobileDevice, + }); + + testUsingContext('Emits partial status when ios-deploy version is too low', () async { + final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget(iosDeployVersionText: '1.8.0'); + final ValidationResult result = await workflow.validate(); + expect(result.type, ValidationType.partial); + }, overrides: { + IMobileDevice: () => iMobileDevice, + }); + + testUsingContext('Emits partial status when ios-deploy version is a known bad version', () async { + final IOSWorkflowTestTarget workflow = IOSWorkflowTestTarget(iosDeployVersionText: '2.0.0'); + final ValidationResult result = await workflow.validate(); + expect(result.type, ValidationType.partial); + }, overrides: { + IMobileDevice: () => iMobileDevice, + }); + + testUsingContext('Succeeds when all checks pass', () async { + final ValidationResult result = await IOSWorkflowTestTarget().validate(); + expect(result.type, ValidationType.installed); + }, overrides: { + FileSystem: () => fs, + IMobileDevice: () => iMobileDevice, + ProcessManager: () => processManager, + }); + }); +} + +final ProcessResult exitsHappy = ProcessResult( + 1, // pid + 0, // exitCode + '', // stdout + '', // stderr +); + +class MockIMobileDevice extends IMobileDevice { + MockIMobileDevice({ + this.isInstalled = true, + bool isWorking = true, + }) : isWorking = Future.value(isWorking); + + @override + final bool isInstalled; + + @override + final Future isWorking; +} + +class MockProcessManager extends Mock implements ProcessManager {} +class MockProcessResult extends Mock implements ProcessResult {} + +class IOSWorkflowTestTarget extends IOSValidator { + IOSWorkflowTestTarget({ + this.hasHomebrew = true, + bool hasIosDeploy = true, + String iosDeployVersionText = '1.9.4', + bool hasIDeviceInstaller = true, + }) : hasIosDeploy = Future.value(hasIosDeploy), + iosDeployVersionText = Future.value(iosDeployVersionText), + hasIDeviceInstaller = Future.value(hasIDeviceInstaller); + + @override + final bool hasHomebrew; + + @override + final Future hasIosDeploy; + + @override + final Future iosDeployVersionText; + + @override + final Future hasIDeviceInstaller; +} diff --git a/packages/flutter_tools/test/ios/mac_test.dart b/packages/flutter_tools/test/ios/mac_test.dart index de77d6e82b..8124ed8e21 100644 --- a/packages/flutter_tools/test/ios/mac_test.dart +++ b/packages/flutter_tools/test/ios/mac_test.dart @@ -9,8 +9,6 @@ import 'package:flutter_tools/src/base/file_system.dart'; import 'package:flutter_tools/src/base/io.dart' show ProcessException, ProcessResult; import 'package:flutter_tools/src/ios/mac.dart'; import 'package:flutter_tools/src/ios/xcodeproj.dart'; -import 'package:flutter_tools/src/artifacts.dart'; -import 'package:flutter_tools/src/cache.dart'; import 'package:flutter_tools/src/project.dart'; import 'package:mockito/mockito.dart'; import 'package:platform/platform.dart'; @@ -24,8 +22,6 @@ final Map noColorTerminalOverride = { Platform: _kNoColorTerminalPlatform, }; -class MockArtifacts extends Mock implements Artifacts {} -class MockCache extends Mock implements Cache {} class MockProcessManager extends Mock implements ProcessManager {} class MockFile extends Mock implements File {} class MockXcodeProjectInterpreter extends Mock implements XcodeProjectInterpreter {} @@ -36,80 +32,41 @@ void main() { final FakePlatform osx = FakePlatform.fromPlatform(const LocalPlatform()) ..operatingSystem = 'macos'; MockProcessManager mockProcessManager; - final String libimobiledevicePath = fs.path.join('bin', 'cache', 'artifacts', 'libimobiledevice'); - final String ideviceIdPath = fs.path.join(libimobiledevicePath, 'idevice_id'); - final String ideviceInfoPath = fs.path.join(libimobiledevicePath, 'ideviceinfo'); - final String idevicescreenshotPath = fs.path.join(libimobiledevicePath, 'idevicescreenshot'); - MockArtifacts mockArtifacts; - MockCache mockCache; setUp(() { mockProcessManager = MockProcessManager(); - mockCache = MockCache(); - mockArtifacts = MockArtifacts(); - when(mockArtifacts.getArtifactPath(Artifact.ideviceId, platform: anyNamed('platform'))).thenReturn(ideviceIdPath); - when(mockCache.dyLdLibEntry).thenReturn( - MapEntry('DYLD_LIBRARY_PATH', libimobiledevicePath) - ); - }); - - testUsingContext('isWorking returns false if libimobiledevice is not installed', () async { - when(mockProcessManager.runSync( - [ideviceIdPath, '-h'], environment: anyNamed('environment') - )).thenReturn(ProcessResult(123, 1, '', '')); - expect(await iMobileDevice.isWorking, false); - }, overrides: { - ProcessManager: () => mockProcessManager, - Artifacts: () => mockArtifacts, }); testUsingContext('getAvailableDeviceIDs throws ToolExit when libimobiledevice is not installed', () async { - when(mockProcessManager.run( - [ideviceIdPath, '-l'], - environment: {'DYLD_LIBRARY_PATH': libimobiledevicePath}, - )).thenThrow(ProcessException(ideviceIdPath, ['-l'])); + when(mockProcessManager.run(['idevice_id', '-l'])) + .thenThrow(const ProcessException('idevice_id', ['-l'])); expect(() async => await iMobileDevice.getAvailableDeviceIDs(), throwsToolExit()); }, overrides: { ProcessManager: () => mockProcessManager, - Cache: () => mockCache, - Artifacts: () => mockArtifacts, }); testUsingContext('getAvailableDeviceIDs throws ToolExit when idevice_id returns non-zero', () async { - when(mockProcessManager.run( - [ideviceIdPath, '-l'], - environment: {'DYLD_LIBRARY_PATH': libimobiledevicePath}, - )).thenAnswer((_) => Future.value(ProcessResult(1, 1, '', 'Sad today'))); + when(mockProcessManager.run(['idevice_id', '-l'])) + .thenAnswer((_) => Future.value(ProcessResult(1, 1, '', 'Sad today'))); expect(() async => await iMobileDevice.getAvailableDeviceIDs(), throwsToolExit()); }, overrides: { ProcessManager: () => mockProcessManager, - Cache: () => mockCache, - Artifacts: () => mockArtifacts, }); testUsingContext('getAvailableDeviceIDs returns idevice_id output when installed', () async { - when(mockProcessManager.run( - [ideviceIdPath, '-l'], - environment: {'DYLD_LIBRARY_PATH': libimobiledevicePath}, - )).thenAnswer((_) => Future.value(ProcessResult(1, 0, 'foo', ''))); + when(mockProcessManager.run(['idevice_id', '-l'])) + .thenAnswer((_) => Future.value(ProcessResult(1, 0, 'foo', ''))); expect(await iMobileDevice.getAvailableDeviceIDs(), 'foo'); }, overrides: { ProcessManager: () => mockProcessManager, - Cache: () => mockCache, - Artifacts: () => mockArtifacts, }); testUsingContext('getInfoForDevice throws IOSDeviceNotFoundError when ideviceinfo returns specific error code and message', () async { - when(mockArtifacts.getArtifactPath(Artifact.ideviceinfo, platform: anyNamed('platform'))).thenReturn(ideviceInfoPath); - when(mockProcessManager.run( - [ideviceInfoPath, '-u', 'foo', '-k', 'bar'], - environment: {'DYLD_LIBRARY_PATH': libimobiledevicePath}, - )).thenAnswer((_) => Future.value(ProcessResult(1, 255, 'No device found with udid foo, is it plugged in?', ''))); + when(mockProcessManager.run(['ideviceinfo', '-u', 'foo', '-k', 'bar'])) + .thenAnswer((_) => Future.value(ProcessResult(1, 255, 'No device found with udid foo, is it plugged in?', ''))); expect(() async => await iMobileDevice.getInfoForDevice('foo', 'bar'), throwsA(isInstanceOf())); }, overrides: { ProcessManager: () => mockProcessManager, - Cache: () => mockCache, - Artifacts: () => mockArtifacts, }); group('screenshot', () { @@ -120,15 +77,14 @@ void main() { setUp(() { mockProcessManager = MockProcessManager(); mockOutputFile = MockFile(); - when(mockArtifacts.getArtifactPath(Artifact.idevicescreenshot, platform: anyNamed('platform'))).thenReturn(idevicescreenshotPath); }); testUsingContext('error if idevicescreenshot is not installed', () async { when(mockOutputFile.path).thenReturn(outputPath); // Let `idevicescreenshot` fail with exit code 1. - when(mockProcessManager.run([idevicescreenshotPath, outputPath], - environment: {'DYLD_LIBRARY_PATH': libimobiledevicePath}, + when(mockProcessManager.run(['idevicescreenshot', outputPath], + environment: null, workingDirectory: null, )).thenAnswer((_) => Future.value(ProcessResult(4, 1, '', ''))); @@ -136,23 +92,20 @@ void main() { }, overrides: { ProcessManager: () => mockProcessManager, Platform: () => osx, - Cache: () => mockCache, }); testUsingContext('idevicescreenshot captures and returns screenshot', () async { when(mockOutputFile.path).thenReturn(outputPath); - when(mockProcessManager.run(any, environment: anyNamed('environment'), workingDirectory: null)).thenAnswer( + when(mockProcessManager.run(any, environment: null, workingDirectory: null)).thenAnswer( (Invocation invocation) => Future.value(ProcessResult(4, 0, '', ''))); await iMobileDevice.takeScreenshot(mockOutputFile); - verify(mockProcessManager.run([idevicescreenshotPath, outputPath], - environment: {'DYLD_LIBRARY_PATH': libimobiledevicePath}, + verify(mockProcessManager.run(['idevicescreenshot', outputPath], + environment: null, workingDirectory: null, )); }, overrides: { ProcessManager: () => mockProcessManager, - Cache: () => mockCache, - Artifacts: () => mockArtifacts, }); }); }); diff --git a/packages/flutter_tools/test/macos/cocoapods_validator_test.dart b/packages/flutter_tools/test/macos/cocoapods_validator_test.dart index 996bd35fd1..bd49fc148b 100644 --- a/packages/flutter_tools/test/macos/cocoapods_validator_test.dart +++ b/packages/flutter_tools/test/macos/cocoapods_validator_test.dart @@ -23,7 +23,7 @@ void main() { }); testUsingContext('Emits installed status when CocoaPods is installed', () async { - const CocoaPodsValidator workflow = CocoaPodsValidator(); + final CocoaPodsTestTarget workflow = CocoaPodsTestTarget(); final ValidationResult result = await workflow.validate(); expect(result.type, ValidationType.installed); }, overrides: { @@ -33,7 +33,7 @@ void main() { testUsingContext('Emits missing status when CocoaPods is not installed', () async { when(cocoaPods.evaluateCocoaPodsInstallation) .thenAnswer((_) async => CocoaPodsStatus.notInstalled); - const CocoaPodsValidator workflow = CocoaPodsValidator(); + final CocoaPodsTestTarget workflow = CocoaPodsTestTarget(); final ValidationResult result = await workflow.validate(); expect(result.type, ValidationType.missing); }, overrides: { @@ -43,7 +43,7 @@ void main() { testUsingContext('Emits partial status when CocoaPods is installed with unknown version', () async { when(cocoaPods.evaluateCocoaPodsInstallation) .thenAnswer((_) async => CocoaPodsStatus.unknownVersion); - const CocoaPodsValidator workflow = CocoaPodsValidator(); + final CocoaPodsTestTarget workflow = CocoaPodsTestTarget(); final ValidationResult result = await workflow.validate(); expect(result.type, ValidationType.partial); }, overrides: { @@ -52,7 +52,7 @@ void main() { testUsingContext('Emits partial status when CocoaPods is not initialized', () async { when(cocoaPods.isCocoaPodsInitialized).thenAnswer((_) async => false); - const CocoaPodsValidator workflow = CocoaPodsValidator(); + final CocoaPodsTestTarget workflow = CocoaPodsTestTarget(); final ValidationResult result = await workflow.validate(); expect(result.type, ValidationType.partial); }, overrides: { @@ -62,13 +62,30 @@ void main() { testUsingContext('Emits partial status when CocoaPods version is too low', () async { when(cocoaPods.evaluateCocoaPodsInstallation) .thenAnswer((_) async => CocoaPodsStatus.belowRecommendedVersion); - const CocoaPodsValidator workflow = CocoaPodsValidator(); + final CocoaPodsTestTarget workflow = CocoaPodsTestTarget(); final ValidationResult result = await workflow.validate(); expect(result.type, ValidationType.partial); }, overrides: { CocoaPods: () => cocoaPods, }); + + testUsingContext('Emits installed status when homebrew not installed, but not needed', () async { + final CocoaPodsTestTarget workflow = CocoaPodsTestTarget(hasHomebrew: false); + final ValidationResult result = await workflow.validate(); + expect(result.type, ValidationType.installed); + }, overrides: { + CocoaPods: () => cocoaPods, + }); }); } class MockCocoaPods extends Mock implements CocoaPods {} + +class CocoaPodsTestTarget extends CocoaPodsValidator { + CocoaPodsTestTarget({ + this.hasHomebrew = true, + }); + + @override + final bool hasHomebrew; +}