ios_project_migration_test.dart 52.2 KB
Newer Older
1 2 3 4 5 6 7
// 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 'package:file/file.dart';
import 'package:file/memory.dart';
import 'package:flutter_tools/src/base/logger.dart';
8
import 'package:flutter_tools/src/base/project_migrator.dart';
9
import 'package:flutter_tools/src/base/version.dart';
10
import 'package:flutter_tools/src/ios/migrations/host_app_info_plist_migration.dart';
11
import 'package:flutter_tools/src/ios/migrations/ios_deployment_target_migration.dart';
12
import 'package:flutter_tools/src/ios/migrations/project_base_configuration_migration.dart';
13
import 'package:flutter_tools/src/ios/migrations/project_build_location_migration.dart';
14
import 'package:flutter_tools/src/ios/migrations/remove_bitcode_migration.dart';
15
import 'package:flutter_tools/src/ios/migrations/remove_framework_link_and_embedding_migration.dart';
16
import 'package:flutter_tools/src/ios/migrations/xcode_build_system_migration.dart';
17 18
import 'package:flutter_tools/src/ios/xcodeproj.dart';
import 'package:flutter_tools/src/migrations/cocoapods_script_symlink.dart';
19
import 'package:flutter_tools/src/migrations/cocoapods_toolchain_directory_migration.dart';
20 21
import 'package:flutter_tools/src/migrations/xcode_project_object_version_migration.dart';
import 'package:flutter_tools/src/migrations/xcode_script_build_phase_migration.dart';
22
import 'package:flutter_tools/src/migrations/xcode_thin_binary_build_phase_input_paths_migration.dart';
23
import 'package:flutter_tools/src/reporting/reporting.dart';
24
import 'package:flutter_tools/src/xcode_project.dart';
25
import 'package:test/fake.dart';
26
import 'package:unified_analytics/unified_analytics.dart';
27 28

import '../../src/common.dart';
29
import '../../src/fake_process_manager.dart';
30
import '../../src/fakes.dart';
31 32

void main () {
33
  group('iOS migration', () {
34
    late TestUsage testUsage;
35
    late FakeAnalytics fakeAnalytics;
36

37
    setUp(() {
38
      testUsage = TestUsage();
39 40 41 42 43 44

      final MemoryFileSystem fs = MemoryFileSystem.test();
      fakeAnalytics = getInitializedFakeAnalyticsInstance(
        fs: fs,
        fakeFlutterVersion: FakeFlutterVersion(),
      );
45 46
    });

47
    testWithoutContext('migrators succeed', () {
48
      final FakeIOSMigrator fakeIOSMigrator = FakeIOSMigrator();
49
      final ProjectMigration migration = ProjectMigration(<ProjectMigrator>[fakeIOSMigrator]);
50
      migration.run();
51 52
    });

53
    group('remove framework linking and embedding migration', () {
54 55 56 57
      late MemoryFileSystem memoryFileSystem;
      late BufferLogger testLogger;
      late FakeIosProject project;
      late File xcodeProjectInfoFile;
58 59

      setUp(() {
60
        memoryFileSystem = MemoryFileSystem.test();
61
        xcodeProjectInfoFile = memoryFileSystem.file('project.pbxproj');
62
        testLogger = BufferLogger.test();
63 64
        project = FakeIosProject();
        project.xcodeProjectInfoFile = xcodeProjectInfoFile;
65 66 67 68
      });

      testWithoutContext('skipped if files are missing', () {
        final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration(
69
          project,
70
          testLogger,
71 72
          testUsage,
          fakeAnalytics,
73
        );
74
        iosProjectMigration.migrate();
75
        expect(testUsage.events, isEmpty);
76
        expect(fakeAnalytics.sentEvents, isEmpty);
77 78 79

        expect(xcodeProjectInfoFile.existsSync(), isFalse);

80
        expect(testLogger.traceText, contains('Xcode project not found, skipping framework link and embedding migration'));
81 82 83 84 85 86 87 88 89
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('skipped if nothing to upgrade', () {
        const String contents = 'Nothing to upgrade';
        xcodeProjectInfoFile.writeAsStringSync(contents);
        final DateTime projectLastModified = xcodeProjectInfoFile.lastModifiedSync();

        final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration(
90
          project,
91
          testLogger,
92
          testUsage,
93
          fakeAnalytics,
94
        );
95
        iosProjectMigration.migrate();
96
        expect(testUsage.events, isEmpty);
97
        expect(fakeAnalytics.sentEvents, isEmpty);
98 99 100 101 102 103 104 105

        expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified);
        expect(xcodeProjectInfoFile.readAsStringSync(), contents);

        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('skips migrating script with embed', () {
106 107
        const String contents = r'''
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed\n/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin";
108
			''';
109 110 111
        xcodeProjectInfoFile.writeAsStringSync(contents);

        final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration(
112
          project,
113
          testLogger,
114
          testUsage,
115
          fakeAnalytics,
116
        );
117
        iosProjectMigration.migrate();
118 119 120 121 122
        expect(xcodeProjectInfoFile.readAsStringSync(), contents);
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('Xcode project is migrated', () {
123
        xcodeProjectInfoFile.writeAsStringSync(r'''
124 125 126 127 128 129 130 131 132 133 134
prefix 3B80C3941E831B6300D905FE
3B80C3951E831B6300D905FE suffix
741F496821356857001E2961
keep this 1
  3B80C3931E831B6300D905FE spaces
741F496521356807001E2961
9705A1C61CF904A100538489
9705A1C71CF904A300538489
741F496221355F47001E2961
9740EEBA1CF902C7004384FC
741F495E21355F27001E2961
135
			shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" thin";
136 137 138
keep this 2
''');

139
        final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration(
140
          project,
141
          testLogger,
142
          testUsage,
143
          fakeAnalytics,
144
        );
145
        iosProjectMigration.migrate();
146
        expect(testUsage.events, isEmpty);
147
        expect(fakeAnalytics.sentEvents, isEmpty);
148

149
        expect(xcodeProjectInfoFile.readAsStringSync(), r'''
150
keep this 1
151
			shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin";
152 153
keep this 2
''');
154 155
        expect(testLogger.statusText, contains('Upgrading project.pbxproj'));
      });
156

157 158
      testWithoutContext('migration fails with leftover App.framework reference', () {
        xcodeProjectInfoFile.writeAsStringSync('''
159 160
        746232531E83B71900CC1A5E /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 746232521E83B71900CC1A5E /* App.framework */; };
''');
161 162

        final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration(
163
          project,
164
          testLogger,
165
          testUsage,
166
          fakeAnalytics,
167 168
        );

169
        expect(iosProjectMigration.migrate, throwsToolExit(message: 'Your Xcode project requires migration'));
170 171 172
        expect(testUsage.events, contains(
          const TestUsageEvent('ios-migration', 'remove-frameworks', label: 'failure'),
        ));
173 174 175 176 177 178 179
        expect(fakeAnalytics.sentEvents, contains(
          Event.appleUsageEvent(
              workflow: 'ios-migration',
              parameter: 'remove-frameworks',
              result: 'failure',
            )
        ));
180 181 182 183
      });

      testWithoutContext('migration fails with leftover Flutter.framework reference', () {
        xcodeProjectInfoFile.writeAsStringSync('''
184 185
      9705A1C71CF904A300538480 /* Flutter.framework in Embed Frameworks */,
''');
186 187

        final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration(
188
          project,
189
          testLogger,
190
          testUsage,
191
          fakeAnalytics,
192
        );
193
        expect(iosProjectMigration.migrate, throwsToolExit(message: 'Your Xcode project requires migration'));
194 195 196
        expect(testUsage.events, contains(
          const TestUsageEvent('ios-migration', 'remove-frameworks', label: 'failure'),
        ));
197 198 199 200 201 202 203
        expect(fakeAnalytics.sentEvents, contains(
          Event.appleUsageEvent(
              workflow: 'ios-migration',
              parameter: 'remove-frameworks',
              result: 'failure',
            )
        ));
204 205 206 207
      });

      testWithoutContext('migration fails without Xcode installed', () {
        xcodeProjectInfoFile.writeAsStringSync('''
208 209
        746232531E83B71900CC1A5E /* App.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 746232521E83B71900CC1A5E /* App.framework */; };
''');
210 211

        final RemoveFrameworkLinkAndEmbeddingMigration iosProjectMigration = RemoveFrameworkLinkAndEmbeddingMigration(
212
          project,
213
          testLogger,
214
          testUsage,
215
          fakeAnalytics,
216
        );
217
        expect(iosProjectMigration.migrate, throwsToolExit(message: 'Your Xcode project requires migration'));
218 219 220
        expect(testUsage.events, contains(
          const TestUsageEvent('ios-migration', 'remove-frameworks', label: 'failure'),
        ));
221 222 223 224 225 226 227
        expect(fakeAnalytics.sentEvents, contains(
          Event.appleUsageEvent(
              workflow: 'ios-migration',
              parameter: 'remove-frameworks',
              result: 'failure',
            )
        ));
228
      });
229
    });
230 231

    group('new Xcode build system', () {
232 233 234 235
      late MemoryFileSystem memoryFileSystem;
      late BufferLogger testLogger;
      late FakeIosProject project;
      late File xcodeWorkspaceSharedSettings;
236 237

      setUp(() {
238
        memoryFileSystem = MemoryFileSystem.test();
239
        xcodeWorkspaceSharedSettings = memoryFileSystem.file('WorkspaceSettings.xcsettings');
240
        testLogger = BufferLogger.test();
241 242
        project = FakeIosProject();
        project.xcodeWorkspaceSharedSettings = xcodeWorkspaceSharedSettings;
243 244 245 246
      });

      testWithoutContext('skipped if files are missing', () {
        final XcodeBuildSystemMigration iosProjectMigration = XcodeBuildSystemMigration(
247
          project,
248 249
          testLogger,
        );
250
        iosProjectMigration.migrate();
251 252
        expect(xcodeWorkspaceSharedSettings.existsSync(), isFalse);

253
        expect(testLogger.traceText, contains('Xcode workspace settings not found, skipping build system migration'));
254 255 256
        expect(testLogger.statusText, isEmpty);
      });

257 258 259 260 261 262 263 264 265 266 267 268 269 270
      testWithoutContext('skipped if _xcodeWorkspaceSharedSettings is null', () {
        final XcodeBuildSystemMigration iosProjectMigration = XcodeBuildSystemMigration(
          project,
          testLogger,
        );
        project.xcodeWorkspaceSharedSettings = null;

        iosProjectMigration.migrate();
        expect(xcodeWorkspaceSharedSettings.existsSync(), isFalse);

        expect(testLogger.traceText, contains('Xcode workspace settings not found, skipping build system migration'));
        expect(testLogger.statusText, isEmpty);
      });

271 272 273 274 275 276 277 278 279 280 281 282 283
      testWithoutContext('skipped if nothing to upgrade', () {
        const String contents = '''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>BuildSystemType</key>
	<string></string>
</dict>
</plist>''';
        xcodeWorkspaceSharedSettings.writeAsStringSync(contents);

        final XcodeBuildSystemMigration iosProjectMigration = XcodeBuildSystemMigration(
284
          project,
285 286
          testLogger,
        );
287
        iosProjectMigration.migrate();
288 289 290 291 292 293 294 295 296 297 298 299
        expect(xcodeWorkspaceSharedSettings.existsSync(), isTrue);
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('Xcode project is migrated', () {
        const String contents = '''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>BuildSystemType</key>
	<string>Original</string>
300 301
	<key>PreviewsEnabled</key>
	<false/>
302 303 304 305 306
</dict>
</plist>''';
        xcodeWorkspaceSharedSettings.writeAsStringSync(contents);

        final XcodeBuildSystemMigration iosProjectMigration = XcodeBuildSystemMigration(
307
          project,
308 309
          testLogger,
        );
310
        iosProjectMigration.migrate();
311 312 313 314 315
        expect(xcodeWorkspaceSharedSettings.existsSync(), isFalse);

        expect(testLogger.statusText, contains('Legacy build system detected, removing'));
      });
    });
316

317
    group('Xcode default build location', () {
318 319 320 321
      late MemoryFileSystem memoryFileSystem;
      late BufferLogger testLogger;
      late FakeIosProject project;
      late File xcodeProjectWorkspaceData;
322 323

      setUp(() {
324 325 326
        memoryFileSystem = MemoryFileSystem();
        xcodeProjectWorkspaceData = memoryFileSystem.file('contents.xcworkspacedata');
        testLogger = BufferLogger.test();
327 328
        project = FakeIosProject();
        project.xcodeProjectWorkspaceData = xcodeProjectWorkspaceData;
329 330 331 332
      });

      testWithoutContext('skipped if files are missing', () {
        final ProjectBuildLocationMigration iosProjectMigration = ProjectBuildLocationMigration(
333
          project,
334 335
          testLogger,
        );
336
        iosProjectMigration.migrate();
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354
        expect(xcodeProjectWorkspaceData.existsSync(), isFalse);

        expect(testLogger.traceText, contains('Xcode project workspace data not found, skipping build location migration.'));
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('skipped if nothing to upgrade', () {
        const String contents = '''
 <?xml version="1.0" encoding="UTF-8"?>
 <Workspace
    version = "1.0">
    <FileRef
      location = "self:">
    </FileRef>
 </Workspace>''';
        xcodeProjectWorkspaceData.writeAsStringSync(contents);

        final ProjectBuildLocationMigration iosProjectMigration = ProjectBuildLocationMigration(
355
          project,
356 357
          testLogger,
        );
358
        iosProjectMigration.migrate();
359 360 361
        expect(xcodeProjectWorkspaceData.existsSync(), isTrue);
        expect(testLogger.statusText, isEmpty);
      });
362

363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
      testWithoutContext('Xcode project is migrated', () {
        const String contents = '''
 <?xml version="1.0" encoding="UTF-8"?>
 <Workspace
   version = "1.0">
   <FileRef
      location = "group:Runner.xcodeproj">
   </FileRef>
   <FileRef
      location = "group:Pods/Pods.xcodeproj">
   </FileRef>
 </Workspace>
''';
        xcodeProjectWorkspaceData.writeAsStringSync(contents);

        final ProjectBuildLocationMigration iosProjectMigration = ProjectBuildLocationMigration(
379
          project,
380
          testLogger,
381
        );
382
        iosProjectMigration.migrate();
383 384 385 386 387 388 389 390 391 392 393 394
        expect(xcodeProjectWorkspaceData.readAsStringSync(), '''
 <?xml version="1.0" encoding="UTF-8"?>
 <Workspace
   version = "1.0">
   <FileRef
      location = "self:">
   </FileRef>
 </Workspace>
''');
        expect(testLogger.statusText, contains('Upgrading contents.xcworkspacedata'));
      });
    });
395

396
    group('remove Runner project base configuration', () {
397 398 399 400
      late MemoryFileSystem memoryFileSystem;
      late BufferLogger testLogger;
      late FakeIosProject project;
      late File xcodeProjectInfoFile;
401 402 403 404 405

      setUp(() {
        memoryFileSystem = MemoryFileSystem();
        xcodeProjectInfoFile = memoryFileSystem.file('project.pbxproj');
        testLogger = BufferLogger.test();
406 407
        project = FakeIosProject();
        project.xcodeProjectInfoFile = xcodeProjectInfoFile;
408 409 410 411
      });

      testWithoutContext('skipped if files are missing', () {
        final ProjectBaseConfigurationMigration iosProjectMigration = ProjectBaseConfigurationMigration(
412
          project,
413 414
          testLogger,
        );
415
        iosProjectMigration.migrate();
416 417 418 419 420 421 422 423 424 425 426 427
        expect(xcodeProjectInfoFile.existsSync(), isFalse);

        expect(testLogger.traceText, contains('Xcode project not found, skipping Runner project build settings and configuration migration'));
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('skipped if nothing to upgrade', () {
        const String contents = 'Nothing to upgrade';
        xcodeProjectInfoFile.writeAsStringSync(contents);
        final DateTime projectLastModified = xcodeProjectInfoFile.lastModifiedSync();

        final ProjectBaseConfigurationMigration iosProjectMigration = ProjectBaseConfigurationMigration(
428
          project,
429 430
          testLogger,
        );
431
        iosProjectMigration.migrate();
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455

        expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified);
        expect(xcodeProjectInfoFile.readAsStringSync(), contents);

        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('Xcode project is migrated with template identifiers', () {
        xcodeProjectInfoFile.writeAsStringSync('''
		97C147031CF9000F007C117D /* Debug */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
keep this 1
		249021D3217E4FDB00AE95B9 /* Profile */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
keep this 2
		97C147041CF9000F007C117D /* Release */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
keep this 3
''');

        final ProjectBaseConfigurationMigration iosProjectMigration = ProjectBaseConfigurationMigration(
456
          project,
457 458
          testLogger,
        );
459
        iosProjectMigration.migrate();
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510

        expect(xcodeProjectInfoFile.readAsStringSync(), '''
		97C147031CF9000F007C117D /* Debug */ = {
			isa = XCBuildConfiguration;
keep this 1
		249021D3217E4FDB00AE95B9 /* Profile */ = {
			isa = XCBuildConfiguration;
keep this 2
		97C147041CF9000F007C117D /* Release */ = {
			isa = XCBuildConfiguration;
keep this 3
''');
        expect(testLogger.statusText, contains('Project base configurations detected, removing.'));
      });

      testWithoutContext('Xcode project is migrated with custom identifiers', () {
        xcodeProjectInfoFile.writeAsStringSync('''
		97C147031CF9000F007C1171 /* Debug */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
		2436755321828D23008C7051 /* Profile */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
		97C147041CF9000F007C1171 /* Release */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = 7AFA3C8E1D35360C0083082E /* Release.xcconfig */;
      /* Begin XCConfigurationList section */
      97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = {
        isa = XCConfigurationList;
        buildConfigurations = (
          97C147031CF9000F007C1171 /* Debug */,
          97C147041CF9000F007C1171 /* Release */,
          2436755321828D23008C7051 /* Profile */,
        );
        defaultConfigurationIsVisible = 0;
        defaultConfigurationName = Release;
      };
      97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = {
        isa = XCConfigurationList;
        buildConfigurations = (
          97C147061CF9000F007C117D /* Debug */,
          97C147071CF9000F007C117D /* Release */,
          2436755421828D23008C705F /* Profile */,
        );
        defaultConfigurationIsVisible = 0;
        defaultConfigurationName = Release;
      };
/* End XCConfigurationList section */
''');

        final ProjectBaseConfigurationMigration iosProjectMigration = ProjectBaseConfigurationMigration(
511
          project,
512 513
          testLogger,
        );
514
        iosProjectMigration.migrate();
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548

        expect(xcodeProjectInfoFile.readAsStringSync(), '''
		97C147031CF9000F007C1171 /* Debug */ = {
			isa = XCBuildConfiguration;
		2436755321828D23008C7051 /* Profile */ = {
			isa = XCBuildConfiguration;
		97C147041CF9000F007C1171 /* Release */ = {
			isa = XCBuildConfiguration;
      /* Begin XCConfigurationList section */
      97C146E91CF9000F007C117D /* Build configuration list for PBXProject "Runner" */ = {
        isa = XCConfigurationList;
        buildConfigurations = (
          97C147031CF9000F007C1171 /* Debug */,
          97C147041CF9000F007C1171 /* Release */,
          2436755321828D23008C7051 /* Profile */,
        );
        defaultConfigurationIsVisible = 0;
        defaultConfigurationName = Release;
      };
      97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */ = {
        isa = XCConfigurationList;
        buildConfigurations = (
          97C147061CF9000F007C117D /* Debug */,
          97C147071CF9000F007C117D /* Release */,
          2436755421828D23008C705F /* Profile */,
        );
        defaultConfigurationIsVisible = 0;
        defaultConfigurationName = Release;
      };
/* End XCConfigurationList section */
''');
        expect(testLogger.statusText, contains('Project base configurations detected, removing.'));
      });
    });
549 550 551 552 553 554 555

    group('update deployment target version', () {
      late MemoryFileSystem memoryFileSystem;
      late BufferLogger testLogger;
      late FakeIosProject project;
      late File xcodeProjectInfoFile;
      late File appFrameworkInfoPlist;
556
      late File podfile;
557 558 559 560 561 562 563 564 565 566

      setUp(() {
        memoryFileSystem = MemoryFileSystem();
        testLogger = BufferLogger.test();
        project = FakeIosProject();
        xcodeProjectInfoFile = memoryFileSystem.file('project.pbxproj');
        project.xcodeProjectInfoFile = xcodeProjectInfoFile;

        appFrameworkInfoPlist = memoryFileSystem.file('AppFrameworkInfo.plist');
        project.appFrameworkInfoPlist = appFrameworkInfoPlist;
567 568 569

        podfile = memoryFileSystem.file('Podfile');
        project.podfile = podfile;
570 571 572
      });

      testWithoutContext('skipped if files are missing', () {
573
        final IOSDeploymentTargetMigration iosProjectMigration = IOSDeploymentTargetMigration(
574 575 576
          project,
          testLogger,
        );
577
        iosProjectMigration.migrate();
578 579
        expect(xcodeProjectInfoFile.existsSync(), isFalse);
        expect(appFrameworkInfoPlist.existsSync(), isFalse);
580
        expect(podfile.existsSync(), isFalse);
581 582 583

        expect(testLogger.traceText, contains('Xcode project not found, skipping iOS deployment target version migration'));
        expect(testLogger.traceText, contains('AppFrameworkInfo.plist not found, skipping minimum OS version migration'));
584
        expect(testLogger.traceText, contains('Podfile not found, skipping global platform iOS version migration'));
585 586 587 588
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('skipped if nothing to upgrade', () {
589
        const String xcodeProjectInfoFileContents = 'IPHONEOS_DEPLOYMENT_TARGET = 12.0;';
590 591 592 593
        xcodeProjectInfoFile.writeAsStringSync(xcodeProjectInfoFileContents);

        const String appFrameworkInfoPlistContents = '''
  <key>MinimumOSVersion</key>
594
  <string>12.0</string>
595 596 597 598 599
''';
        appFrameworkInfoPlist.writeAsStringSync(appFrameworkInfoPlistContents);

        final DateTime projectLastModified = xcodeProjectInfoFile.lastModifiedSync();

600
        const String podfileFileContents = "# platform :ios, '12.0'";
601 602 603
        podfile.writeAsStringSync(podfileFileContents);
        final DateTime podfileLastModified = podfile.lastModifiedSync();

604
        final IOSDeploymentTargetMigration iosProjectMigration = IOSDeploymentTargetMigration(
605 606 607
          project,
          testLogger,
        );
608
        iosProjectMigration.migrate();
609 610 611 612

        expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified);
        expect(xcodeProjectInfoFile.readAsStringSync(), xcodeProjectInfoFileContents);
        expect(appFrameworkInfoPlist.readAsStringSync(), appFrameworkInfoPlistContents);
613 614
        expect(podfile.lastModifiedSync(), podfileLastModified);
        expect(podfile.readAsStringSync(), podfileFileContents);
615 616 617 618

        expect(testLogger.statusText, isEmpty);
      });

619
      testWithoutContext('Xcode project is migrated to 12', () {
620 621 622 623 624 625 626
        xcodeProjectInfoFile.writeAsStringSync('''
				GCC_WARN_UNUSED_VARIABLE = YES;
				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
				MTL_ENABLE_DEBUG_INFO = YES;
				ONLY_ACTIVE_ARCH = YES;

				IPHONEOS_DEPLOYMENT_TARGET = 8.0;
627
				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
628
				IPHONEOS_DEPLOYMENT_TARGET = 12.0;
629 630 631 632 633 634 635 636 637 638 639
''');

        appFrameworkInfoPlist.writeAsStringSync('''
  <key>CFBundleShortVersionString</key>
  <string>1.0</string>
  <key>CFBundleSignature</key>
  <string>????</string>
  <key>CFBundleVersion</key>
  <string>1.0</string>
  <key>MinimumOSVersion</key>
  <string>8.0</string>
640 641
  <key>MinimumOSVersion</key>
  <string>11.0</string>
642 643
  <key>MinimumOSVersion</key>
  <string>12.0</string>
644 645
</dict>
</plist>
646 647 648 649 650
''');

        podfile.writeAsStringSync('''
# platform :ios, '9.0'
platform :ios, '9.0'
651 652
# platform :ios, '11.0'
platform :ios, '11.0'
653 654
''');

655
        final IOSDeploymentTargetMigration iosProjectMigration = IOSDeploymentTargetMigration(
656 657 658
          project,
          testLogger,
        );
659
        iosProjectMigration.migrate();
660 661 662

        expect(xcodeProjectInfoFile.readAsStringSync(), '''
				GCC_WARN_UNUSED_VARIABLE = YES;
663
				IPHONEOS_DEPLOYMENT_TARGET = 12.0;
664 665 666
				MTL_ENABLE_DEBUG_INFO = YES;
				ONLY_ACTIVE_ARCH = YES;

667 668 669
				IPHONEOS_DEPLOYMENT_TARGET = 12.0;
				IPHONEOS_DEPLOYMENT_TARGET = 12.0;
				IPHONEOS_DEPLOYMENT_TARGET = 12.0;
670 671 672 673 674 675 676 677 678 679
''');

        expect(appFrameworkInfoPlist.readAsStringSync(), '''
  <key>CFBundleShortVersionString</key>
  <string>1.0</string>
  <key>CFBundleSignature</key>
  <string>????</string>
  <key>CFBundleVersion</key>
  <string>1.0</string>
  <key>MinimumOSVersion</key>
680
  <string>12.0</string>
681
  <key>MinimumOSVersion</key>
682 683 684
  <string>12.0</string>
  <key>MinimumOSVersion</key>
  <string>12.0</string>
685 686
</dict>
</plist>
687 688 689
''');

        expect(podfile.readAsStringSync(), '''
690 691 692 693
# platform :ios, '12.0'
platform :ios, '12.0'
# platform :ios, '12.0'
platform :ios, '12.0'
694 695
''');
        // Only print once even though 2 lines were changed.
696
        expect('Updating minimum iOS deployment target to 12.0'.allMatches(testLogger.statusText).length, 1);
697 698
      });
    });
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714

    group('update Xcode project object version', () {
      late MemoryFileSystem memoryFileSystem;
      late BufferLogger testLogger;
      late FakeIosProject project;
      late File xcodeProjectInfoFile;
      late File xcodeProjectSchemeFile;

      setUp(() {
        memoryFileSystem = MemoryFileSystem();
        testLogger = BufferLogger.test();
        project = FakeIosProject();
        xcodeProjectInfoFile = memoryFileSystem.file('project.pbxproj');
        project.xcodeProjectInfoFile = xcodeProjectInfoFile;

        xcodeProjectSchemeFile = memoryFileSystem.file('Runner.xcscheme');
715
        project.schemeFile = xcodeProjectSchemeFile;
716 717 718
      });

      testWithoutContext('skipped if files are missing', () {
719
        final XcodeProjectObjectVersionMigration iosProjectMigration = XcodeProjectObjectVersionMigration(
720 721 722
          project,
          testLogger,
        );
723
        iosProjectMigration.migrate();
724 725 726 727 728 729 730 731 732 733 734 735
        expect(xcodeProjectInfoFile.existsSync(), isFalse);
        expect(xcodeProjectSchemeFile.existsSync(), isFalse);

        expect(testLogger.traceText, contains('Xcode project not found, skipping Xcode compatibility migration'));
        expect(testLogger.traceText, contains('Runner scheme not found, skipping Xcode compatibility migration'));
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('skipped if nothing to upgrade', () {
        const String xcodeProjectInfoFileContents = '''
	classes = {
	};
736
	objectVersion = 54;
737 738
	objects = {
			attributes = {
739
				LastUpgradeCheck = 1510;
740 741 742 743 744
				ORGANIZATIONNAME = "";
      ''';
        xcodeProjectInfoFile.writeAsStringSync(xcodeProjectInfoFileContents);

        const String xcodeProjectSchemeFileContents = '''
745
   LastUpgradeVersion = "1510"
746 747 748 749 750
''';
        xcodeProjectSchemeFile.writeAsStringSync(xcodeProjectSchemeFileContents);

        final DateTime projectLastModified = xcodeProjectInfoFile.lastModifiedSync();

751
        final XcodeProjectObjectVersionMigration iosProjectMigration = XcodeProjectObjectVersionMigration(
752 753 754
          project,
          testLogger,
        );
755
        iosProjectMigration.migrate();
756 757 758 759 760 761 762 763

        expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified);
        expect(xcodeProjectInfoFile.readAsStringSync(), xcodeProjectInfoFileContents);
        expect(xcodeProjectSchemeFile.readAsStringSync(), xcodeProjectSchemeFileContents);

        expect(testLogger.statusText, isEmpty);
      });

764
      testWithoutContext('Xcode project is migrated to newest objectVersion', () {
765 766 767 768 769 770
        xcodeProjectInfoFile.writeAsStringSync('''
	classes = {
	};
	objectVersion = 46;
	objects = {
			attributes = {
771
				LastUpgradeCheck = 1430;
772 773 774 775 776
				ORGANIZATIONNAME = "";
''');

        xcodeProjectSchemeFile.writeAsStringSync('''
<Scheme
777
   LastUpgradeVersion = "1430"
778 779 780
   version = "1.3">
''');

781
        final XcodeProjectObjectVersionMigration iosProjectMigration = XcodeProjectObjectVersionMigration(
782 783 784
          project,
          testLogger,
        );
785
        iosProjectMigration.migrate();
786 787 788 789

        expect(xcodeProjectInfoFile.readAsStringSync(), '''
	classes = {
	};
790
	objectVersion = 54;
791 792
	objects = {
			attributes = {
793
				LastUpgradeCheck = 1510;
794 795 796 797 798
				ORGANIZATIONNAME = "";
''');

        expect(xcodeProjectSchemeFile.readAsStringSync(), '''
<Scheme
799
   LastUpgradeVersion = "1510"
800 801 802 803 804 805
   version = "1.3">
''');
        // Only print once even though 3 lines were changed.
        expect('Updating project for Xcode compatibility'.allMatches(testLogger.statusText).length, 1);
      });
    });
806

807
    group('update info.plist migration', () {
808 809 810 811 812 813 814 815 816 817 818 819 820 821
      late MemoryFileSystem memoryFileSystem;
      late BufferLogger testLogger;
      late FakeIosProject project;
      late File infoPlistFile;

      setUp(() {
        memoryFileSystem = MemoryFileSystem();
        testLogger = BufferLogger.test();
        project = FakeIosProject();
        infoPlistFile = memoryFileSystem.file('info.plist');
        project.defaultHostInfoPlist = infoPlistFile;
      });

      testWithoutContext('skipped if files are missing', () {
822
        final HostAppInfoPlistMigration iosProjectMigration = HostAppInfoPlistMigration(
823 824 825
          project,
          testLogger,
        );
826
        iosProjectMigration.migrate();
827 828
        expect(infoPlistFile.existsSync(), isFalse);

829
        expect(testLogger.traceText, contains('Info.plist not found, skipping host app Info.plist migration.'));
830 831 832 833 834 835 836 837 838 839 840
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('skipped if nothing to upgrade', () {
        const String infoPlistFileContent = '''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CADisableMinimumFrameDurationOnPhone</key>
	<true/>
841 842
	<key>UIApplicationSupportsIndirectInputEvents</key>
	<true/>
843 844 845 846 847
</dict>
</plist>
''';
        infoPlistFile.writeAsStringSync(infoPlistFileContent);

848
        final HostAppInfoPlistMigration iosProjectMigration = HostAppInfoPlistMigration(
849 850 851 852
          project,
          testLogger,
        );
        final DateTime infoPlistFileLastModified = infoPlistFile.lastModifiedSync();
853
        iosProjectMigration.migrate();
854 855 856 857 858

        expect(infoPlistFile.lastModifiedSync(), infoPlistFileLastModified);
        expect(testLogger.statusText, isEmpty);
      });

859
      testWithoutContext('info.plist is migrated', () {
860 861 862 863 864 865 866 867 868 869
        const String infoPlistFileContent = '''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
</dict>
</plist>
''';
        infoPlistFile.writeAsStringSync(infoPlistFileContent);

870
        final HostAppInfoPlistMigration iosProjectMigration = HostAppInfoPlistMigration(
871 872 873
          project,
          testLogger,
        );
874
        iosProjectMigration.migrate();
875 876 877 878 879 880 881
        expect(infoPlistFile.readAsStringSync(), equals('''
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>CADisableMinimumFrameDurationOnPhone</key>
	<true/>
882 883
	<key>UIApplicationSupportsIndirectInputEvents</key>
	<true/>
884 885 886 887 888
</dict>
</plist>
'''));
      });
    });
889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916

    group('remove bitcode build setting', () {
      late MemoryFileSystem memoryFileSystem;
      late BufferLogger testLogger;
      late FakeIosProject project;
      late File xcodeProjectInfoFile;

      setUp(() {
        memoryFileSystem = MemoryFileSystem();
        testLogger = BufferLogger.test();
        project = FakeIosProject();
        xcodeProjectInfoFile = memoryFileSystem.file('project.pbxproj');
        project.xcodeProjectInfoFile = xcodeProjectInfoFile;
      });

      testWithoutContext('skipped if files are missing', () {
        final RemoveBitcodeMigration migration = RemoveBitcodeMigration(
          project,
          testLogger,
        );
        expect(migration.migrate(), isTrue);
        expect(xcodeProjectInfoFile.existsSync(), isFalse);

        expect(testLogger.traceText, contains('Xcode project not found, skipping removing bitcode migration'));
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('skipped if nothing to upgrade', () {
917
        const String xcodeProjectInfoFileContents = 'IPHONEOS_DEPLOYMENT_TARGET = 12.0;';
918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958
        xcodeProjectInfoFile.writeAsStringSync(xcodeProjectInfoFileContents);
        final DateTime projectLastModified = xcodeProjectInfoFile.lastModifiedSync();

        final RemoveBitcodeMigration migration = RemoveBitcodeMigration(
          project,
          testLogger,
        );
        expect(migration.migrate(), isTrue);

        expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified);
        expect(xcodeProjectInfoFile.readAsStringSync(), xcodeProjectInfoFileContents);

        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('bitcode build setting is removed', () {
        xcodeProjectInfoFile.writeAsStringSync('''
				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
				ENABLE_BITCODE = YES;
				INFOPLIST_FILE = Runner/Info.plist;

				ENABLE_BITCODE = YES;
''');

        final RemoveBitcodeMigration migration = RemoveBitcodeMigration(
          project,
          testLogger,
        );
        expect(migration.migrate(), isTrue);

        expect(xcodeProjectInfoFile.readAsStringSync(), '''
				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
				ENABLE_BITCODE = NO;
				INFOPLIST_FILE = Runner/Info.plist;

				ENABLE_BITCODE = NO;
''');
        // Only print once even though 2 lines were changed.
        expect('Disabling deprecated bitcode Xcode build setting'.allMatches(testLogger.warningText).length, 1);
      });
    });
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056

    group('CocoaPods script readlink', () {
      late MemoryFileSystem memoryFileSystem;
      late BufferLogger testLogger;
      late FakeIosProject project;
      late File podRunnerFrameworksScript;
      late ProcessManager processManager;
      late XcodeProjectInterpreter xcode143ProjectInterpreter;

      setUp(() {
        memoryFileSystem = MemoryFileSystem();
        podRunnerFrameworksScript = memoryFileSystem.file('Pods-Runner-frameworks.sh');
        testLogger = BufferLogger.test();
        project = FakeIosProject();
        processManager = FakeProcessManager.any();
        xcode143ProjectInterpreter = XcodeProjectInterpreter.test(processManager: processManager, version: Version(14, 3, 0));
        project.podRunnerFrameworksScript = podRunnerFrameworksScript;
      });

      testWithoutContext('skipped if files are missing', () {
        final CocoaPodsScriptReadlink iosProjectMigration = CocoaPodsScriptReadlink(
          project,
          xcode143ProjectInterpreter,
          testLogger,
        );
        iosProjectMigration.migrate();
        expect(podRunnerFrameworksScript.existsSync(), isFalse);

        expect(testLogger.traceText, contains('CocoaPods Pods-Runner-frameworks.sh script not found'));
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('skipped if nothing to upgrade', () {
        const String contents = r'''
  if [ -L "${source}" ]; then
    echo "Symlinked..."
    source="$(readlink -f "${source}")"
  fi''';
        podRunnerFrameworksScript.writeAsStringSync(contents);

        final CocoaPodsScriptReadlink iosProjectMigration = CocoaPodsScriptReadlink(
          project,
          xcode143ProjectInterpreter,
          testLogger,
        );
        iosProjectMigration.migrate();
        expect(podRunnerFrameworksScript.existsSync(), isTrue);
        expect(testLogger.traceText, isEmpty);
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('skipped if Xcode version below 14.3', () {
        const String contents = r'''
  if [ -L "${source}" ]; then
    echo "Symlinked..."
    source="$(readlink "${source}")"
  fi''';
        podRunnerFrameworksScript.writeAsStringSync(contents);

        final XcodeProjectInterpreter xcode142ProjectInterpreter = XcodeProjectInterpreter.test(
          processManager: processManager,
          version: Version(14, 2, 0),
        );

        final CocoaPodsScriptReadlink iosProjectMigration = CocoaPodsScriptReadlink(
          project,
          xcode142ProjectInterpreter,
          testLogger,
        );
        iosProjectMigration.migrate();
        expect(podRunnerFrameworksScript.existsSync(), isTrue);
        expect(testLogger.traceText, contains('Detected Xcode version is 14.2.0, below 14.3, skipping "readlink -f" workaround'));
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('Xcode project is migrated', () {
        const String contents = r'''
  if [ -L "${source}" ]; then
    echo "Symlinked..."
    source="$(readlink "${source}")"
  fi''';
        podRunnerFrameworksScript.writeAsStringSync(contents);

        final CocoaPodsScriptReadlink iosProjectMigration = CocoaPodsScriptReadlink(
          project,
          xcode143ProjectInterpreter,
          testLogger,
        );
        iosProjectMigration.migrate();
        expect(podRunnerFrameworksScript.readAsStringSync(), r'''
  if [ -L "${source}" ]; then
    echo "Symlinked..."
    source="$(readlink -f "${source}")"
  fi
''');
        expect(testLogger.statusText, contains('Upgrading Pods-Runner-frameworks.sh'));
      });
    });
1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200

    group('Cocoapods migrate toolchain directory', () {
      late MemoryFileSystem memoryFileSystem;
      late BufferLogger testLogger;
      late FakeIosProject project;
      late Directory podRunnerTargetSupportFiles;
      late ProcessManager processManager;
      late XcodeProjectInterpreter xcode15ProjectInterpreter;

      setUp(() {
        memoryFileSystem = MemoryFileSystem();
        podRunnerTargetSupportFiles = memoryFileSystem.directory('Pods-Runner');
        testLogger = BufferLogger.test();
        project = FakeIosProject();
        processManager = FakeProcessManager.any();
        xcode15ProjectInterpreter = XcodeProjectInterpreter.test(processManager: processManager, version: Version(15, 0, 0));
        project.podRunnerTargetSupportFiles = podRunnerTargetSupportFiles;
      });

      testWithoutContext('skip if directory is missing', () {
        final CocoaPodsToolchainDirectoryMigration iosProjectMigration = CocoaPodsToolchainDirectoryMigration(
          project,
          xcode15ProjectInterpreter,
          testLogger,
        );
        iosProjectMigration.migrate();
        expect(podRunnerTargetSupportFiles.existsSync(), isFalse);

        expect(testLogger.traceText, contains('CocoaPods Pods-Runner Target Support Files not found'));
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('skip if xcconfig files are missing', () {
        podRunnerTargetSupportFiles.createSync();
        final CocoaPodsToolchainDirectoryMigration iosProjectMigration = CocoaPodsToolchainDirectoryMigration(
          project,
          xcode15ProjectInterpreter,
          testLogger,
        );
        iosProjectMigration.migrate();
        expect(podRunnerTargetSupportFiles.existsSync(), isTrue);
        expect(testLogger.traceText, isEmpty);
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('skip if nothing to upgrade', () {
        podRunnerTargetSupportFiles.createSync();
        final File debugConfig = podRunnerTargetSupportFiles.childFile('Pods-Runner.debug.xcconfig');
        const String contents = r'''
LD_RUNPATH_SEARCH_PATHS = $(inherited) /usr/lib/swift '@executable_path/../Frameworks' '@loader_path/Frameworks' "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
LIBRARY_SEARCH_PATHS = $(inherited) "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" /usr/lib/swift
''';
        debugConfig.writeAsStringSync(contents);

        final File profileConfig = podRunnerTargetSupportFiles.childFile('Pods-Runner.profile.xcconfig');
        profileConfig.writeAsStringSync(contents);

        final File releaseConfig = podRunnerTargetSupportFiles.childFile('Pods-Runner.release.xcconfig');
        releaseConfig.writeAsStringSync(contents);

        final CocoaPodsToolchainDirectoryMigration iosProjectMigration = CocoaPodsToolchainDirectoryMigration(
          project,
          xcode15ProjectInterpreter,
          testLogger,
        );
        iosProjectMigration.migrate();
        expect(debugConfig.existsSync(), isTrue);
        expect(testLogger.traceText, isEmpty);
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('skipped if Xcode version below 15', () {
        podRunnerTargetSupportFiles.createSync();
        final File debugConfig = podRunnerTargetSupportFiles.childFile('Pods-Runner.debug.xcconfig');
        const String contents = r'''
LD_RUNPATH_SEARCH_PATHS = $(inherited) /usr/lib/swift '@executable_path/../Frameworks' '@loader_path/Frameworks' "${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
LIBRARY_SEARCH_PATHS = $(inherited) "${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" /usr/lib/swift
''';
        debugConfig.writeAsStringSync(contents);

        final File profileConfig = podRunnerTargetSupportFiles.childFile('Pods-Runner.profile.xcconfig');
        profileConfig.writeAsStringSync(contents);

        final File releaseConfig = podRunnerTargetSupportFiles.childFile('Pods-Runner.release.xcconfig');
        releaseConfig.writeAsStringSync(contents);

        final XcodeProjectInterpreter xcode14ProjectInterpreter = XcodeProjectInterpreter.test(
          processManager: processManager,
          version: Version(14, 0, 0),
        );

        final CocoaPodsToolchainDirectoryMigration iosProjectMigration = CocoaPodsToolchainDirectoryMigration(
          project,
          xcode14ProjectInterpreter,
          testLogger,
        );
        iosProjectMigration.migrate();
        expect(debugConfig.existsSync(), isTrue);
        expect(testLogger.traceText, contains('Detected Xcode version is 14.0.0, below 15.0'));
        expect(testLogger.statusText, isEmpty);
      });

      testWithoutContext('Xcode project is migrated and ignores leading whitespace', () {
        podRunnerTargetSupportFiles.createSync();
        final File debugConfig = podRunnerTargetSupportFiles.childFile('Pods-Runner.debug.xcconfig');
        const String contents = r'''
LD_RUNPATH_SEARCH_PATHS = $(inherited) /usr/lib/swift '@executable_path/../Frameworks' '@loader_path/Frameworks' "${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
  LIBRARY_SEARCH_PATHS = $(inherited) "${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" /usr/lib/swift
''';
        debugConfig.writeAsStringSync(contents);

        final File profileConfig = podRunnerTargetSupportFiles.childFile('Pods-Runner.profile.xcconfig');
        profileConfig.writeAsStringSync(contents);

        final File releaseConfig = podRunnerTargetSupportFiles.childFile('Pods-Runner.release.xcconfig');
        releaseConfig.writeAsStringSync(contents);

        final CocoaPodsToolchainDirectoryMigration iosProjectMigration = CocoaPodsToolchainDirectoryMigration(
          project,
          xcode15ProjectInterpreter,
          testLogger,
        );
        iosProjectMigration.migrate();

        expect(debugConfig.existsSync(), isTrue);
        expect(debugConfig.readAsStringSync(), r'''
LD_RUNPATH_SEARCH_PATHS = $(inherited) /usr/lib/swift '@executable_path/../Frameworks' '@loader_path/Frameworks' "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
  LIBRARY_SEARCH_PATHS = $(inherited) "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" /usr/lib/swift
''');
        expect(profileConfig.existsSync(), isTrue);
        expect(profileConfig.readAsStringSync(), r'''
LD_RUNPATH_SEARCH_PATHS = $(inherited) /usr/lib/swift '@executable_path/../Frameworks' '@loader_path/Frameworks' "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
  LIBRARY_SEARCH_PATHS = $(inherited) "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" /usr/lib/swift
''');
        expect(releaseConfig.existsSync(), isTrue);
        expect(releaseConfig.readAsStringSync(), r'''
LD_RUNPATH_SEARCH_PATHS = $(inherited) /usr/lib/swift '@executable_path/../Frameworks' '@loader_path/Frameworks' "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
  LIBRARY_SEARCH_PATHS = $(inherited) "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" /usr/lib/swift
''');
        expect(testLogger.statusText, contains('Upgrading Pods-Runner.debug.xcconfig'));
        expect(testLogger.statusText, contains('Upgrading Pods-Runner.profile.xcconfig'));
        expect(testLogger.statusText, contains('Upgrading Pods-Runner.release.xcconfig'));
      });
    });
1201
  });
1202

1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
  group('update Xcode script build phase', () {
    late MemoryFileSystem memoryFileSystem;
    late BufferLogger testLogger;
    late FakeIosProject project;
    late File xcodeProjectInfoFile;

    setUp(() {
      memoryFileSystem = MemoryFileSystem();
      testLogger = BufferLogger.test();
      project = FakeIosProject();
      xcodeProjectInfoFile = memoryFileSystem.file('project.pbxproj');
      project.xcodeProjectInfoFile = xcodeProjectInfoFile;
    });

    testWithoutContext('skipped if files are missing', () {
      final XcodeScriptBuildPhaseMigration iosProjectMigration = XcodeScriptBuildPhaseMigration(
        project,
        testLogger,
      );
1222
      iosProjectMigration.migrate();
1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247
      expect(xcodeProjectInfoFile.existsSync(), isFalse);

      expect(testLogger.traceText, contains('Xcode project not found, skipping script build phase dependency analysis removal'));
      expect(testLogger.statusText, isEmpty);
    });

    testWithoutContext('skipped if nothing to upgrade', () {
      const String xcodeProjectInfoFileContents = '''
/* Begin PBXShellScriptBuildPhase section */
		3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
			isa = PBXShellScriptBuildPhase;
			alwaysOutOfDate = 1;
			buildActionMask = 2147483647;
			files = (
			);
			inputPaths = (
      ''';
      xcodeProjectInfoFile.writeAsStringSync(xcodeProjectInfoFileContents);

      final DateTime projectLastModified = xcodeProjectInfoFile.lastModifiedSync();

      final XcodeScriptBuildPhaseMigration iosProjectMigration = XcodeScriptBuildPhaseMigration(
        project,
        testLogger,
      );
1248
      iosProjectMigration.migrate();
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278

      expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified);
      expect(xcodeProjectInfoFile.readAsStringSync(), xcodeProjectInfoFileContents);

      expect(testLogger.statusText, isEmpty);
    });

    testWithoutContext('alwaysOutOfDate is migrated', () {
      xcodeProjectInfoFile.writeAsStringSync('''
/* Begin PBXShellScriptBuildPhase section */
		3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
			isa = PBXShellScriptBuildPhase;
			buildActionMask = 2147483647;
			files = (
			);
			inputPaths = (

		9740EEB61CF901F6004384FC /* Run Script */ = {
			isa = PBXShellScriptBuildPhase;
			buildActionMask = 2147483647;
			files = (
			);
			inputPaths = (
			);
''');

      final XcodeScriptBuildPhaseMigration iosProjectMigration = XcodeScriptBuildPhaseMigration(
        project,
        testLogger,
      );
1279
      iosProjectMigration.migrate();
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302

      expect(xcodeProjectInfoFile.readAsStringSync(), '''
/* Begin PBXShellScriptBuildPhase section */
		3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
			isa = PBXShellScriptBuildPhase;
			alwaysOutOfDate = 1;
			buildActionMask = 2147483647;
			files = (
			);
			inputPaths = (

		9740EEB61CF901F6004384FC /* Run Script */ = {
			isa = PBXShellScriptBuildPhase;
			alwaysOutOfDate = 1;
			buildActionMask = 2147483647;
			files = (
			);
			inputPaths = (
			);
''');
      expect(testLogger.statusText, contains('Removing script build phase dependency analysis'));
    });
  });
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410

  group('update Xcode Thin Binary build phase to have input path', () {
    late MemoryFileSystem memoryFileSystem;
    late BufferLogger testLogger;
    late FakeIosProject project;
    late File xcodeProjectInfoFile;

    setUp(() {
      memoryFileSystem = MemoryFileSystem();
      testLogger = BufferLogger.test();
      project = FakeIosProject();
      xcodeProjectInfoFile = memoryFileSystem.file('project.pbxproj');
      project.xcodeProjectInfoFile = xcodeProjectInfoFile;
    });

    testWithoutContext('skipped if files are missing', () {
      final XcodeThinBinaryBuildPhaseInputPathsMigration iosProjectMigration = XcodeThinBinaryBuildPhaseInputPathsMigration(
        project,
        testLogger,
      );
      iosProjectMigration.migrate();
      expect(xcodeProjectInfoFile.existsSync(), isFalse);

      expect(testLogger.traceText, contains('Xcode project not found, skipping script build phase dependency analysis removal'));
      expect(testLogger.statusText, isEmpty);
    });

    testWithoutContext('skipped if nothing to upgrade', () {
      const String xcodeProjectInfoFileContents = r'''
/* Begin PBXShellScriptBuildPhase section */
		3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
			isa = PBXShellScriptBuildPhase;
			alwaysOutOfDate = 1;
			buildActionMask = 2147483647;
			files = (
			);
			inputPaths = (
				"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
			);
      ''';
      xcodeProjectInfoFile.writeAsStringSync(xcodeProjectInfoFileContents);

      final DateTime projectLastModified = xcodeProjectInfoFile.lastModifiedSync();

      final XcodeThinBinaryBuildPhaseInputPathsMigration iosProjectMigration = XcodeThinBinaryBuildPhaseInputPathsMigration(
        project,
        testLogger,
      );
      iosProjectMigration.migrate();

      expect(xcodeProjectInfoFile.lastModifiedSync(), projectLastModified);
      expect(xcodeProjectInfoFile.readAsStringSync(), xcodeProjectInfoFileContents);

      expect(testLogger.statusText, isEmpty);
    });

    testWithoutContext('Thin Binary inputPaths is migrated', () {
      xcodeProjectInfoFile.writeAsStringSync(r'''
/* Begin PBXShellScriptBuildPhase section */
		3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
			isa = PBXShellScriptBuildPhase;
			alwaysOutOfDate = 1;
			buildActionMask = 2147483647;
			files = (
			);
			inputPaths = (
			);

		9740EEB61CF901F6004384FC /* Run Script */ = {
			isa = PBXShellScriptBuildPhase;
			alwaysOutOfDate = 1;
			buildActionMask = 2147483647;
			files = (
			);
			inputPaths = (
			);
''');

      final XcodeThinBinaryBuildPhaseInputPathsMigration iosProjectMigration = XcodeThinBinaryBuildPhaseInputPathsMigration(
        project,
        testLogger,
      );
      iosProjectMigration.migrate();

      expect(xcodeProjectInfoFile.readAsStringSync(), r'''
/* Begin PBXShellScriptBuildPhase section */
		3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
			isa = PBXShellScriptBuildPhase;
			alwaysOutOfDate = 1;
			buildActionMask = 2147483647;
			files = (
			);
			inputPaths = (
				"${TARGET_BUILD_DIR}/${INFOPLIST_PATH}",
			);

		9740EEB61CF901F6004384FC /* Run Script */ = {
			isa = PBXShellScriptBuildPhase;
			alwaysOutOfDate = 1;
			buildActionMask = 2147483647;
			files = (
			);
			inputPaths = (
			);
''');
      expect(testLogger.statusText, contains('Adding input path to Thin Binary build phase.'));
    });
  });
1411 1412
}

1413 1414
class FakeIosProject extends Fake implements IosProject {
  @override
1415
  File xcodeProjectWorkspaceData = MemoryFileSystem.test().file('xcodeProjectWorkspaceData');
1416 1417

  @override
1418
  File? xcodeWorkspaceSharedSettings = MemoryFileSystem.test().file('xcodeWorkspaceSharedSettings');
1419 1420

  @override
1421
  File xcodeProjectInfoFile = MemoryFileSystem.test().file('xcodeProjectInfoFile');
1422

1423 1424
  File? schemeFile;

1425
  @override
1426
  File xcodeProjectSchemeFile({String? scheme}) => schemeFile ?? MemoryFileSystem.test().file('xcodeProjectSchemeFile');
1427

1428 1429
  @override
  File appFrameworkInfoPlist = MemoryFileSystem.test().file('appFrameworkInfoPlist');
1430 1431 1432

  @override
  File defaultHostInfoPlist = MemoryFileSystem.test().file('defaultHostInfoPlist');
1433 1434 1435

  @override
  File podfile = MemoryFileSystem.test().file('Podfile');
1436 1437 1438

  @override
  File podRunnerFrameworksScript = MemoryFileSystem.test().file('podRunnerFrameworksScript');
1439 1440 1441

  @override
  Directory podRunnerTargetSupportFiles = MemoryFileSystem.test().directory('Pods-Runner');
1442
}
1443

1444
class FakeIOSMigrator extends ProjectMigrator {
1445
  FakeIOSMigrator()
1446
    : super(BufferLogger.test());
1447 1448

  @override
1449
  void migrate() {}
1450 1451 1452 1453 1454 1455

  @override
  String migrateLine(String line) {
    return line;
  }
}