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
5import '../base/file_system.dart';
6import '../base/project_migrator.dart';
7import '../xcode_project.dart';
8
9/// Migrate the Xcode project for Xcode compatibility to avoid an "Update to recommended settings" Xcode warning.
10class XcodeProjectObjectVersionMigration extends ProjectMigrator {
11 XcodeProjectObjectVersionMigration(
12 XcodeBasedProject project,
13 super.logger,
14 ) : _xcodeProjectInfoFile = project.xcodeProjectInfoFile,
15 _xcodeProjectSchemeFile = project.xcodeProjectSchemeFile();
16
17 final File _xcodeProjectInfoFile;
18 final File _xcodeProjectSchemeFile;
19
20 @override
21 Future<void> migrate() async {
22 if (_xcodeProjectInfoFile.existsSync()) {
23 processFileLines(_xcodeProjectInfoFile);
24 } else {
25 logger.printTrace('Xcode project not found, skipping Xcode compatibility migration.');
26 }
27 if (_xcodeProjectSchemeFile.existsSync()) {
28 processFileLines(_xcodeProjectSchemeFile);
29 } else {
30 logger.printTrace('Runner scheme not found, skipping Xcode compatibility migration.');
31 }
32 }
33
34 @override
35 String? migrateLine(String line) {
36 String updatedString = line;
37 final Map<Pattern, String> originalToReplacement = <Pattern, String>{
38 // objectVersion value has been 46, 50, 51, and 54 in the template.
39 RegExp(r'objectVersion = \d+;'): 'objectVersion = 54;',
40 // LastUpgradeCheck is in the Xcode project file, not scheme file.
41 // Value has been 0730, 0800, 1020, 1300, 1430, and 1510 in the template.
42 RegExp(r'LastUpgradeCheck = \d+;'): 'LastUpgradeCheck = 1510;',
43 // LastUpgradeVersion is in the scheme file, not Xcode project file.
44 RegExp(r'LastUpgradeVersion = "\d+"'): 'LastUpgradeVersion = "1510"',
45 };
46
47 originalToReplacement.forEach((Pattern original, String replacement) {
48 if (line.contains(original)) {
49 updatedString = line.replaceAll(original, replacement);
50 if (!migrationRequired && updatedString != line) {
51 // Only print once.
52 logger.printStatus('Updating project for Xcode compatibility.');
53 }
54 }
55 });
56
57 return updatedString;
58 }
59}
60

Provided by KDAB

Privacy Policy
Learn more about Flutter for embedded and desktop on industrialflutter.com