Revert "Eliminate CocoaPods install step (#8694)" (#8705)

* Revert "Eliminate CocoaPods install step (#8694)"

This reverts commit f4a13bc72b.

If the developer is relying on CocoaPods and hasn't done a pod install, we will do it for them. This is needed for a smooth native plugin experience, similar to what Gradle is doing on the Android side.

There's no hard dependency on CocoaPods. We only run pod install if the project uses CocoaPods, so developers are still free to use alternatives if they prefer (and if they don't want to use native plugins).

Fixes #8685
Fixes #8657
Fixes #8526

* Require CocoaPods 1.0.0 or newer.

And make sure we don't get a crash if running `pod install` fails.

* Address review feedback
This commit is contained in:
Jakob Andersen
2017-03-10 13:43:57 +01:00
committed by GitHub
parent c22812e0ea
commit 60c0c3d323
5 changed files with 67 additions and 6 deletions

View File

@@ -211,6 +211,7 @@ String runCheckedSync(List<String> cmd, {
String workingDirectory,
bool allowReentrantFlutter: false,
bool hideStdout: false,
Map<String, String> environment,
}) {
return _runWithLoggingSync(
cmd,
@@ -219,6 +220,7 @@ String runCheckedSync(List<String> cmd, {
hideStdout: hideStdout,
checked: true,
noisyErrors: true,
environment: environment,
);
}
@@ -259,12 +261,13 @@ String _runWithLoggingSync(List<String> cmd, {
String workingDirectory,
bool allowReentrantFlutter: false,
bool hideStdout: false,
Map<String, String> environment,
}) {
_traceCommand(cmd, workingDirectory: workingDirectory);
final ProcessResult results = processManager.runSync(
cmd,
workingDirectory: workingDirectory,
environment: _environment(allowReentrantFlutter),
environment: _environment(allowReentrantFlutter, environment),
);
printTrace('Exit code ${results.exitCode} from: ${cmd.join(' ')}');

View File

@@ -41,7 +41,6 @@ class Doctor {
IOSWorkflow _iosWorkflow;
AndroidWorkflow _androidWorkflow;
/// This can return null for platforms that don't support developing for iOS.
IOSWorkflow get iosWorkflow => _iosWorkflow;
AndroidWorkflow get androidWorkflow => _androidWorkflow;

View File

@@ -41,6 +41,12 @@ class IOSWorkflow extends DoctorValidator implements Workflow {
bool get hasPythonSixModule => exitsHappy(<String>['python', '-c', 'import six']);
bool get hasCocoaPods => exitsHappy(<String>['pod', '--version']);
String get cocoaPodsMinimumVersion => '1.0.0';
String get cocoaPodsVersionText => runSync(<String>['pod', '--version']).trim();
bool get _iosDeployIsInstalledAndMeetsVersionCheck {
if (!hasIosDeploy)
return false;
@@ -52,6 +58,17 @@ class IOSWorkflow extends DoctorValidator implements Workflow {
}
}
bool get _cocoaPodsInstalledAndMeetsVersionCheck {
if (!hasCocoaPods)
return false;
try {
final Version installedVersion = new Version.parse(cocoaPodsVersionText);
return installedVersion >= new Version.parse(cocoaPodsMinimumVersion);
} on FormatException {
return false;
}
}
@override
Future<ValidationResult> validate() async {
final List<ValidationMessage> messages = <ValidationMessage>[];
@@ -159,6 +176,23 @@ class IOSWorkflow extends DoctorValidator implements Workflow {
));
}
}
if (_cocoaPodsInstalledAndMeetsVersionCheck) {
messages.add(new ValidationMessage('CocoaPods version $cocoaPodsVersionText'));
} else {
if (!hasCocoaPods) {
messages.add(new ValidationMessage.error(
'CocoaPods not installed. To install:\n'
'brew update\n'
'brew install cocoapods'
));
} else {
messages.add(new ValidationMessage.error(
'CocoaPods out of date ($cocoaPodsMinimumVersion is required). To upgrade:\n'
'brew update\n'
'brew upgrade cocoapods'
));
}
}
} else {
brewStatus = ValidationType.missing;
messages.add(new ValidationMessage.error(

View File

@@ -9,12 +9,14 @@ import 'package:meta/meta.dart';
import '../application_package.dart';
import '../base/context.dart';
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/io.dart';
import '../base/platform.dart';
import '../base/process.dart';
import '../base/process_manager.dart';
import '../build_info.dart';
import '../doctor.dart';
import '../flx.dart' as flx;
import '../globals.dart';
import '../services.dart';
@@ -123,8 +125,10 @@ Future<XcodeBuildResult> buildXcodeProject({
// Before the build, all service definitions must be updated and the dylibs
// copied over to a location that is suitable for Xcodebuild to find them.
final Directory appDirectory = fs.directory(app.appDirectory);
await _addServicesToBundle(appDirectory);
await _addServicesToBundle(fs.directory(app.appDirectory));
_runPodInstall(appDirectory, flutterFrameworkDir(mode));
final List<String> commands = <String>[
'/usr/bin/env',
@@ -309,12 +313,30 @@ bool _checkXcodeVersion() {
return false;
}
} catch (e) {
printError('Cannot find "xcodebuid". $_xcodeRequirement');
printError('Cannot find "xcodebuild". $_xcodeRequirement');
return false;
}
return true;
}
void _runPodInstall(Directory bundle, String engineDirectory) {
if (fs.file(fs.path.join(bundle.path, 'Podfile')).existsSync()) {
if (!doctor.iosWorkflow.hasCocoaPods) {
printError('Warning: CocoaPods not installed. Not running pod install.');
return;
}
try {
runCheckedSync(
<String>['pod', 'install'],
workingDirectory: bundle.path,
environment: <String, String>{'FLUTTER_FRAMEWORK_DIR': engineDirectory},
);
} catch (e) {
throwToolExit('Error running pod install: $e');
}
}
}
Future<Null> _addServicesToBundle(Directory bundle) async {
final List<Map<String, String>> services = <Map<String, String>>[];
printTrace("Trying to resolve native pub services.");

View File

@@ -12,6 +12,10 @@ import '../globals.dart';
final RegExp _settingExpr = new RegExp(r'(\w+)\s*=\s*(\S+)');
final RegExp _varExpr = new RegExp(r'\$\((.*)\)');
String flutterFrameworkDir(BuildMode mode) {
return fs.path.normalize(fs.path.dirname(artifacts.getArtifactPath(Artifact.flutterFramework, TargetPlatform.ios, mode)));
}
void updateXcodeGeneratedProperties(String projectPath, BuildMode mode, String target) {
final StringBuffer localsBuffer = new StringBuffer();
@@ -34,8 +38,7 @@ void updateXcodeGeneratedProperties(String projectPath, BuildMode mode, String t
localsBuffer.writeln('SYMROOT=\${SOURCE_ROOT}/../${getIosBuildDirectory()}');
final String flutterFrameworkDir = fs.path.normalize(fs.path.dirname(artifacts.getArtifactPath(Artifact.flutterFramework, TargetPlatform.ios, mode)));
localsBuffer.writeln('FLUTTER_FRAMEWORK_DIR=$flutterFrameworkDir');
localsBuffer.writeln('FLUTTER_FRAMEWORK_DIR=${flutterFrameworkDir(mode)}');
if (artifacts is LocalEngineArtifacts) {
final LocalEngineArtifacts localEngineArtifacts = artifacts;