diff --git a/packages/flutter_tools/lib/src/ios/ios_workflow.dart b/packages/flutter_tools/lib/src/ios/ios_workflow.dart index a9d0ce6dd4..5604f2f618 100644 --- a/packages/flutter_tools/lib/src/ios/ios_workflow.dart +++ b/packages/flutter_tools/lib/src/ios/ios_workflow.dart @@ -4,6 +4,8 @@ import 'dart:async'; +import '../base/common.dart'; +import '../base/file_system.dart'; import '../base/io.dart'; import '../base/os.dart'; import '../base/platform.dart'; @@ -60,7 +62,7 @@ class IOSWorkflow extends DoctorValidator implements Workflow { } } - bool get cocoaPodsInstalledAndMeetsVersionCheck { + bool get isCocoaPodsInstalledAndMeetsVersionCheck { if (!hasCocoaPods) return false; try { @@ -71,6 +73,13 @@ class IOSWorkflow extends DoctorValidator implements Workflow { } } + /// Whether CocoaPods ran 'pod setup' once where the costly pods' specs are cloned. + bool get isCocoaPodsInitialized { + return fs.isDirectorySync( + fs.path.join(homeDirPath, '.cocoapods', 'repos', 'master') + ); + } + @override Future validate() async { final List messages = []; @@ -175,8 +184,19 @@ class IOSWorkflow extends DoctorValidator implements Workflow { )); } } - if (cocoaPodsInstalledAndMeetsVersionCheck) { - messages.add(new ValidationMessage('CocoaPods version $cocoaPodsVersionText')); + if (isCocoaPodsInstalledAndMeetsVersionCheck) { + if (isCocoaPodsInitialized) { + messages.add(new ValidationMessage('CocoaPods version $cocoaPodsVersionText')); + } else { + brewStatus = ValidationType.partial; + messages.add(new ValidationMessage.error( + 'CocoaPods installed but not initialized.\n' + '$noCocoaPodsConsequence\n' + 'To initialize CocoaPods, run:\n' + ' pod setup\n' + 'once to finalize CocoaPods\' installation.' + )); + } } else { brewStatus = ValidationType.partial; if (!hasCocoaPods) { diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index 4774054ff8..973652974c 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -348,9 +348,8 @@ bool _checkXcodeVersion() { } final String noCocoaPodsConsequence = ''' - CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your - plugin usage on the Dart side. - Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS. + CocoaPods is used to retrieve the iOS platform side's plugin code that responds to your plugin usage on the Dart side. + Without resolving iOS dependencies with CocoaPods, plugins will not work on iOS. For more info, see https://flutter.io/platform-plugins'''; final String cocoaPodsInstallInstructions = ''' @@ -365,7 +364,7 @@ final String cocoaPodsUpgradeInstructions = ''' Future _runPodInstall(Directory bundle, String engineDirectory) async { if (fs.file(fs.path.join(bundle.path, 'Podfile')).existsSync()) { - if (!doctor.iosWorkflow.cocoaPodsInstalledAndMeetsVersionCheck) { + if (!doctor.iosWorkflow.isCocoaPodsInstalledAndMeetsVersionCheck) { final String minimumVersion = doctor.iosWorkflow.cocoaPodsMinimumVersion; printError( 'Warning: CocoaPods version $minimumVersion or greater not installed. Skipping pod install.\n' @@ -375,6 +374,16 @@ Future _runPodInstall(Directory bundle, String engineDirectory) async { ); return; } + if (!doctor.iosWorkflow.isCocoaPodsInitialized) { + printError( + 'Warning: CocoaPods installed but not initialized. Skipping pod install.\n' + '$noCocoaPodsConsequence\n' + 'To initialize CocoaPods, run:\n' + ' pod setup\n' + 'once to finalize CocoaPods\' installation.' + ); + return; + } try { final Status status = logger.startProgress('Running pod install...', expectSlowOperation: true); await runCheckedAsync( diff --git a/packages/flutter_tools/test/src/ios/ios_workflow_test.dart b/packages/flutter_tools/test/src/ios/ios_workflow_test.dart index 9f61486ae7..16c61d6912 100644 --- a/packages/flutter_tools/test/src/ios/ios_workflow_test.dart +++ b/packages/flutter_tools/test/src/ios/ios_workflow_test.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:file/memory.dart'; +import 'package:flutter_tools/src/base/common.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'; @@ -16,10 +19,12 @@ void main() { group('iOS Workflow validation', () { MockXcode xcode; MockProcessManager processManager; + FileSystem fs; setUp(() { xcode = new MockXcode(); processManager = new MockProcessManager(); + fs = new MemoryFileSystem(); }); testUsingContext('Emit missing status when nothing is installed', () async { @@ -143,7 +148,7 @@ void main() { expect(result.type, ValidationType.partial); }, overrides: { Xcode: () => xcode }); - testUsingContext('Succeeds when all checks pass', () async { + testUsingContext('Emits partial status when CocoaPods is not initialized', () async { when(xcode.isInstalled).thenReturn(true); when(xcode.xcodeVersionText) .thenReturn('Xcode 8.2.1\nBuild version 8C1002\n'); @@ -155,9 +160,32 @@ void main() { when(processManager.run(argThat(contains('idevice_id')), workingDirectory: any, environment: any)) .thenReturn(exitsHappy); + final ValidationResult result = await new IOSWorkflowTestTarget().validate(); + expect(result.type, ValidationType.partial); + }, overrides: { + FileSystem: () => fs, + Xcode: () => xcode, + ProcessManager: () => processManager, + }); + + testUsingContext('Succeeds when all checks pass', () async { + when(xcode.isInstalled).thenReturn(true); + when(xcode.xcodeVersionText) + .thenReturn('Xcode 8.2.1\nBuild version 8C1002\n'); + when(xcode.isInstalledAndMeetsVersionCheck).thenReturn(true); + when(xcode.eulaSigned).thenReturn(true); + + when(processManager.runSync(argThat(contains('idevice_id')))) + .thenReturn(exitsHappy); + when(processManager.run(argThat(contains('idevice_id')), workingDirectory: any, environment: any)) + .thenReturn(exitsHappy); + + ensureDirectoryExists(fs.path.join(homeDirPath, '.cocoapods', 'repos', 'master', 'README.md')); + final ValidationResult result = await new IOSWorkflowTestTarget().validate(); expect(result.type, ValidationType.installed); }, overrides: { + FileSystem: () => fs, Xcode: () => xcode, ProcessManager: () => processManager, });