Skip to content

Commit 45d71e2

Browse files
authored
Build iOS apps using Swift Packages (flutter#73508)
1 parent 544a41e commit 45d71e2

File tree

32 files changed

+182
-64
lines changed

32 files changed

+182
-64
lines changed

dev/benchmarks/complex_layout/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/benchmarks/macrobenchmarks/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/benchmarks/microbenchmarks/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/benchmarks/platform_views_layout/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/benchmarks/platform_views_layout_hybrid_composition/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/benchmarks/test_apps/stocks/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/integration_tests/channels/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/integration_tests/external_ui/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/integration_tests/flavors/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/integration_tests/flutter_driver_screenshot_test/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/integration_tests/flutter_gallery/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/integration_tests/ios_app_with_extensions/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/integration_tests/ios_platform_view_tests/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/integration_tests/non_nullable/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/integration_tests/platform_interaction/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/integration_tests/release_smoke_test/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/integration_tests/ui/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/manual_tests/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/flutter_view/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/hello_world/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/image_list/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/layers/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/platform_channel/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/platform_channel_swift/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/platform_view/ios/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/flutter_tools/lib/src/base/project_migrator.dart

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ abstract class ProjectMigrator {
2626
}
2727

2828
@protected
29+
String migrateFileContents(String fileContents) {
30+
return fileContents;
31+
}
32+
33+
@protected
34+
/// Calls [migrateLine] per line, then [migrateFileContents]
35+
/// including the line migrations.
2936
void processFileLines(File file) {
3037
final List<String> lines = file.readAsLinesSync();
3138

@@ -51,9 +58,16 @@ abstract class ProjectMigrator {
5158
newProjectContents.writeln(newProjectLine);
5259
}
5360

61+
final String projectContentsWithMigratedLines = newProjectContents.toString();
62+
final String projectContentsWithMigratedContents = migrateFileContents(projectContentsWithMigratedLines);
63+
if (projectContentsWithMigratedLines != projectContentsWithMigratedContents) {
64+
logger.printTrace('Migrating $basename contents');
65+
migrationRequired = true;
66+
}
67+
5468
if (migrationRequired) {
5569
logger.printStatus('Upgrading $basename');
56-
file.writeAsStringSync(newProjectContents.toString());
70+
file.writeAsStringSync(projectContentsWithMigratedContents);
5771
}
5872
}
5973
}

packages/flutter_tools/lib/src/ios/mac.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import '../reporting/reporting.dart';
2525
import 'code_signing.dart';
2626
import 'devices.dart';
2727
import 'migrations/project_base_configuration_migration.dart';
28+
import 'migrations/project_build_location_migration.dart';
2829
import 'migrations/remove_framework_link_and_embedding_migration.dart';
2930
import 'migrations/xcode_build_system_migration.dart';
3031
import 'xcodeproj.dart';
@@ -106,6 +107,7 @@ Future<XcodeBuildResult> buildXcodeProject({
106107
RemoveFrameworkLinkAndEmbeddingMigration(app.project, globals.logger, globals.xcode, globals.flutterUsage),
107108
XcodeBuildSystemMigration(app.project, globals.logger),
108109
ProjectBaseConfigurationMigration(app.project, globals.logger),
110+
ProjectBuildLocationMigration(app.project, globals.logger),
109111
];
110112

111113
final ProjectMigration migration = ProjectMigration(migrators);
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2014 The Flutter Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import '../../base/file_system.dart';
6+
import '../../base/logger.dart';
7+
import '../../base/project_migrator.dart';
8+
import '../../project.dart';
9+
10+
// Update the xcodeproj build location. Legacy build location does not work with Swift Packages.
11+
class ProjectBuildLocationMigration extends ProjectMigrator {
12+
ProjectBuildLocationMigration(
13+
IosProject project,
14+
Logger logger,
15+
) : _xcodeProjectWorkspaceData = project.xcodeProjectWorkspaceData,
16+
super(logger);
17+
18+
final File _xcodeProjectWorkspaceData;
19+
20+
@override
21+
bool migrate() {
22+
if (!_xcodeProjectWorkspaceData.existsSync()) {
23+
logger.printTrace('Xcode project workspace data not found, skipping build location migration.');
24+
return true;
25+
}
26+
27+
processFileLines(_xcodeProjectWorkspaceData);
28+
return true;
29+
}
30+
31+
@override
32+
String migrateLine(String line) {
33+
const String legacyBuildLocation = 'location = "group:Runner.xcodeproj"';
34+
const String defaultBuildLocation = 'location = "self:"';
35+
36+
return line.replaceAll(legacyBuildLocation, defaultBuildLocation);
37+
}
38+
39+
@override
40+
String migrateFileContents(String fileContents) {
41+
const String podLocation = '''
42+
<FileRef
43+
location = "group:Pods/Pods.xcodeproj">
44+
</FileRef>
45+
''';
46+
47+
return fileContents.replaceAll(podLocation, '');
48+
}
49+
}

packages/flutter_tools/lib/src/project.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ class IosProject extends FlutterProjectPlatform implements XcodeBasedProject {
446446
@override
447447
File get xcodeProjectInfoFile => xcodeProject.childFile('project.pbxproj');
448448

449+
File get xcodeProjectWorkspaceData =>
450+
xcodeProject
451+
.childDirectory('project.xcworkspace')
452+
.childFile('contents.xcworkspacedata');
453+
449454
@override
450455
Directory get xcodeWorkspace => hostAppRoot.childDirectory('$_hostAppProjectName.xcworkspace');
451456

packages/flutter_tools/templates/app/ios.tmpl/Runner.xcodeproj/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/flutter_tools/templates/module/ios/host_app_ephemeral/Runner.xcodeproj.tmpl/project.xcworkspace/contents.xcworkspacedata

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)