mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
Make FlutterGeneratedPluginSwiftPackage an Xcode root package (#168789)
This PR makes the `FlutterGeneratedPluginSwiftPackage` swift package an Xcode root package. A root package is one that is within the Xcode project as a file reference. See image below:  This change makes it so that when the `FlutterGeneratedPluginSwiftPackage` changes, if Xcode is also open, Xcode will automatically re-resolve the package. This makes Xcode use the new version instead of whatever it had cached. Fixes https://github.com/flutter/flutter/issues/162399 and incremental change towards https://github.com/flutter/flutter/issues/166489. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
This commit is contained in:
parent
154146d0dd
commit
63f9060fb0
@ -165,7 +165,6 @@ Future<XcodeBuildResult> buildXcodeProject({
|
||||
logger: globals.logger,
|
||||
fileSystem: globals.fs,
|
||||
plistParser: globals.plistParser,
|
||||
features: featureFlags,
|
||||
),
|
||||
SwiftPackageManagerGitignoreMigration(project, globals.logger),
|
||||
MetalAPIValidationMigrator.ios(app.project, globals.logger),
|
||||
|
||||
@ -102,7 +102,6 @@ Future<void> buildMacOS({
|
||||
logger: globals.logger,
|
||||
fileSystem: globals.fs,
|
||||
plistParser: globals.plistParser,
|
||||
features: featureFlags,
|
||||
),
|
||||
SwiftPackageManagerGitignoreMigration(flutterProject, globals.logger),
|
||||
MetalAPIValidationMigrator.macos(flutterProject.macos, globals.logger),
|
||||
|
||||
@ -10,6 +10,10 @@ import '../plugins.dart';
|
||||
import '../project.dart';
|
||||
import 'swift_packages.dart';
|
||||
|
||||
/// The name of the Swift package that's generated by the Flutter tool to add
|
||||
/// dependencies on Flutter plugin swift packages.
|
||||
const String kFlutterGeneratedPluginSwiftPackageName = 'FlutterGeneratedPluginSwiftPackage';
|
||||
|
||||
/// Swift Package Manager is a dependency management solution for iOS and macOS
|
||||
/// applications.
|
||||
///
|
||||
@ -28,8 +32,6 @@ class SwiftPackageManager {
|
||||
final FileSystem _fileSystem;
|
||||
final TemplateRenderer _templateRenderer;
|
||||
|
||||
static const String _defaultFlutterPluginsSwiftPackageName = 'FlutterGeneratedPluginSwiftPackage';
|
||||
|
||||
static final SwiftPackageSupportedPlatform iosSwiftPackageSupportedPlatform =
|
||||
SwiftPackageSupportedPlatform(
|
||||
platform: SwiftPackagePlatform.ios,
|
||||
@ -76,19 +78,19 @@ class SwiftPackageManager {
|
||||
// FlutterGeneratedPluginSwiftPackage must be statically linked to ensure
|
||||
// any dynamic dependencies are linked to Runner and prevent undefined symbols.
|
||||
final SwiftPackageProduct generatedProduct = SwiftPackageProduct(
|
||||
name: _defaultFlutterPluginsSwiftPackageName,
|
||||
targets: <String>[_defaultFlutterPluginsSwiftPackageName],
|
||||
name: kFlutterGeneratedPluginSwiftPackageName,
|
||||
targets: <String>[kFlutterGeneratedPluginSwiftPackageName],
|
||||
libraryType: SwiftPackageLibraryType.static,
|
||||
);
|
||||
|
||||
final SwiftPackageTarget generatedTarget = SwiftPackageTarget.defaultTarget(
|
||||
name: _defaultFlutterPluginsSwiftPackageName,
|
||||
name: kFlutterGeneratedPluginSwiftPackageName,
|
||||
dependencies: targetDependencies,
|
||||
);
|
||||
|
||||
final SwiftPackage pluginsPackage = SwiftPackage(
|
||||
manifest: project.flutterPluginSwiftPackageManifest,
|
||||
name: _defaultFlutterPluginsSwiftPackageName,
|
||||
name: kFlutterGeneratedPluginSwiftPackageName,
|
||||
platforms: <SwiftPackageSupportedPlatform>[swiftSupportedPlatform],
|
||||
products: <SwiftPackageProduct>[generatedProduct],
|
||||
dependencies: packageDependencies,
|
||||
|
||||
@ -11,9 +11,9 @@ import '../base/logger.dart';
|
||||
import '../base/project_migrator.dart';
|
||||
import '../build_info.dart';
|
||||
import '../convert.dart';
|
||||
import '../features.dart';
|
||||
import '../ios/plist_parser.dart';
|
||||
import '../ios/xcodeproj.dart';
|
||||
import '../macos/swift_package_manager.dart';
|
||||
import '../project.dart';
|
||||
|
||||
/// Swift Package Manager integration requires changes to the Xcode project's
|
||||
@ -27,7 +27,6 @@ class SwiftPackageManagerIntegrationMigration extends ProjectMigrator {
|
||||
required Logger logger,
|
||||
required FileSystem fileSystem,
|
||||
required PlistParser plistParser,
|
||||
required FeatureFlags features,
|
||||
}) : _xcodeProject = project,
|
||||
_platform = platform,
|
||||
_buildInfo = buildInfo,
|
||||
@ -35,17 +34,15 @@ class SwiftPackageManagerIntegrationMigration extends ProjectMigrator {
|
||||
_xcodeProjectInterpreter = xcodeProjectInterpreter,
|
||||
_fileSystem = fileSystem,
|
||||
_plistParser = plistParser,
|
||||
_features = features,
|
||||
super(logger);
|
||||
|
||||
final XcodeBasedProject _xcodeProject;
|
||||
final SupportedPlatform _platform;
|
||||
final BuildInfo _buildInfo;
|
||||
final BuildInfo? _buildInfo;
|
||||
final XcodeProjectInterpreter _xcodeProjectInterpreter;
|
||||
final FileSystem _fileSystem;
|
||||
final File _xcodeProjectInfoFile;
|
||||
final PlistParser _plistParser;
|
||||
final FeatureFlags _features;
|
||||
|
||||
/// New identifier for FlutterGeneratedPluginSwiftPackage PBXBuildFile.
|
||||
static const String _flutterPluginsSwiftPackageBuildFileIdentifier = '78A318202AECB46A00862997';
|
||||
@ -58,6 +55,15 @@ class SwiftPackageManagerIntegrationMigration extends ProjectMigrator {
|
||||
static const String _flutterPluginsSwiftPackageProductDependencyIdentifier =
|
||||
'78A3181F2AECB46A00862997';
|
||||
|
||||
/// New identifier for FlutterGeneratedPluginSwiftPackage PBXFileReference.
|
||||
static const String _flutterPluginsSwiftPackageFileIdentifer = '78E0A7A72DC9AD7400C4905E';
|
||||
|
||||
/// Existing iOS identifer for Flutter PBXGroup.
|
||||
static const String _iosFlutterGroupIdentifier = '9740EEB11CF90186004384FC';
|
||||
|
||||
/// Existing macOS identifer for Flutter PBXGroup.
|
||||
static const String _macosFlutterGroupIdentifier = '33CEB47122A05771004F2AC0';
|
||||
|
||||
/// Existing iOS identifier for Runner PBXFrameworksBuildPhase.
|
||||
static const String _iosRunnerFrameworksBuildPhaseIdentifier = '97C146EB1CF9000F007C117D';
|
||||
|
||||
@ -95,6 +101,22 @@ class SwiftPackageManagerIntegrationMigration extends ProjectMigrator {
|
||||
return _platform == SupportedPlatform.ios ? _iosProjectIdentifier : _macosProjectIdentifier;
|
||||
}
|
||||
|
||||
String get _flutterGroupIdentifier {
|
||||
return _platform == SupportedPlatform.ios
|
||||
? _iosFlutterGroupIdentifier
|
||||
: _macosFlutterGroupIdentifier;
|
||||
}
|
||||
|
||||
/// The leading path for the `PBXFileReference` relative to the Flutter `PBXGroup`.
|
||||
///
|
||||
/// The actual location for both iOS and macOS is `Flutter/ephemeral`. However,
|
||||
/// including the `Flutter/` prefix for macOS will cause it to resolve to
|
||||
/// `Flutter/Flutter/ephemeral`. This is likely due to the macOS Flutter `PBXGroup`
|
||||
/// using `path` whereas the iOS Flutter `PBXGroup` uses `name`.
|
||||
String get _relativeEphemeralPath {
|
||||
return _platform == SupportedPlatform.ios ? 'Flutter/ephemeral' : 'ephemeral';
|
||||
}
|
||||
|
||||
void restoreFromBackup(SchemeInfo? schemeInfo) {
|
||||
if (backupProjectSettings.existsSync()) {
|
||||
logger.printTrace('Restoring project settings from backup file...');
|
||||
@ -110,7 +132,7 @@ class SwiftPackageManagerIntegrationMigration extends ProjectMigrator {
|
||||
/// will revert any changes made and throw an error.
|
||||
@override
|
||||
Future<void> migrate() async {
|
||||
if (!_features.isSwiftPackageManagerEnabled) {
|
||||
if (!_xcodeProject.usesSwiftPackageManager) {
|
||||
logger.printTrace(
|
||||
'The Swift Package Manager feature is off. '
|
||||
'Skipping the migration that adds Swift Package Manager integration...',
|
||||
@ -139,7 +161,7 @@ class SwiftPackageManagerIntegrationMigration extends ProjectMigrator {
|
||||
// Check for specific strings in the xcscheme and pbxproj to see if the
|
||||
// project has been already migrated, whether automatically or manually.
|
||||
final bool isSchemeMigrated = _isSchemeMigrated(schemeInfo);
|
||||
final bool isPbxprojMigrated = _xcodeProject.flutterPluginSwiftPackageInProjectSettings;
|
||||
final bool isPbxprojMigrated = _quickCheckIsPbxprojMigrated(_xcodeProjectInfoFile);
|
||||
if (isSchemeMigrated && isPbxprojMigrated) {
|
||||
return;
|
||||
}
|
||||
@ -355,6 +377,20 @@ $newContent
|
||||
}
|
||||
}
|
||||
|
||||
/// Check if the project has had migrations performed already.
|
||||
bool _quickCheckIsPbxprojMigrated(File xcodeProjectInfoFile) {
|
||||
// Initial migration added the `FlutterGeneratedPluginSwiftPackage` and other settings to the pbxproj file.
|
||||
final bool initialMigrationComplete = _xcodeProject.flutterPluginSwiftPackageInProjectSettings;
|
||||
|
||||
// Secondary migration added the `FlutterGeneratedPluginSwiftPackage` as a root package (via PBXFileReference)
|
||||
final bool rootFlutterGeneratedPluginSwiftPackageMigrationComplete = xcodeProjectInfoFile
|
||||
.readAsStringSync()
|
||||
.contains(
|
||||
'$_flutterPluginsSwiftPackageFileIdentifer /* $kFlutterGeneratedPluginSwiftPackageName */ = {isa = PBXFileReference',
|
||||
);
|
||||
return initialMigrationComplete && rootFlutterGeneratedPluginSwiftPackageMigrationComplete;
|
||||
}
|
||||
|
||||
/// Checks if all sections have been migrated. If [logErrorIfNotMigrated] is
|
||||
/// true, will log an error for each section that is not migrated.
|
||||
bool _isPbxprojMigratedCorrectly(
|
||||
@ -365,10 +401,21 @@ $newContent
|
||||
projectInfo,
|
||||
logErrorIfNotMigrated: logErrorIfNotMigrated,
|
||||
);
|
||||
final bool packageFileReferenceMigrated = _isFileReferenceMigrated(
|
||||
projectInfo,
|
||||
logErrorIfNotMigrated: logErrorIfNotMigrated,
|
||||
identifer: _flutterPluginsSwiftPackageFileIdentifer,
|
||||
name: kFlutterGeneratedPluginSwiftPackageName,
|
||||
);
|
||||
final bool frameworksBuildPhaseMigrated = _isFrameworksBuildPhaseMigrated(
|
||||
projectInfo,
|
||||
logErrorIfNotMigrated: logErrorIfNotMigrated,
|
||||
);
|
||||
final bool groupPluginPackageMigrated = _isGroupMigrated(
|
||||
projectInfo,
|
||||
logErrorIfNotMigrated: logErrorIfNotMigrated,
|
||||
fileReferenceIdentifier: _flutterPluginsSwiftPackageFileIdentifer,
|
||||
);
|
||||
final bool nativeTargetsMigrated = _isNativeTargetMigrated(
|
||||
projectInfo,
|
||||
logErrorIfNotMigrated: logErrorIfNotMigrated,
|
||||
@ -386,7 +433,9 @@ $newContent
|
||||
logErrorIfNotMigrated: logErrorIfNotMigrated,
|
||||
);
|
||||
return buildFilesMigrated &&
|
||||
packageFileReferenceMigrated &&
|
||||
frameworksBuildPhaseMigrated &&
|
||||
groupPluginPackageMigrated &&
|
||||
nativeTargetsMigrated &&
|
||||
projectObjectMigrated &&
|
||||
localSwiftPackageMigrated &&
|
||||
@ -403,7 +452,19 @@ $newContent
|
||||
|
||||
List<String> lines = LineSplitter.split(originalProjectContents).toList();
|
||||
lines = _migrateBuildFile(lines, parsedInfo);
|
||||
lines = _migrateFileReference(
|
||||
lines,
|
||||
parsedInfo,
|
||||
_flutterPluginsSwiftPackageFileIdentifer,
|
||||
kFlutterGeneratedPluginSwiftPackageName,
|
||||
);
|
||||
lines = _migrateFrameworksBuildPhase(lines, parsedInfo);
|
||||
lines = _migrateGroup(
|
||||
lines,
|
||||
parsedInfo,
|
||||
_flutterPluginsSwiftPackageFileIdentifer,
|
||||
kFlutterGeneratedPluginSwiftPackageName,
|
||||
);
|
||||
lines = _migrateNativeTarget(lines, parsedInfo);
|
||||
lines = _migrateProjectObject(lines, parsedInfo);
|
||||
lines = _migrateLocalPackageProductDependencies(lines, parsedInfo);
|
||||
@ -419,15 +480,32 @@ $newContent
|
||||
}
|
||||
|
||||
void _ensureNewIdentifiersNotUsed(String originalProjectContents) {
|
||||
if (originalProjectContents.contains(_flutterPluginsSwiftPackageBuildFileIdentifier)) {
|
||||
if (!originalProjectContents.contains(
|
||||
'$_flutterPluginsSwiftPackageBuildFileIdentifier /* $kFlutterGeneratedPluginSwiftPackageName in Frameworks */',
|
||||
) &&
|
||||
originalProjectContents.contains(_flutterPluginsSwiftPackageBuildFileIdentifier)) {
|
||||
throw Exception('Duplicate id found for PBXBuildFile.');
|
||||
}
|
||||
if (originalProjectContents.contains(_flutterPluginsSwiftPackageProductDependencyIdentifier)) {
|
||||
if (!originalProjectContents.contains(
|
||||
'$_flutterPluginsSwiftPackageProductDependencyIdentifier /* $kFlutterGeneratedPluginSwiftPackageName */',
|
||||
) &&
|
||||
originalProjectContents.contains(_flutterPluginsSwiftPackageProductDependencyIdentifier)) {
|
||||
throw Exception('Duplicate id found for XCSwiftPackageProductDependency.');
|
||||
}
|
||||
if (originalProjectContents.contains(_localFlutterPluginsSwiftPackageReferenceIdentifier)) {
|
||||
if (!originalProjectContents.contains(
|
||||
'$_localFlutterPluginsSwiftPackageReferenceIdentifier /* XCLocalSwiftPackageReference',
|
||||
) &&
|
||||
originalProjectContents.contains(_localFlutterPluginsSwiftPackageReferenceIdentifier)) {
|
||||
throw Exception('Duplicate id found for XCLocalSwiftPackageReference.');
|
||||
}
|
||||
if (!originalProjectContents.contains(
|
||||
'$_flutterPluginsSwiftPackageFileIdentifer /* $kFlutterGeneratedPluginSwiftPackageName */',
|
||||
) &&
|
||||
originalProjectContents.contains(_flutterPluginsSwiftPackageFileIdentifer)) {
|
||||
throw Exception(
|
||||
'Duplicate id found for $kFlutterGeneratedPluginSwiftPackageName PBXFileReference.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
bool _isBuildFilesMigrated(ParsedProjectInfo projectInfo, {bool logErrorIfNotMigrated = false}) {
|
||||
@ -447,7 +525,7 @@ $newContent
|
||||
}
|
||||
|
||||
const String newContent =
|
||||
' $_flutterPluginsSwiftPackageBuildFileIdentifier /* FlutterGeneratedPluginSwiftPackage in Frameworks */ = {isa = PBXBuildFile; productRef = $_flutterPluginsSwiftPackageProductDependencyIdentifier /* FlutterGeneratedPluginSwiftPackage */; };';
|
||||
' $_flutterPluginsSwiftPackageBuildFileIdentifier /* $kFlutterGeneratedPluginSwiftPackageName in Frameworks */ = {isa = PBXBuildFile; productRef = $_flutterPluginsSwiftPackageProductDependencyIdentifier /* $kFlutterGeneratedPluginSwiftPackageName */; };';
|
||||
|
||||
final (int _, int endSectionIndex) = _sectionRange('PBXBuildFile', lines);
|
||||
|
||||
@ -455,6 +533,39 @@ $newContent
|
||||
return lines;
|
||||
}
|
||||
|
||||
bool _isFileReferenceMigrated(
|
||||
ParsedProjectInfo projectInfo, {
|
||||
bool logErrorIfNotMigrated = false,
|
||||
required String identifer,
|
||||
required String name,
|
||||
}) {
|
||||
final bool migrated = projectInfo.fileReferenceIdentifiers.contains(identifer);
|
||||
if (logErrorIfNotMigrated && !migrated) {
|
||||
logger.printError('PBXFileReference for $name was not migrated or was migrated incorrectly.');
|
||||
}
|
||||
return migrated;
|
||||
}
|
||||
|
||||
List<String> _migrateFileReference(
|
||||
List<String> lines,
|
||||
ParsedProjectInfo projectInfo,
|
||||
String identifier,
|
||||
String name,
|
||||
) {
|
||||
if (_isFileReferenceMigrated(projectInfo, identifer: identifier, name: name)) {
|
||||
logger.printTrace('PBXFileReference already migrated. Skipping...');
|
||||
return lines;
|
||||
}
|
||||
|
||||
final String newContent =
|
||||
' $identifier /* $name */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = $name; path = $_relativeEphemeralPath/Packages/$name; sourceTree = "<group>"; };';
|
||||
|
||||
final (int _, int endSectionIndex) = _sectionRange('PBXFileReference', lines);
|
||||
|
||||
lines.insert(endSectionIndex, newContent);
|
||||
return lines;
|
||||
}
|
||||
|
||||
bool _isFrameworksBuildPhaseMigrated(
|
||||
ParsedProjectInfo projectInfo, {
|
||||
bool logErrorIfNotMigrated = false,
|
||||
@ -519,7 +630,7 @@ $newContent
|
||||
// If files is null, the files field is missing and must be added.
|
||||
const String newContent = '''
|
||||
files = (
|
||||
$_flutterPluginsSwiftPackageBuildFileIdentifier /* FlutterGeneratedPluginSwiftPackage in Frameworks */,
|
||||
$_flutterPluginsSwiftPackageBuildFileIdentifier /* $kFlutterGeneratedPluginSwiftPackageName in Frameworks */,
|
||||
);''';
|
||||
lines.insert(runnerFrameworksPhaseStartIndex + 1, newContent);
|
||||
} else {
|
||||
@ -534,7 +645,7 @@ $newContent
|
||||
);
|
||||
}
|
||||
const String newContent =
|
||||
' $_flutterPluginsSwiftPackageBuildFileIdentifier /* FlutterGeneratedPluginSwiftPackage in Frameworks */,';
|
||||
' $_flutterPluginsSwiftPackageBuildFileIdentifier /* $kFlutterGeneratedPluginSwiftPackageName in Frameworks */,';
|
||||
lines.insert(startFilesIndex + 1, newContent);
|
||||
}
|
||||
|
||||
@ -601,7 +712,7 @@ $newContent
|
||||
// If packageProductDependencies is null, the packageProductDependencies field is missing and must be added.
|
||||
const List<String> newContent = <String>[
|
||||
' packageProductDependencies = (',
|
||||
' $_flutterPluginsSwiftPackageProductDependencyIdentifier /* FlutterGeneratedPluginSwiftPackage */,',
|
||||
' $_flutterPluginsSwiftPackageProductDependencyIdentifier /* $kFlutterGeneratedPluginSwiftPackageName */,',
|
||||
' );',
|
||||
];
|
||||
lines.insertAll(runnerNativeTargetStartIndex + 1, newContent);
|
||||
@ -618,12 +729,88 @@ $newContent
|
||||
);
|
||||
}
|
||||
const String newContent =
|
||||
' $_flutterPluginsSwiftPackageProductDependencyIdentifier /* FlutterGeneratedPluginSwiftPackage */,';
|
||||
' $_flutterPluginsSwiftPackageProductDependencyIdentifier /* $kFlutterGeneratedPluginSwiftPackageName */,';
|
||||
lines.insert(packageProductDependenciesIndex + 1, newContent);
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
bool _isGroupMigrated(
|
||||
ParsedProjectInfo projectInfo, {
|
||||
bool logErrorIfNotMigrated = false,
|
||||
required String fileReferenceIdentifier,
|
||||
}) {
|
||||
final bool migrated =
|
||||
projectInfo.parsedGroups
|
||||
.where(
|
||||
(ParsedProjectGroup group) =>
|
||||
group.identifier == _flutterGroupIdentifier &&
|
||||
group.children != null &&
|
||||
group.children!.contains(fileReferenceIdentifier),
|
||||
)
|
||||
.toList()
|
||||
.isNotEmpty;
|
||||
if (logErrorIfNotMigrated && !migrated) {
|
||||
logger.printError('PBXGroup was not migrated or was migrated incorrectly.');
|
||||
}
|
||||
return migrated;
|
||||
}
|
||||
|
||||
List<String> _migrateGroup(
|
||||
List<String> lines,
|
||||
ParsedProjectInfo projectInfo,
|
||||
String fileReferenceIdentifier,
|
||||
String fileReferenceName,
|
||||
) {
|
||||
if (_isGroupMigrated(projectInfo, fileReferenceIdentifier: fileReferenceIdentifier)) {
|
||||
logger.printTrace('PBXGroup already migrated. Skipping...');
|
||||
return lines;
|
||||
}
|
||||
|
||||
final (int startSectionIndex, int endSectionIndex) = _sectionRange('PBXGroup', lines);
|
||||
|
||||
// Find index where Flutter group begins.
|
||||
final int flutterGroupStartIndex = lines.indexWhere(
|
||||
(String line) => line.trim().startsWith('$_flutterGroupIdentifier /* Flutter */ = {'),
|
||||
startSectionIndex,
|
||||
);
|
||||
if (flutterGroupStartIndex == -1 || flutterGroupStartIndex > endSectionIndex) {
|
||||
throw Exception('Unable to find Flutter PBXGroup.');
|
||||
}
|
||||
|
||||
// Get the Flutter Group from the parsed project info.
|
||||
final ParsedProjectGroup? parsedGroup =
|
||||
projectInfo.parsedGroups
|
||||
.where((ParsedProjectGroup group) => group.identifier == _flutterGroupIdentifier)
|
||||
.toList()
|
||||
.firstOrNull;
|
||||
if (parsedGroup == null) {
|
||||
throw Exception('Unable to find parsed Flutter PBXGroup.');
|
||||
}
|
||||
|
||||
if (parsedGroup.children == null) {
|
||||
// If children is null, the children field is missing and must be added.
|
||||
final String newContent = '''
|
||||
children = (
|
||||
$fileReferenceIdentifier /* $fileReferenceName */,
|
||||
);''';
|
||||
lines.insert(flutterGroupStartIndex + 1, newContent);
|
||||
} else {
|
||||
// Find the children field within the Flutter PBXGroup.
|
||||
final int startChildrenIndex = lines.indexWhere(
|
||||
(String line) => line.trim().contains('children = ('),
|
||||
flutterGroupStartIndex,
|
||||
);
|
||||
if (startChildrenIndex == -1 || startChildrenIndex > endSectionIndex) {
|
||||
throw Exception('Unable to children for Flutter PBXGroup.');
|
||||
}
|
||||
final String newContent = ' $fileReferenceIdentifier /* $fileReferenceName */,';
|
||||
lines.insert(startChildrenIndex + 1, newContent);
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
bool _isProjectObjectMigrated(
|
||||
ParsedProjectInfo projectInfo, {
|
||||
bool logErrorIfNotMigrated = false,
|
||||
@ -675,9 +862,9 @@ $newContent
|
||||
|
||||
if (projectObject.packageReferences == null) {
|
||||
// If packageReferences is null, the packageReferences field is missing and must be added.
|
||||
const List<String> newContent = <String>[
|
||||
final List<String> newContent = <String>[
|
||||
' packageReferences = (',
|
||||
' $_localFlutterPluginsSwiftPackageReferenceIdentifier /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */,',
|
||||
' $_localFlutterPluginsSwiftPackageReferenceIdentifier /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/$kFlutterGeneratedPluginSwiftPackageName" */,',
|
||||
' );',
|
||||
];
|
||||
lines.insertAll(projectStartIndex + 1, newContent);
|
||||
@ -693,7 +880,7 @@ $newContent
|
||||
);
|
||||
}
|
||||
const String newContent =
|
||||
' $_localFlutterPluginsSwiftPackageReferenceIdentifier /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */,';
|
||||
' $_localFlutterPluginsSwiftPackageReferenceIdentifier /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/$kFlutterGeneratedPluginSwiftPackageName" */,';
|
||||
lines.insert(packageReferencesIndex + 1, newContent);
|
||||
}
|
||||
return lines;
|
||||
@ -733,9 +920,9 @@ $newContent
|
||||
// There isn't a XCLocalSwiftPackageReference section yet, so add it
|
||||
final List<String> newContent = <String>[
|
||||
'/* Begin XCLocalSwiftPackageReference section */',
|
||||
' $_localFlutterPluginsSwiftPackageReferenceIdentifier /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */ = {',
|
||||
' $_localFlutterPluginsSwiftPackageReferenceIdentifier /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/$kFlutterGeneratedPluginSwiftPackageName" */ = {',
|
||||
' isa = XCLocalSwiftPackageReference;',
|
||||
' relativePath = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage;',
|
||||
' relativePath = Flutter/ephemeral/Packages/$kFlutterGeneratedPluginSwiftPackageName;',
|
||||
' };',
|
||||
'/* End XCLocalSwiftPackageReference section */',
|
||||
];
|
||||
@ -750,9 +937,9 @@ $newContent
|
||||
}
|
||||
|
||||
final List<String> newContent = <String>[
|
||||
' $_localFlutterPluginsSwiftPackageReferenceIdentifier /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage" */ = {',
|
||||
' $_localFlutterPluginsSwiftPackageReferenceIdentifier /* XCLocalSwiftPackageReference "Flutter/ephemeral/Packages/$kFlutterGeneratedPluginSwiftPackageName" */ = {',
|
||||
' isa = XCLocalSwiftPackageReference;',
|
||||
' relativePath = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage;',
|
||||
' relativePath = Flutter/ephemeral/Packages/$kFlutterGeneratedPluginSwiftPackageName;',
|
||||
' };',
|
||||
];
|
||||
|
||||
@ -795,9 +982,9 @@ $newContent
|
||||
// There isn't a XCSwiftPackageProductDependency section yet, so add it
|
||||
final List<String> newContent = <String>[
|
||||
'/* Begin XCSwiftPackageProductDependency section */',
|
||||
' $_flutterPluginsSwiftPackageProductDependencyIdentifier /* FlutterGeneratedPluginSwiftPackage */ = {',
|
||||
' $_flutterPluginsSwiftPackageProductDependencyIdentifier /* $kFlutterGeneratedPluginSwiftPackageName */ = {',
|
||||
' isa = XCSwiftPackageProductDependency;',
|
||||
' productName = FlutterGeneratedPluginSwiftPackage;',
|
||||
' productName = $kFlutterGeneratedPluginSwiftPackageName;',
|
||||
' };',
|
||||
'/* End XCSwiftPackageProductDependency section */',
|
||||
];
|
||||
@ -812,9 +999,9 @@ $newContent
|
||||
}
|
||||
|
||||
final List<String> newContent = <String>[
|
||||
' $_flutterPluginsSwiftPackageProductDependencyIdentifier /* FlutterGeneratedPluginSwiftPackage */ = {',
|
||||
' $_flutterPluginsSwiftPackageProductDependencyIdentifier /* $kFlutterGeneratedPluginSwiftPackageName */ = {',
|
||||
' isa = XCSwiftPackageProductDependency;',
|
||||
' productName = FlutterGeneratedPluginSwiftPackage;',
|
||||
' productName = $kFlutterGeneratedPluginSwiftPackageName;',
|
||||
' };',
|
||||
];
|
||||
|
||||
|
||||
@ -21,6 +21,7 @@ import 'ios/code_signing.dart';
|
||||
import 'ios/plist_parser.dart';
|
||||
import 'ios/xcode_build_settings.dart' as xcode;
|
||||
import 'ios/xcodeproj.dart';
|
||||
import 'macos/swift_package_manager.dart';
|
||||
import 'macos/xcode.dart';
|
||||
import 'platform_plugins.dart';
|
||||
import 'project.dart';
|
||||
@ -142,7 +143,7 @@ abstract class XcodeBasedProject extends FlutterProjectPlatform {
|
||||
/// dependencies.
|
||||
Directory get flutterPluginSwiftPackageDirectory => ephemeralDirectory
|
||||
.childDirectory('Packages')
|
||||
.childDirectory('FlutterGeneratedPluginSwiftPackage');
|
||||
.childDirectory(kFlutterGeneratedPluginSwiftPackageName);
|
||||
|
||||
/// The Flutter generated Swift Package manifest (Package.swift) for plugin
|
||||
/// dependencies.
|
||||
@ -153,7 +154,7 @@ abstract class XcodeBasedProject extends FlutterProjectPlatform {
|
||||
/// project's build settings by checking the contents of the pbxproj.
|
||||
bool get flutterPluginSwiftPackageInProjectSettings {
|
||||
return xcodeProjectInfoFile.existsSync() &&
|
||||
xcodeProjectInfoFile.readAsStringSync().contains('FlutterGeneratedPluginSwiftPackage');
|
||||
xcodeProjectInfoFile.readAsStringSync().contains(kFlutterGeneratedPluginSwiftPackageName);
|
||||
}
|
||||
|
||||
/// True if this project doesn't have Swift Package Manager disabled in the
|
||||
|
||||
@ -49,6 +49,9 @@
|
||||
331C80F1294D02FB00263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
331C80F3294D02FB00263BE5 /* RunnerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RunnerTests.m; sourceTree = "<group>"; };
|
||||
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
|
||||
{{#withSwiftPackageManager}}
|
||||
78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlutterGeneratedPluginSwiftPackage; path = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; sourceTree = "<group>"; };
|
||||
{{/withSwiftPackageManager}}
|
||||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
|
||||
7AFFD8ED1D35381100E5BB4D /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
|
||||
7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
|
||||
@ -94,6 +97,9 @@
|
||||
9740EEB11CF90186004384FC /* Flutter */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
{{#withSwiftPackageManager}}
|
||||
78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */,
|
||||
{{/withSwiftPackageManager}}
|
||||
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
|
||||
9740EEB21CF90195004384FC /* Debug.xcconfig */,
|
||||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */,
|
||||
|
||||
@ -50,6 +50,9 @@
|
||||
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
|
||||
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
|
||||
{{#withSwiftPackageManager}}
|
||||
78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlutterGeneratedPluginSwiftPackage; path = Flutter/ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; sourceTree = "<group>"; };
|
||||
{{/withSwiftPackageManager}}
|
||||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
|
||||
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
|
||||
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
|
||||
@ -85,6 +88,9 @@
|
||||
9740EEB11CF90186004384FC /* Flutter */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
{{#withSwiftPackageManager}}
|
||||
78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */,
|
||||
{{/withSwiftPackageManager}}
|
||||
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */,
|
||||
9740EEB21CF90195004384FC /* Debug.xcconfig */,
|
||||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */,
|
||||
|
||||
@ -79,6 +79,9 @@
|
||||
33E51913231747F40026EE4D /* DebugProfile.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = DebugProfile.entitlements; sourceTree = "<group>"; };
|
||||
33E51914231749380026EE4D /* Release.entitlements */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.entitlements; path = Release.entitlements; sourceTree = "<group>"; };
|
||||
33E5194F232828860026EE4D /* AppInfo.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = AppInfo.xcconfig; sourceTree = "<group>"; };
|
||||
{{#withSwiftPackageManager}}
|
||||
78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = FlutterGeneratedPluginSwiftPackage; path = ephemeral/Packages/FlutterGeneratedPluginSwiftPackage; sourceTree = "<group>"; };
|
||||
{{/withSwiftPackageManager}}
|
||||
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Release.xcconfig; sourceTree = "<group>"; };
|
||||
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Debug.xcconfig; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
@ -157,6 +160,9 @@
|
||||
33CEB47122A05771004F2AC0 /* Flutter */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
{{#withSwiftPackageManager}}
|
||||
78E0A7A72DC9AD7400C4905E /* FlutterGeneratedPluginSwiftPackage */,
|
||||
{{/withSwiftPackageManager}}
|
||||
335BBD1A22A9A15E00E9071D /* GeneratedPluginRegistrant.swift */,
|
||||
33CEB47222A05771004F2AC0 /* Flutter-Debug.xcconfig */,
|
||||
33CEB47422A05771004F2AC0 /* Flutter-Release.xcconfig */,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user