Add readlink -f flag to CocoaPods script to workaround Xcode 14.3 issue (#124062)

This commit is contained in:
Jenn Magder
2023-04-03 16:55:00 -07:00
committed by GitHub
parent d32dc71223
commit d4934fb6ab
5 changed files with 223 additions and 0 deletions

View File

@@ -13,10 +13,12 @@ import '../base/logger.dart';
import '../base/os.dart';
import '../base/platform.dart';
import '../base/process.dart';
import '../base/project_migrator.dart';
import '../base/version.dart';
import '../build_info.dart';
import '../cache.dart';
import '../ios/xcodeproj.dart';
import '../migrations/cocoapods_script_symlink.dart';
import '../reporting/reporting.dart';
import '../xcode_project.dart';
@@ -166,6 +168,13 @@ class CocoaPods {
throwToolExit('CocoaPods not installed or not in valid state.');
}
await _runPodInstall(xcodeProject, buildMode);
// This migrator works around a CocoaPods bug, and should be run after `pod install` is run.
final ProjectMigration postPodMigration = ProjectMigration(<ProjectMigrator>[
CocoaPodsScriptReadlink(xcodeProject, _xcodeProjectInterpreter, _logger),
]);
postPodMigration.run();
podsProcessed = true;
}
return podsProcessed;

View File

@@ -0,0 +1,52 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../base/file_system.dart';
import '../base/project_migrator.dart';
import '../base/version.dart';
import '../ios/xcodeproj.dart';
import '../xcode_project.dart';
// Xcode 14.3 changed the readlink symlink behavior to be relative from the script working directory, instead of the
// relative path of the symlink. The -f flag returns the original "--canonicalize" behavior the CocoaPods script relies on.
// This has been fixed upstream in CocoaPods, but migrate a copy of their workaround so users don't need to update.
//
// See https://github.com/flutter/flutter/issues/123890#issuecomment-1494825976.
class CocoaPodsScriptReadlink extends ProjectMigrator {
CocoaPodsScriptReadlink(
XcodeBasedProject project,
XcodeProjectInterpreter xcodeProjectInterpreter,
super.logger,
) : _podRunnerFrameworksScript = project.podRunnerFrameworksScript,
_xcodeProjectInterpreter = xcodeProjectInterpreter;
final File _podRunnerFrameworksScript;
final XcodeProjectInterpreter _xcodeProjectInterpreter;
@override
void migrate() {
if (!_podRunnerFrameworksScript.existsSync()) {
logger.printTrace('CocoaPods Pods-Runner-frameworks.sh script not found, skipping "readlink -f" workaround.');
return;
}
final Version? version = _xcodeProjectInterpreter.version;
// If Xcode not installed or less than 14.3 with readlink behavior change, skip this migration.
if (version == null || version < Version(14, 3, 0)) {
logger.printTrace('Detected Xcode version is $version, below 14.3, skipping "readlink -f" workaround.');
return;
}
processFileLines(_podRunnerFrameworksScript);
}
@override
String? migrateLine(String line) {
const String originalReadLinkLine = r'source="$(readlink "${source}")"';
const String replacementReadLinkLine = r'source="$(readlink -f "${source}")"';
return line.replaceAll(originalReadLinkLine, replacementReadLinkLine);
}
}

View File

@@ -89,6 +89,13 @@ abstract class XcodeBasedProject extends FlutterProjectPlatform {
/// The CocoaPods 'Manifest.lock'.
File get podManifestLock => hostAppRoot.childDirectory('Pods').childFile('Manifest.lock');
/// The CocoaPods generated 'Pods-Runner-frameworks.sh'.
File get podRunnerFrameworksScript => hostAppRoot
.childDirectory('Pods')
.childDirectory('Target Support Files')
.childDirectory('Pods-Runner')
.childFile('Pods-Runner-frameworks.sh');
}
/// Represents the iOS sub-project of a Flutter project.