Skip to content

Commit

Permalink
Make pod install a long-running step. (flutter#8999)
Browse files Browse the repository at this point in the history
The very first time `pod install` is invoked, CocoaPods downloads the master spec repository, which takes quite a while. Before this change, the build appeared to have stalled. With this change, at least the spinner is moving.

Added `pod setup` to the install instructions for CocoaPods, so the spec repo is downloaded while setting up Flutter, instead of during the first build.
  • Loading branch information
jakobr-google authored Mar 27, 2017
1 parent 5a10102 commit eedc5d9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
21 changes: 19 additions & 2 deletions packages/flutter_tools/lib/src/base/process.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,36 @@ Future<Process> runDetached(List<String> cmd) {

Future<RunResult> runAsync(List<String> cmd, {
String workingDirectory,
bool allowReentrantFlutter: false
bool allowReentrantFlutter: false,
Map<String, String> environment
}) async {
_traceCommand(cmd, workingDirectory: workingDirectory);
final ProcessResult results = await processManager.run(
cmd,
workingDirectory: workingDirectory,
environment: _environment(allowReentrantFlutter),
environment: _environment(allowReentrantFlutter, environment),
);
final RunResult runResults = new RunResult(results);
printTrace(runResults.toString());
return runResults;
}

Future<RunResult> runCheckedAsync(List<String> cmd, {
String workingDirectory,
bool allowReentrantFlutter: false,
Map<String, String> environment
}) async {
final RunResult result = await runAsync(
cmd,
workingDirectory: workingDirectory,
allowReentrantFlutter: allowReentrantFlutter,
environment: environment
);
if (result.exitCode != 0)
throw 'Exit code ${result.exitCode} from: ${cmd.join(' ')}';
return result;
}

bool exitsHappy(List<String> cli) {
_traceCommand(cli);
try {
Expand Down
5 changes: 1 addition & 4 deletions packages/flutter_tools/lib/src/commands/build_ios.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import 'dart:async';

import '../application_package.dart';
import '../base/common.dart';
import '../base/logger.dart';
import '../base/utils.dart';
import '../build_info.dart';
import '../globals.dart';
Expand Down Expand Up @@ -64,16 +63,14 @@ class BuildIOSCommand extends BuildSubCommand {
final String logTarget = forSimulator ? 'simulator' : 'device';

final String typeName = artifacts.getEngineType(TargetPlatform.ios, getBuildMode());
final Status status = logger.startProgress('Building $app for $logTarget ($typeName)...',
expectSlowOperation: true);
printStatus('Building $app for $logTarget ($typeName)...');
final XcodeBuildResult result = await buildXcodeProject(
app: app,
mode: getBuildMode(),
target: targetFile,
buildForDevice: !forSimulator,
codesign: shouldCodesign
);
status.stop();

if (!result.success) {
await diagnoseXcodeBuildFailure(result);
Expand Down
6 changes: 4 additions & 2 deletions packages/flutter_tools/lib/src/ios/ios_workflow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,15 @@ class IOSWorkflow extends DoctorValidator implements Workflow {
messages.add(new ValidationMessage.error(
'CocoaPods not installed. To install:\n'
'brew update\n'
'brew install cocoapods'
'brew install cocoapods\n'
'pod setup'
));
} else {
messages.add(new ValidationMessage.error(
'CocoaPods out of date ($cocoaPodsMinimumVersion is required). To upgrade:\n'
'brew update\n'
'brew upgrade cocoapods'
'brew upgrade cocoapods\n'
'pod setup'
));
}
}
Expand Down
11 changes: 8 additions & 3 deletions packages/flutter_tools/lib/src/ios/mac.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import '../application_package.dart';
import '../base/context.dart';
import '../base/common.dart';
import '../base/file_system.dart';
import '../base/logger.dart';
import '../base/io.dart';
import '../base/platform.dart';
import '../base/process.dart';
Expand Down Expand Up @@ -130,7 +131,7 @@ Future<XcodeBuildResult> buildXcodeProject({
await _addServicesToBundle(appDirectory);
writeFlutterPluginsList();

_runPodInstall(appDirectory, flutterFrameworkDir(mode));
await _runPodInstall(appDirectory, flutterFrameworkDir(mode));

final List<String> commands = <String>[
'/usr/bin/env',
Expand Down Expand Up @@ -170,11 +171,13 @@ Future<XcodeBuildResult> buildXcodeProject({
);
}

final Status status = logger.startProgress('Running Xcode build...', expectSlowOperation: true);
final RunResult result = await runAsync(
commands,
workingDirectory: app.appDirectory,
allowReentrantFlutter: true
);
status.stop();

if (result.exitCode != 0) {
printStatus('Failed to build iOS app');
Expand Down Expand Up @@ -321,19 +324,21 @@ bool _checkXcodeVersion() {
return true;
}

void _runPodInstall(Directory bundle, String engineDirectory) {
Future<Null> _runPodInstall(Directory bundle, String engineDirectory) async {
if (fs.file(fs.path.join(bundle.path, 'Podfile')).existsSync()) {
if (!doctor.iosWorkflow.cocoaPodsInstalledAndMeetsVersionCheck) {
final String minimumVersion = doctor.iosWorkflow.cocoaPodsMinimumVersion;
printError('Warning: CocoaPods version $minimumVersion or greater not installed. Skipping pod install.');
return;
}
try {
runCheckedSync(
final Status status = logger.startProgress('Running pod install...', expectSlowOperation: true);
await runCheckedAsync(
<String>['pod', 'install'],
workingDirectory: bundle.path,
environment: <String, String>{'FLUTTER_FRAMEWORK_DIR': engineDirectory},
);
status.stop();
} catch (e) {
throwToolExit('Error running pod install: $e');
}
Expand Down

0 comments on commit eedc5d9

Please sign in to comment.