From 2c846af1a04ab0e83f8cd1e55a6e5701073f406b Mon Sep 17 00:00:00 2001 From: Christopher Fujino Date: Tue, 3 Mar 2020 17:55:02 -0800 Subject: [PATCH] Fix `_checkPodCondition` not handling `CocoaPodsStatus.brokenInstall` (#51676) --- .../lib/src/macos/cocoapods.dart | 22 +++++++--- .../general.shard/macos/cocoapods_test.dart | 42 ++++++++++++++++--- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/packages/flutter_tools/lib/src/macos/cocoapods.dart b/packages/flutter_tools/lib/src/macos/cocoapods.dart index d748ab1747..4283826dc1 100644 --- a/packages/flutter_tools/lib/src/macos/cocoapods.dart +++ b/packages/flutter_tools/lib/src/macos/cocoapods.dart @@ -143,13 +143,14 @@ class CocoaPods { throwToolExit('Podfile missing'); } bool podsProcessed = false; - if (await _checkPodCondition()) { - if (_shouldRunPodInstall(xcodeProject, dependenciesChanged)) { - await _runPodInstall(xcodeProject, engineDir); - podsProcessed = true; + if (_shouldRunPodInstall(xcodeProject, dependenciesChanged)) { + if (!await _checkPodCondition()) { + throwToolExit('CocoaPods not installed or not in valid state.'); } - _warnIfPodfileOutOfDate(xcodeProject); + await _runPodInstall(xcodeProject, engineDir); + podsProcessed = true; } + _warnIfPodfileOutOfDate(xcodeProject); return podsProcessed; } @@ -166,6 +167,15 @@ class CocoaPods { emphasis: true, ); return false; + case CocoaPodsStatus.brokenInstall: + globals.printError( + 'Warning: CocoaPods is installed but broken. Skipping pod install.\n' + '$brokenCocoaPodsConsequence\n' + 'To re-install:\n' + '$cocoaPodsUpgradeInstructions\n', + emphasis: true, + ); + return false; case CocoaPodsStatus.unknownVersion: globals.printError( 'Warning: Unknown CocoaPods version installed.\n' @@ -193,7 +203,7 @@ class CocoaPods { emphasis: true, ); break; - default: + case CocoaPodsStatus.recommended: break; } if (!await isCocoaPodsInitialized) { diff --git a/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart b/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart index ebfd87bb03..d712f7f1b5 100644 --- a/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart +++ b/packages/flutter_tools/test/general.shard/macos/cocoapods_test.dart @@ -109,6 +109,22 @@ void main() { )).thenAnswer((_) async => exitsWithError()); } + void pretendPodIsBroken() { + // it is present + when(mockProcessManager.run( + ['which', 'pod'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).thenAnswer((_) async => exitsHappy()); + + // but is not working + when(mockProcessManager.run( + ['pod', '--version'], + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )).thenAnswer((_) async => exitsWithError()); + } + void pretendPodIsInstalled() { when(mockProcessManager.run( ['which', 'pod'], @@ -306,21 +322,37 @@ void main() { podsIsInHomeDir(); }); - testUsingContext('prints error, if CocoaPods is not installed', () async { + testUsingContext('throwsToolExit if CocoaPods is not installed', () async { pretendPodIsNotInstalled(); projectUnderTest.ios.podfile.createSync(); - final bool didInstall = await cocoaPodsUnderTest.processPods( + final Function invokeProcessPods = () async => await cocoaPodsUnderTest.processPods( xcodeProject: projectUnderTest.ios, engineDir: 'engine/path', ); + expect(invokeProcessPods, throwsToolExit()); + verifyNever(mockProcessManager.run( + argThat(containsAllInOrder(['pod', 'install'])), + workingDirectory: anyNamed('workingDirectory'), + environment: anyNamed('environment'), + )); + }, overrides: { + FileSystem: () => fs, + ProcessManager: () => mockProcessManager, + }); + + testUsingContext('throwsToolExit if CocoaPods install is broken', () async { + pretendPodIsBroken(); + projectUnderTest.ios.podfile.createSync(); + final Function invokeProcessPods = () async => await cocoaPodsUnderTest.processPods( + xcodeProject: projectUnderTest.ios, + engineDir: 'engine/path', + ); + expect(invokeProcessPods, throwsToolExit()); verifyNever(mockProcessManager.run( argThat(containsAllInOrder(['pod', 'install'])), workingDirectory: anyNamed('workingDirectory'), environment: anyNamed('environment'), )); - expect(testLogger.errorText, contains('not installed')); - expect(testLogger.errorText, contains('Skipping pod install')); - expect(didInstall, isFalse); }, overrides: { FileSystem: () => fs, ProcessManager: () => mockProcessManager,