Skip to content

Commit

Permalink
[Doctor] Improve CocoaPods messages (#146701)
Browse files Browse the repository at this point in the history
This tweaks the Flutter doctor messages for CocoaPods.

This also switches the "unknown version" error to link to the update instructions instead of the installation instructions; the user has already installed CocoaPods in this scenario.

Example error before:

```
    � CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
```

Example error after:

```
    � CocoaPods not installed.
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      For installation instructions, see https://guides.cocoapods.org/using/getting-started.html#installation
```
  • Loading branch information
loic-sharma authored Apr 15, 2024
1 parent 2e748e8 commit 882bcbb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
8 changes: 4 additions & 4 deletions packages/flutter_tools/lib/src/base/user_messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,19 @@ class UserMessages {
String cocoaPodsMissing(String consequence, String installInstructions) =>
'CocoaPods not installed.\n'
'$consequence\n'
'To install $installInstructions';
'For installation instructions, $installInstructions';
String cocoaPodsUnknownVersion(String consequence, String upgradeInstructions) =>
'Unknown CocoaPods version installed.\n'
'$consequence\n'
'To upgrade $upgradeInstructions';
'To update CocoaPods, $upgradeInstructions';
String cocoaPodsOutdated(String currentVersion, String recVersion, String consequence, String upgradeInstructions) =>
'CocoaPods $currentVersion out of date ($recVersion is recommended).\n'
'$consequence\n'
'To upgrade $upgradeInstructions';
'To update CocoaPods, $upgradeInstructions';
String cocoaPodsBrokenInstall(String consequence, String reinstallInstructions) =>
'CocoaPods installed but not working.\n'
'$consequence\n'
'To re-install $reinstallInstructions';
'For re-installation instructions, $reinstallInstructions';

// Messages used in VisualStudioValidator
String visualStudioVersion(String name, String version) => '$name version $version';
Expand Down
16 changes: 8 additions & 8 deletions packages/flutter_tools/lib/src/macos/cocoapods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import '../reporting/reporting.dart';
import '../xcode_project.dart';

const String noCocoaPodsConsequence = '''
CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
CocoaPods is a package manager for iOS or macOS platform code.
Without CocoaPods, plugins will not work on iOS or macOS.
For more info, see https://flutter.dev/platform-plugins''';

Expand All @@ -47,9 +47,9 @@ const String outOfDatePluginsPodfileConsequence = '''
See https://flutter.dev/docs/development/packages-and-plugins/developing-packages#plugin-platforms for details.
If you have local Podfile edits you would like to keep, see https://github.com/flutter/flutter/issues/45197 for instructions.''';

const String cocoaPodsInstallInstructions = 'see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.';
const String cocoaPodsInstallInstructions = 'see https://guides.cocoapods.org/using/getting-started.html#installation';

const String cocoaPodsUpdateInstructions = 'see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods for instructions.';
const String cocoaPodsUpdateInstructions = 'see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods';

const String podfileIosMigrationInstructions = '''
rm ios/Podfile''';
Expand Down Expand Up @@ -200,38 +200,38 @@ class CocoaPods {
_logger.printWarning(
'Warning: CocoaPods not installed. Skipping pod install.\n'
'$noCocoaPodsConsequence\n'
'To install $cocoaPodsInstallInstructions\n',
'For installation instructions, $cocoaPodsInstallInstructions\n',
emphasis: true,
);
return false;
case CocoaPodsStatus.brokenInstall:
_logger.printWarning(
'Warning: CocoaPods is installed but broken. Skipping pod install.\n'
'$brokenCocoaPodsConsequence\n'
'To re-install $cocoaPodsInstallInstructions\n',
'For re-installation instructions, $cocoaPodsInstallInstructions\n',
emphasis: true,
);
return false;
case CocoaPodsStatus.unknownVersion:
_logger.printWarning(
'Warning: Unknown CocoaPods version installed.\n'
'$unknownCocoaPodsConsequence\n'
'To upgrade $cocoaPodsInstallInstructions\n',
'To update CocoaPods, $cocoaPodsUpdateInstructions\n',
emphasis: true,
);
case CocoaPodsStatus.belowMinimumVersion:
_logger.printWarning(
'Warning: CocoaPods minimum required version $cocoaPodsMinimumVersion or greater not installed. Skipping pod install.\n'
'$noCocoaPodsConsequence\n'
'To upgrade $cocoaPodsInstallInstructions\n',
'To update CocoaPods, $cocoaPodsUpdateInstructions\n',
emphasis: true,
);
return false;
case CocoaPodsStatus.belowRecommendedVersion:
_logger.printWarning(
'Warning: CocoaPods recommended version $cocoaPodsRecommendedVersion or greater not installed.\n'
'Pods handling may fail on some projects involving plugins.\n'
'To upgrade $cocoaPodsInstallInstructions\n',
'To update CocoaPods, $cocoaPodsUpdateInstructions\n',
emphasis: true,
);
case CocoaPodsStatus.recommended:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class CocoaPodsValidator extends DoctorValidator {
case CocoaPodsStatus.unknownVersion:
status = ValidationType.partial;
messages.add(ValidationMessage.hint(
_userMessages.cocoaPodsUnknownVersion(unknownCocoaPodsConsequence, cocoaPodsInstallInstructions)));
_userMessages.cocoaPodsUnknownVersion(unknownCocoaPodsConsequence, cocoaPodsUpdateInstructions)));
case CocoaPodsStatus.belowMinimumVersion:
case CocoaPodsStatus.belowRecommendedVersion:
status = ValidationType.partial;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,32 @@ void main() {
final CocoaPodsValidator workflow = CocoaPodsValidator(FakeCocoaPods(CocoaPodsStatus.recommended, '1000.0.0'), UserMessages());
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.success);
expect(result.messages.length, 1);
final ValidationMessage message = result.messages.first;
expect(message.type, ValidationMessageType.information);
expect(message.message, contains('CocoaPods version 1000.0.0'));
});

testWithoutContext('Emits missing status when CocoaPods is not installed', () async {
final CocoaPodsValidator workflow = CocoaPodsValidator(FakeCocoaPods(CocoaPodsStatus.notInstalled), UserMessages());
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.missing);
expect(result.messages.length, 1);
final ValidationMessage message = result.messages.first;
expect(message.type, ValidationMessageType.error);
expect(message.message, contains('CocoaPods not installed'));
expect(message.message, contains('getting-started.html#installation'));
});

testWithoutContext('Emits partial status when CocoaPods is installed with unknown version', () async {
final CocoaPodsValidator workflow = CocoaPodsValidator(FakeCocoaPods(CocoaPodsStatus.unknownVersion), UserMessages());
final ValidationResult result = await workflow.validate();
expect(result.type, ValidationType.partial);
expect(result.messages.length, 1);
final ValidationMessage message = result.messages.first;
expect(message.type, ValidationMessageType.hint);
expect(message.message, contains('Unknown CocoaPods version installed'));
expect(message.message, contains('getting-started.html#updating-cocoapods'));
});

testWithoutContext('Emits partial status when CocoaPods version is too low', () async {
Expand Down

0 comments on commit 882bcbb

Please sign in to comment.