From e94038154b759f850d7cd0b8a99ce9d78a2f3306 Mon Sep 17 00:00:00 2001 From: xster Date: Fri, 10 Nov 2017 12:41:58 -0800 Subject: [PATCH] Print a warning when cocoapods specs repo is out of date (#12915) --- .../flutter_tools/lib/src/ios/cocoapods.dart | 15 +++++- .../test/ios/cocoapods_test.dart | 46 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/packages/flutter_tools/lib/src/ios/cocoapods.dart b/packages/flutter_tools/lib/src/ios/cocoapods.dart index e2ed2a3df9..8fba49d554 100644 --- a/packages/flutter_tools/lib/src/ios/cocoapods.dart +++ b/packages/flutter_tools/lib/src/ios/cocoapods.dart @@ -133,7 +133,20 @@ class CocoaPods { printStatus(result.stderr, indent: 4); } } - if (result.exitCode != 0) + if (result.exitCode != 0) { + _diagnosePodInstallFailure(result); throwToolExit('Error running pod install'); + } + } + + void _diagnosePodInstallFailure(ProcessResult result) { + if (result.stdout is String && result.stdout.contains('out-of-date source repos')) { + printError( + "Error: CocoaPods's specs repository is too out-of-date to satisfy dependencies.\n" + 'To update the CocoaPods specs, run:\n' + ' pod repo update\n', + emphasis: true, + ); + } } } diff --git a/packages/flutter_tools/test/ios/cocoapods_test.dart b/packages/flutter_tools/test/ios/cocoapods_test.dart index db9baaeec3..493468fae8 100644 --- a/packages/flutter_tools/test/ios/cocoapods_test.dart +++ b/packages/flutter_tools/test/ios/cocoapods_test.dart @@ -131,6 +131,52 @@ void main() { ProcessManager: () => mockProcessManager, }, ); + + testUsingContext( + 'outdated specs repo should print error', + () async { + fs.file(fs.path.join('project', 'ios', 'Podfile')) + ..createSync() + ..writeAsString('Existing Podfile'); + + when(mockProcessManager.run( + ['pod', 'install', '--verbose'], + workingDirectory: 'project/ios', + environment: {'FLUTTER_FRAMEWORK_DIR': 'engine/path', 'COCOAPODS_DISABLE_STATS': 'true'}, + )).thenReturn(new ProcessResult( + 1, + 1, + ''' +[!] Unable to satisfy the following requirements: + +- `Firebase/Auth` required by `Podfile` +- `Firebase/Auth (= 4.0.0)` required by `Podfile.lock` + +None of your spec sources contain a spec satisfying the dependencies: `Firebase/Auth, Firebase/Auth (= 4.0.0)`. + +You have either: + * out-of-date source repos which you can update with `pod repo update` or with `pod install --repo-update`. + * mistyped the name or version. + * not added the source repo that hosts the Podspec to your Podfile. + +Note: as of CocoaPods 1.0, `pod repo update` does not happen on `pod install` by default.''', + '', + )); + try { + await cocoaPodsUnderTest.processPods( + appIosDir: projectUnderTest, + iosEngineDir: 'engine/path', + ); expect(fs.file(fs.path.join('project', 'ios', 'Podfile')).readAsStringSync() , 'Existing Podfile'); + fail('Exception expected'); + } catch (ToolExit) { + expect(testLogger.errorText, contains("CocoaPods's specs repository is too out-of-date to satisfy dependencies")); + } + }, + overrides: { + FileSystem: () => fs, + ProcessManager: () => mockProcessManager, + }, + ); } class MockProcessManager extends Mock implements ProcessManager {}