Build iOS apps using Swift Packages (#72761)
This commit is contained in:
@@ -26,6 +26,13 @@ abstract class ProjectMigrator {
|
||||
}
|
||||
|
||||
@protected
|
||||
String migrateFileContents(String fileContents) {
|
||||
return fileContents;
|
||||
}
|
||||
|
||||
@protected
|
||||
/// Calls [migrateLine] per line, then [migrateFileContents]
|
||||
/// including the line migrations.
|
||||
void processFileLines(File file) {
|
||||
final List<String> lines = file.readAsLinesSync();
|
||||
|
||||
@@ -51,9 +58,16 @@ abstract class ProjectMigrator {
|
||||
newProjectContents.writeln(newProjectLine);
|
||||
}
|
||||
|
||||
final String projectContentsWithMigratedLines = newProjectContents.toString();
|
||||
final String projectContentsWithMigratedContents = migrateFileContents(projectContentsWithMigratedLines);
|
||||
if (projectContentsWithMigratedLines != projectContentsWithMigratedContents) {
|
||||
logger.printTrace('Migrating $basename contents');
|
||||
migrationRequired = true;
|
||||
}
|
||||
|
||||
if (migrationRequired) {
|
||||
logger.printStatus('Upgrading $basename');
|
||||
file.writeAsStringSync(newProjectContents.toString());
|
||||
file.writeAsStringSync(projectContentsWithMigratedContents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import '../reporting/reporting.dart';
|
||||
import 'code_signing.dart';
|
||||
import 'devices.dart';
|
||||
import 'migrations/project_base_configuration_migration.dart';
|
||||
import 'migrations/project_build_location_migration.dart';
|
||||
import 'migrations/remove_framework_link_and_embedding_migration.dart';
|
||||
import 'migrations/xcode_build_system_migration.dart';
|
||||
import 'xcodeproj.dart';
|
||||
@@ -106,6 +107,7 @@ Future<XcodeBuildResult> buildXcodeProject({
|
||||
RemoveFrameworkLinkAndEmbeddingMigration(app.project, globals.logger, globals.xcode, globals.flutterUsage),
|
||||
XcodeBuildSystemMigration(app.project, globals.logger),
|
||||
ProjectBaseConfigurationMigration(app.project, globals.logger),
|
||||
ProjectBuildLocationMigration(app.project, globals.logger),
|
||||
];
|
||||
|
||||
final ProjectMigration migration = ProjectMigration(migrators);
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
// 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/logger.dart';
|
||||
import '../../base/project_migrator.dart';
|
||||
import '../../project.dart';
|
||||
|
||||
// Update the xcodeproj build location. Legacy build location does not work with Swift Packages.
|
||||
class ProjectBuildLocationMigration extends ProjectMigrator {
|
||||
ProjectBuildLocationMigration(
|
||||
IosProject project,
|
||||
Logger logger,
|
||||
) : _xcodeProjectWorkspaceData = project.xcodeProjectWorkspaceData,
|
||||
super(logger);
|
||||
|
||||
final File _xcodeProjectWorkspaceData;
|
||||
|
||||
@override
|
||||
bool migrate() {
|
||||
if (!_xcodeProjectWorkspaceData.existsSync()) {
|
||||
logger.printTrace('Xcode project workspace data not found, skipping build location migration.');
|
||||
return true;
|
||||
}
|
||||
|
||||
processFileLines(_xcodeProjectWorkspaceData);
|
||||
return true;
|
||||
}
|
||||
|
||||
@override
|
||||
String migrateLine(String line) {
|
||||
const String legacyBuildLocation = 'location = "group:Runner.xcodeproj"';
|
||||
const String defaultBuildLocation = 'location = "self:"';
|
||||
|
||||
return line.replaceAll(legacyBuildLocation, defaultBuildLocation);
|
||||
}
|
||||
|
||||
@override
|
||||
String migrateFileContents(String fileContents) {
|
||||
const String podLocation = '''
|
||||
<FileRef
|
||||
location = "group:Pods/Pods.xcodeproj">
|
||||
</FileRef>
|
||||
''';
|
||||
|
||||
return fileContents.replaceAll(podLocation, '');
|
||||
}
|
||||
}
|
||||
@@ -446,6 +446,11 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject {
|
||||
@override
|
||||
File get xcodeProjectInfoFile => xcodeProject.childFile('project.pbxproj');
|
||||
|
||||
File get xcodeProjectWorkspaceData =>
|
||||
xcodeProject
|
||||
.childDirectory('project.xcworkspace')
|
||||
.childFile('contents.xcworkspacedata');
|
||||
|
||||
@override
|
||||
Directory get xcodeWorkspace => hostAppRoot.childDirectory('$_hostAppProjectName.xcworkspace');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user