From a4883de38f0e3c1abb44043fb874350f77092369 Mon Sep 17 00:00:00 2001 From: Jakob Andersen Date: Wed, 8 Mar 2017 05:34:38 +0100 Subject: [PATCH] Run 'pod install' before building iOS app. (#8609) Since iOS builds are CocoaPods enabled by default, we should make sure to run `pod install` to get pods wired up before building the app. Also added a check to `flutter doctor` to verify CocoaPods is installed. I'm passing FLUTTER_FRAMEWORK_DIR to the `pod install` command, so we can have the app's Podfile link in Flutter.framework as a pod instead of having to copy it over in xcode_backend.sh. --- .../flutter_tools/lib/src/base/process.dart | 5 ++++- .../lib/src/ios/ios_workflow.dart | 18 +++++++++++++++++- packages/flutter_tools/lib/src/ios/mac.dart | 14 +++++++++++++- .../flutter_tools/lib/src/ios/xcodeproj.dart | 7 +++++-- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/packages/flutter_tools/lib/src/base/process.dart b/packages/flutter_tools/lib/src/base/process.dart index 7922904324..04a3c6fcc1 100644 --- a/packages/flutter_tools/lib/src/base/process.dart +++ b/packages/flutter_tools/lib/src/base/process.dart @@ -211,6 +211,7 @@ String runCheckedSync(List cmd, { String workingDirectory, bool allowReentrantFlutter: false, bool hideStdout: false, + Map environment, }) { return _runWithLoggingSync( cmd, @@ -219,6 +220,7 @@ String runCheckedSync(List cmd, { hideStdout: hideStdout, checked: true, noisyErrors: true, + environment: environment, ); } @@ -259,12 +261,13 @@ String _runWithLoggingSync(List cmd, { String workingDirectory, bool allowReentrantFlutter: false, bool hideStdout: false, + Map 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(' ')}'); diff --git a/packages/flutter_tools/lib/src/ios/ios_workflow.dart b/packages/flutter_tools/lib/src/ios/ios_workflow.dart index 5549284015..fd5779ad70 100644 --- a/packages/flutter_tools/lib/src/ios/ios_workflow.dart +++ b/packages/flutter_tools/lib/src/ios/ios_workflow.dart @@ -41,6 +41,10 @@ class IOSWorkflow extends DoctorValidator implements Workflow { bool get hasPythonSixModule => exitsHappy(['python', '-c', 'import six']); + bool get hasCocoaPods => exitsHappy(['pod', '--version']); + + String get cocoaPodsVersionText => runSync(['pod', '--version']).trim(); + bool get _iosDeployIsInstalledAndMeetsVersionCheck { if (!hasIosDeploy) return false; @@ -58,6 +62,7 @@ class IOSWorkflow extends DoctorValidator implements Workflow { ValidationType xcodeStatus = ValidationType.missing; ValidationType pythonStatus = ValidationType.missing; ValidationType brewStatus = ValidationType.missing; + ValidationType podStatus = ValidationType.missing; String xcodeVersionInfo; if (xcode.isInstalled) { @@ -160,8 +165,19 @@ class IOSWorkflow extends DoctorValidator implements Workflow { )); } + if (hasCocoaPods) { + podStatus = ValidationType.installed; + messages.add(new ValidationMessage('CocoaPods version $cocoaPodsVersionText')); + } else { + podStatus = ValidationType.missing; + messages.add(new ValidationMessage.error( + 'CocoaPods not installed; this is used for iOS development.\n' + 'Install by running: \'sudo gem install cocoapods\'' + )); + } + return new ValidationResult( - [xcodeStatus, pythonStatus, brewStatus].reduce(_mergeValidationTypes), + [xcodeStatus, pythonStatus, brewStatus, podStatus].reduce(_mergeValidationTypes), messages, statusInfo: xcodeVersionInfo ); diff --git a/packages/flutter_tools/lib/src/ios/mac.dart b/packages/flutter_tools/lib/src/ios/mac.dart index 26b6c93e47..aa3e8c8ce6 100644 --- a/packages/flutter_tools/lib/src/ios/mac.dart +++ b/packages/flutter_tools/lib/src/ios/mac.dart @@ -123,8 +123,10 @@ Future 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)); + _installCocoaPods(appDirectory, flutterFrameworkDir(mode)); final List commands = [ '/usr/bin/env', @@ -315,6 +317,16 @@ bool _checkXcodeVersion() { return true; } +void _installCocoaPods(Directory bundle, String engineDirectory) { + if (fs.file(fs.path.join(bundle.path, 'Podfile')).existsSync()) { + runCheckedSync( + ['pod', 'install'], + workingDirectory: bundle.path, + environment: {'FLUTTER_FRAMEWORK_DIR': engineDirectory}, + ); + } +} + Future _addServicesToBundle(Directory bundle) async { final List> services = >[]; printTrace("Trying to resolve native pub services."); diff --git a/packages/flutter_tools/lib/src/ios/xcodeproj.dart b/packages/flutter_tools/lib/src/ios/xcodeproj.dart index c32ab15d91..73f0afa627 100644 --- a/packages/flutter_tools/lib/src/ios/xcodeproj.dart +++ b/packages/flutter_tools/lib/src/ios/xcodeproj.dart @@ -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;