forked from firka/flutter
Enable developers to run pod from terminal directly and skip pod install if possible. (#13374)
Avoids running pod install if .flutter-plugins and its flutter framework pod dependency didn't change
This commit is contained in:
@@ -24,7 +24,7 @@ class InjectPluginsCommand extends FlutterCommand {
|
||||
|
||||
@override
|
||||
Future<Null> runCommand() async {
|
||||
final bool result = injectPlugins();
|
||||
final bool result = injectPlugins().hasPlugin;
|
||||
if (result) {
|
||||
printStatus('GeneratedPluginRegistrants successfully written.');
|
||||
} else {
|
||||
|
||||
@@ -57,15 +57,17 @@ class CocoaPods {
|
||||
|
||||
Future<Null> processPods({
|
||||
@required Directory appIosDir,
|
||||
@required String iosEngineDir,
|
||||
bool isSwift: false,
|
||||
bool pluginOrFlutterPodChanged: true,
|
||||
}) async {
|
||||
if (await _checkPodCondition()) {
|
||||
if (!fs.file(fs.path.join(appIosDir.path, 'Podfile')).existsSync()) {
|
||||
await _createPodfile(appIosDir, isSwift);
|
||||
} // TODO(xster): Add more logic for handling merge conflicts.
|
||||
|
||||
await _runPodInstall(appIosDir, iosEngineDir);
|
||||
if (_checkIfRunPodInstall(appIosDir.path, pluginOrFlutterPodChanged))
|
||||
await _runPodInstall(appIosDir);
|
||||
} else {
|
||||
throwToolExit('CocoaPods not available for project using Flutter plugins');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,13 +110,12 @@ class CocoaPods {
|
||||
podfileTemplate.copySync(fs.path.join(bundle.path, 'Podfile'));
|
||||
}
|
||||
|
||||
Future<Null> _runPodInstall(Directory bundle, String engineDirectory) async {
|
||||
Future<Null> _runPodInstall(Directory bundle) async {
|
||||
final Status status = logger.startProgress('Running pod install...', expectSlowOperation: true);
|
||||
final ProcessResult result = await processManager.run(
|
||||
<String>['pod', 'install', '--verbose'],
|
||||
workingDirectory: bundle.path,
|
||||
environment: <String, String>{
|
||||
'FLUTTER_FRAMEWORK_DIR': engineDirectory,
|
||||
// See https://github.com/flutter/flutter/issues/10873.
|
||||
// CocoaPods analytics adds a lot of latency.
|
||||
'COCOAPODS_DISABLE_STATS': 'true',
|
||||
@@ -137,6 +138,28 @@ class CocoaPods {
|
||||
}
|
||||
}
|
||||
|
||||
// Check if you need to run pod install.
|
||||
// The pod install will run if any of below is true.
|
||||
// 1.Any plugins changed (add/update/delete)
|
||||
// 2.The flutter.framework has changed (debug/release/profile)
|
||||
// 3.The podfile.lock doesn't exists
|
||||
// 4.The Pods/manifest.lock doesn't exists
|
||||
// 5.The podfile.lock doesn't match Pods/manifest.lock.
|
||||
bool _checkIfRunPodInstall(String appDir, bool pluginOrFlutterPodChanged) {
|
||||
if (pluginOrFlutterPodChanged)
|
||||
return true;
|
||||
// Check if podfile.lock and Pods/Manifest.lock exists and matches.
|
||||
final File podfileLockFile = fs.file(fs.path.join(appDir, 'Podfile.lock'));
|
||||
final File manifestLockFile =
|
||||
fs.file(fs.path.join(appDir, 'Pods', 'Manifest.lock'));
|
||||
if (!podfileLockFile.existsSync() ||
|
||||
!manifestLockFile.existsSync() ||
|
||||
podfileLockFile.readAsStringSync() !=
|
||||
manifestLockFile.readAsStringSync())
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void _diagnosePodInstallFailure(ProcessResult result) {
|
||||
if (result.stdout is String && result.stdout.contains('out-of-date source repos')) {
|
||||
printError(
|
||||
|
||||
@@ -254,14 +254,9 @@ Future<XcodeBuildResult> buildXcodeProject({
|
||||
// copied over to a location that is suitable for Xcodebuild to find them.
|
||||
final Directory appDirectory = fs.directory(app.appDirectory);
|
||||
await _addServicesToBundle(appDirectory);
|
||||
final bool hasFlutterPlugins = injectPlugins();
|
||||
|
||||
if (hasFlutterPlugins)
|
||||
await cocoaPods.processPods(
|
||||
appIosDir: appDirectory,
|
||||
iosEngineDir: flutterFrameworkDir(buildInfo.mode),
|
||||
isSwift: app.isSwift,
|
||||
);
|
||||
final InjectPluginsResult injectionResult = injectPlugins();
|
||||
final bool hasFlutterPlugins = injectionResult.hasPlugin;
|
||||
final String priorGeneratedXCConfig = readGeneratedXCConfig(app.appDirectory);
|
||||
|
||||
updateXcodeGeneratedProperties(
|
||||
projectPath: fs.currentDirectory.path,
|
||||
@@ -271,6 +266,15 @@ Future<XcodeBuildResult> buildXcodeProject({
|
||||
previewDart2: buildInfo.previewDart2,
|
||||
);
|
||||
|
||||
if (hasFlutterPlugins) {
|
||||
final String currentGeneratedXCConfig = readGeneratedXCConfig(app.appDirectory);
|
||||
await cocoaPods.processPods(
|
||||
appIosDir: appDirectory,
|
||||
isSwift: app.isSwift,
|
||||
pluginOrFlutterPodChanged: (injectionResult.hasChanged ||
|
||||
priorGeneratedXCConfig != currentGeneratedXCConfig));
|
||||
}
|
||||
|
||||
final List<String> commands = <String>[
|
||||
'/usr/bin/env',
|
||||
'xcrun',
|
||||
@@ -355,7 +359,17 @@ Future<XcodeBuildResult> buildXcodeProject({
|
||||
}
|
||||
}
|
||||
|
||||
Future<Null> diagnoseXcodeBuildFailure(XcodeBuildResult result, BuildableIOSApp app) async {
|
||||
String readGeneratedXCConfig(String appPath) {
|
||||
final String generateXCConfigPath =
|
||||
fs.path.join(fs.currentDirectory.path, appPath, 'Flutter','Generated.xcconfig');
|
||||
final File generateXCConfigFile = fs.file(generateXCConfigPath);
|
||||
if (!generateXCConfigFile.existsSync())
|
||||
return null;
|
||||
return generateXCConfigFile.readAsStringSync();
|
||||
}
|
||||
|
||||
Future<Null> diagnoseXcodeBuildFailure(
|
||||
XcodeBuildResult result, BuildableIOSApp app) async {
|
||||
if (result.xcodeBuildExecution != null &&
|
||||
result.xcodeBuildExecution.buildForPhysicalDevice &&
|
||||
result.stdout?.contains('BCEROR') == true &&
|
||||
|
||||
@@ -77,8 +77,10 @@ List<Plugin> _findPlugins(String directory) {
|
||||
return plugins;
|
||||
}
|
||||
|
||||
void _writeFlutterPluginsList(String directory, List<Plugin> plugins) {
|
||||
// Return true if .flutter-plugins has changed, otherwise return false.
|
||||
bool _writeFlutterPluginsList(String directory, List<Plugin> plugins) {
|
||||
final File pluginsProperties = fs.file(fs.path.join(directory, '.flutter-plugins'));
|
||||
final String priorFlutterPlugins = (pluginsProperties.existsSync() ? pluginsProperties.readAsStringSync() : null);
|
||||
final String pluginManifest =
|
||||
plugins.map((Plugin p) => '${p.name}=${escapePath(p.path)}').join('\n');
|
||||
if (pluginManifest.isNotEmpty) {
|
||||
@@ -88,6 +90,8 @@ void _writeFlutterPluginsList(String directory, List<Plugin> plugins) {
|
||||
pluginsProperties.deleteSync();
|
||||
}
|
||||
}
|
||||
final String currentFlutterPlugins = (pluginsProperties.existsSync() ? pluginsProperties.readAsStringSync() : null);
|
||||
return currentFlutterPlugins != priorFlutterPlugins;
|
||||
}
|
||||
|
||||
const String _androidPluginRegistryTemplate = '''package io.flutter.plugins;
|
||||
@@ -206,17 +210,25 @@ void _writeIOSPluginRegistry(String directory, List<Plugin> plugins) {
|
||||
|
||||
}
|
||||
|
||||
class InjectPluginsResult{
|
||||
InjectPluginsResult({this.hasPlugin : false, this.hasChanged : false});
|
||||
/// True if any flutter plugin exists, otherwise false.
|
||||
final bool hasPlugin;
|
||||
/// True if plugins have changed since last build.
|
||||
final bool hasChanged;
|
||||
}
|
||||
|
||||
/// Finds Flutter plugins in the pubspec.yaml, creates platform injection
|
||||
/// registries classes and add them to the build dependencies.
|
||||
///
|
||||
/// Returns whether any Flutter plugins are added.
|
||||
bool injectPlugins({String directory}) {
|
||||
InjectPluginsResult injectPlugins({String directory}) {
|
||||
directory ??= fs.currentDirectory.path;
|
||||
final List<Plugin> plugins = _findPlugins(directory);
|
||||
_writeFlutterPluginsList(directory, plugins);
|
||||
final bool hasPluginsChanged = _writeFlutterPluginsList(directory, plugins);
|
||||
if (fs.isDirectorySync(fs.path.join(directory, 'android')))
|
||||
_writeAndroidPluginRegistry(directory, plugins);
|
||||
if (fs.isDirectorySync(fs.path.join(directory, 'ios')))
|
||||
_writeIOSPluginRegistry(directory, plugins);
|
||||
return plugins.isNotEmpty;
|
||||
}
|
||||
return new InjectPluginsResult(hasPlugin: plugins.isNotEmpty, hasChanged: hasPluginsChanged);
|
||||
}
|
||||
Reference in New Issue
Block a user