@@ -16,6 +16,7 @@ import 'package:flutter_tools/src/ios/migrations/remove_framework_link_and_embed
1616import 'package:flutter_tools/src/ios/migrations/xcode_build_system_migration.dart' ;
1717import 'package:flutter_tools/src/ios/xcodeproj.dart' ;
1818import 'package:flutter_tools/src/migrations/cocoapods_script_symlink.dart' ;
19+ import 'package:flutter_tools/src/migrations/cocoapods_toolchain_directory_migration.dart' ;
1920import 'package:flutter_tools/src/migrations/xcode_project_object_version_migration.dart' ;
2021import 'package:flutter_tools/src/migrations/xcode_script_build_phase_migration.dart' ;
2122import 'package:flutter_tools/src/migrations/xcode_thin_binary_build_phase_input_paths_migration.dart' ;
@@ -1003,6 +1004,150 @@ platform :ios, '11.0'
10031004 expect (testLogger.statusText, contains ('Upgrading Pods-Runner-frameworks.sh' ));
10041005 });
10051006 });
1007+
1008+ group ('Cocoapods migrate toolchain directory' , () {
1009+ late MemoryFileSystem memoryFileSystem;
1010+ late BufferLogger testLogger;
1011+ late FakeIosProject project;
1012+ late Directory podRunnerTargetSupportFiles;
1013+ late ProcessManager processManager;
1014+ late XcodeProjectInterpreter xcode15ProjectInterpreter;
1015+
1016+ setUp (() {
1017+ memoryFileSystem = MemoryFileSystem ();
1018+ podRunnerTargetSupportFiles = memoryFileSystem.directory ('Pods-Runner' );
1019+ testLogger = BufferLogger .test ();
1020+ project = FakeIosProject ();
1021+ processManager = FakeProcessManager .any ();
1022+ xcode15ProjectInterpreter = XcodeProjectInterpreter .test (processManager: processManager, version: Version (15 , 0 , 0 ));
1023+ project.podRunnerTargetSupportFiles = podRunnerTargetSupportFiles;
1024+ });
1025+
1026+ testWithoutContext ('skip if directory is missing' , () {
1027+ final CocoaPodsToolchainDirectoryMigration iosProjectMigration = CocoaPodsToolchainDirectoryMigration (
1028+ project,
1029+ xcode15ProjectInterpreter,
1030+ testLogger,
1031+ );
1032+ iosProjectMigration.migrate ();
1033+ expect (podRunnerTargetSupportFiles.existsSync (), isFalse);
1034+
1035+ expect (testLogger.traceText, contains ('CocoaPods Pods-Runner Target Support Files not found' ));
1036+ expect (testLogger.statusText, isEmpty);
1037+ });
1038+
1039+ testWithoutContext ('skip if xcconfig files are missing' , () {
1040+ podRunnerTargetSupportFiles.createSync ();
1041+ final CocoaPodsToolchainDirectoryMigration iosProjectMigration = CocoaPodsToolchainDirectoryMigration (
1042+ project,
1043+ xcode15ProjectInterpreter,
1044+ testLogger,
1045+ );
1046+ iosProjectMigration.migrate ();
1047+ expect (podRunnerTargetSupportFiles.existsSync (), isTrue);
1048+ expect (testLogger.traceText, isEmpty);
1049+ expect (testLogger.statusText, isEmpty);
1050+ });
1051+
1052+ testWithoutContext ('skip if nothing to upgrade' , () {
1053+ podRunnerTargetSupportFiles.createSync ();
1054+ final File debugConfig = podRunnerTargetSupportFiles.childFile ('Pods-Runner.debug.xcconfig' );
1055+ const String contents = r'''
1056+ LD_RUNPATH_SEARCH_PATHS = $(inherited) /usr/lib/swift '@executable_path/../Frameworks' '@loader_path/Frameworks' "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
1057+ LIBRARY_SEARCH_PATHS = $(inherited) "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" /usr/lib/swift
1058+ ''' ;
1059+ debugConfig.writeAsStringSync (contents);
1060+
1061+ final File profileConfig = podRunnerTargetSupportFiles.childFile ('Pods-Runner.profile.xcconfig' );
1062+ profileConfig.writeAsStringSync (contents);
1063+
1064+ final File releaseConfig = podRunnerTargetSupportFiles.childFile ('Pods-Runner.release.xcconfig' );
1065+ releaseConfig.writeAsStringSync (contents);
1066+
1067+ final CocoaPodsToolchainDirectoryMigration iosProjectMigration = CocoaPodsToolchainDirectoryMigration (
1068+ project,
1069+ xcode15ProjectInterpreter,
1070+ testLogger,
1071+ );
1072+ iosProjectMigration.migrate ();
1073+ expect (debugConfig.existsSync (), isTrue);
1074+ expect (testLogger.traceText, isEmpty);
1075+ expect (testLogger.statusText, isEmpty);
1076+ });
1077+
1078+ testWithoutContext ('skipped if Xcode version below 15' , () {
1079+ podRunnerTargetSupportFiles.createSync ();
1080+ final File debugConfig = podRunnerTargetSupportFiles.childFile ('Pods-Runner.debug.xcconfig' );
1081+ const String contents = r'''
1082+ LD_RUNPATH_SEARCH_PATHS = $(inherited) /usr/lib/swift '@executable_path/../Frameworks' '@loader_path/Frameworks' "${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
1083+ LIBRARY_SEARCH_PATHS = $(inherited) "${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" /usr/lib/swift
1084+ ''' ;
1085+ debugConfig.writeAsStringSync (contents);
1086+
1087+ final File profileConfig = podRunnerTargetSupportFiles.childFile ('Pods-Runner.profile.xcconfig' );
1088+ profileConfig.writeAsStringSync (contents);
1089+
1090+ final File releaseConfig = podRunnerTargetSupportFiles.childFile ('Pods-Runner.release.xcconfig' );
1091+ releaseConfig.writeAsStringSync (contents);
1092+
1093+ final XcodeProjectInterpreter xcode14ProjectInterpreter = XcodeProjectInterpreter .test (
1094+ processManager: processManager,
1095+ version: Version (14 , 0 , 0 ),
1096+ );
1097+
1098+ final CocoaPodsToolchainDirectoryMigration iosProjectMigration = CocoaPodsToolchainDirectoryMigration (
1099+ project,
1100+ xcode14ProjectInterpreter,
1101+ testLogger,
1102+ );
1103+ iosProjectMigration.migrate ();
1104+ expect (debugConfig.existsSync (), isTrue);
1105+ expect (testLogger.traceText, contains ('Detected Xcode version is 14.0.0, below 15.0' ));
1106+ expect (testLogger.statusText, isEmpty);
1107+ });
1108+
1109+ testWithoutContext ('Xcode project is migrated and ignores leading whitespace' , () {
1110+ podRunnerTargetSupportFiles.createSync ();
1111+ final File debugConfig = podRunnerTargetSupportFiles.childFile ('Pods-Runner.debug.xcconfig' );
1112+ const String contents = r'''
1113+ LD_RUNPATH_SEARCH_PATHS = $(inherited) /usr/lib/swift '@executable_path/../Frameworks' '@loader_path/Frameworks' "${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
1114+ LIBRARY_SEARCH_PATHS = $(inherited) "${DT_TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" /usr/lib/swift
1115+ ''' ;
1116+ debugConfig.writeAsStringSync (contents);
1117+
1118+ final File profileConfig = podRunnerTargetSupportFiles.childFile ('Pods-Runner.profile.xcconfig' );
1119+ profileConfig.writeAsStringSync (contents);
1120+
1121+ final File releaseConfig = podRunnerTargetSupportFiles.childFile ('Pods-Runner.release.xcconfig' );
1122+ releaseConfig.writeAsStringSync (contents);
1123+
1124+ final CocoaPodsToolchainDirectoryMigration iosProjectMigration = CocoaPodsToolchainDirectoryMigration (
1125+ project,
1126+ xcode15ProjectInterpreter,
1127+ testLogger,
1128+ );
1129+ iosProjectMigration.migrate ();
1130+
1131+ expect (debugConfig.existsSync (), isTrue);
1132+ expect (debugConfig.readAsStringSync (), r'''
1133+ LD_RUNPATH_SEARCH_PATHS = $(inherited) /usr/lib/swift '@executable_path/../Frameworks' '@loader_path/Frameworks' "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
1134+ LIBRARY_SEARCH_PATHS = $(inherited) "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" /usr/lib/swift
1135+ ''' );
1136+ expect (profileConfig.existsSync (), isTrue);
1137+ expect (profileConfig.readAsStringSync (), r'''
1138+ LD_RUNPATH_SEARCH_PATHS = $(inherited) /usr/lib/swift '@executable_path/../Frameworks' '@loader_path/Frameworks' "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
1139+ LIBRARY_SEARCH_PATHS = $(inherited) "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" /usr/lib/swift
1140+ ''' );
1141+ expect (releaseConfig.existsSync (), isTrue);
1142+ expect (releaseConfig.readAsStringSync (), r'''
1143+ LD_RUNPATH_SEARCH_PATHS = $(inherited) /usr/lib/swift '@executable_path/../Frameworks' '@loader_path/Frameworks' "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}"
1144+ LIBRARY_SEARCH_PATHS = $(inherited) "${TOOLCHAIN_DIR}/usr/lib/swift/${PLATFORM_NAME}" /usr/lib/swift
1145+ ''' );
1146+ expect (testLogger.statusText, contains ('Upgrading Pods-Runner.debug.xcconfig' ));
1147+ expect (testLogger.statusText, contains ('Upgrading Pods-Runner.profile.xcconfig' ));
1148+ expect (testLogger.statusText, contains ('Upgrading Pods-Runner.release.xcconfig' ));
1149+ });
1150+ });
10061151 });
10071152
10081153 group ('update Xcode script build phase' , () {
@@ -1239,6 +1384,9 @@ class FakeIosProject extends Fake implements IosProject {
12391384
12401385 @override
12411386 File podRunnerFrameworksScript = MemoryFileSystem .test ().file ('podRunnerFrameworksScript' );
1387+
1388+ @override
1389+ Directory podRunnerTargetSupportFiles = MemoryFileSystem .test ().directory ('Pods-Runner' );
12421390}
12431391
12441392class FakeIOSMigrator extends ProjectMigrator {
0 commit comments