CocoaPods flow step 3 - don't automatically pod setup (#9703)

* Don’t automatically pod setup if the user never did it

* fix/add test

* rename getters
This commit is contained in:
xster 2017-05-02 16:11:37 -07:00 committed by GitHub
parent 7fb6646c96
commit 85b2b86939
3 changed files with 65 additions and 8 deletions

View file

@ -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<ValidationResult> validate() async {
final List<ValidationMessage> messages = <ValidationMessage>[];
@ -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) {

View file

@ -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<Null> _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<Null> _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(

View file

@ -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: <Type, Generator>{ 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: <Type, Generator>{
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: <Type, Generator>{
FileSystem: () => fs,
Xcode: () => xcode,
ProcessManager: () => processManager,
});