Module: SecureKeys::Swift::Xcodeproj
- Defined in:
- lib/core/utils/swift/xcodeproj.rb
Class Method Summary collapse
-
.add_framework_search_path(xcodeproj_target:, configurations: %w[Debug Release])) ⇒ Object
Add the SecureKeys XCFramework to the Xcodeproj target build settings.
-
.add_xcframework_to_build_phases(xcodeproj:, xcodeproj_target:) ⇒ Object
Add the SecureKeys XCFramework to the Xcodeproj target build phases.
-
.remove_xcframework(xcodeproj:, xcodeproj_target:, xcframework_path:) ⇒ Object
Remove all references to SecureKeys.xcframework from the Xcodeproj.
-
.remove_xcframework_file_references(xcodeproj:, xcframework_filename:) ⇒ Object
Remove the XCFramework from the file references.
-
.remove_xcframework_from_build_phase(xcodeproj_target:, xcframework_filename:) ⇒ Object
Remove the XCFramework from the “Link Binary With Libraries” build phase.
-
.remove_xcframework_from_groups(xcodeproj:, xcframework_filename:) ⇒ Object
Remove the XCFramework from groups (e.g., Frameworks Group).
-
.remove_xcframework_from_search_paths(xcodeproj_target:, xcframework_filename:) ⇒ Object
Remove the XCFramework from FRAMEWORK_SEARCH_PATHS.
-
.xcframework_relative_path ⇒ Pathname
Get the XCFramework relative path.
-
.xcodeproj ⇒ Xcodeproj
Get the Xcodeproj.
-
.xcodeproj_has_secure_keys_xcframework?(xcodeproj:) ⇒ Bool
Check if the Xcode project has the secure keys XCFramework.
-
.xcodeproj_target_by_target_name(xcodeproj:, target_name:) ⇒ Xcodeproj
Get the Xcodeproj target by target name.
Class Method Details
.add_framework_search_path(xcodeproj_target:, configurations: %w[Debug Release])) ⇒ Object
Add the SecureKeys XCFramework to the Xcodeproj target build settings
14 15 16 17 18 19 |
# File 'lib/core/utils/swift/xcodeproj.rb', line 14 def add_framework_search_path(xcodeproj_target:, configurations: %w[Debug Release]) configurations.each do |config| paths = ['$(inherited)', "$(SRCROOT)/#{xcframework_relative_path}"] xcodeproj_target.build_settings(config)['FRAMEWORK_SEARCH_PATHS'] = paths end end |
.add_xcframework_to_build_phases(xcodeproj:, xcodeproj_target:) ⇒ Object
Add the SecureKeys XCFramework to the Xcodeproj target build phases
24 25 26 27 28 |
# File 'lib/core/utils/swift/xcodeproj.rb', line 24 def add_xcframework_to_build_phases(xcodeproj:, xcodeproj_target:) Core::Console::Logger.crash!(message: "The xcodeproj #{xcodeproj} already have the #{XCFRAMEWORK_DIRECTORY}") if xcodeproj_has_secure_keys_xcframework?(xcodeproj:) xcframework_reference = xcodeproj.frameworks_group.new_file(xcframework_relative_path) xcodeproj_target.frameworks_build_phase.add_file_reference(xcframework_reference) end |
.remove_xcframework(xcodeproj:, xcodeproj_target:, xcframework_path:) ⇒ Object
Remove all references to SecureKeys.xcframework from the Xcodeproj
52 53 54 55 56 57 58 59 |
# File 'lib/core/utils/swift/xcodeproj.rb', line 52 def remove_xcframework(xcodeproj:, xcodeproj_target:, xcframework_path:) xcframework_filename = File.basename(xcframework_path) remove_xcframework_from_build_phase(xcodeproj_target:, xcframework_filename:) remove_xcframework_file_references(xcodeproj:, xcframework_filename:) remove_xcframework_from_groups(xcodeproj:, xcframework_filename:) remove_xcframework_from_search_paths(xcodeproj_target:, xcframework_filename:) end |
.remove_xcframework_file_references(xcodeproj:, xcframework_filename:) ⇒ Object
Remove the XCFramework from the file references
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/core/utils/swift/xcodeproj.rb', line 98 def remove_xcframework_file_references(xcodeproj:, xcframework_filename:) file_references = xcodeproj.files.select { |file| file.path&.include?(xcframework_filename) } file_references.each do |file_ref| file_ref.remove_from_project Core::Console::Logger.verbose(message: "Removed #{xcframework_filename} file reference") end # Ensure no orphaned references remain xcodeproj.objects.select { |obj| obj.isa == 'PBXFileReference' && obj.path&.include?(xcframework_filename) }.each(&:remove_from_project) xcodeproj.objects.select { |obj| obj.isa == 'PBXBuildFile' && obj.file_ref&.path&.include?(xcframework_filename) }.each(&:remove_from_project) end |
.remove_xcframework_from_build_phase(xcodeproj_target:, xcframework_filename:) ⇒ Object
Remove the XCFramework from the “Link Binary With Libraries” build phase
84 85 86 87 88 89 90 91 92 93 |
# File 'lib/core/utils/swift/xcodeproj.rb', line 84 def remove_xcframework_from_build_phase(xcodeproj_target:, xcframework_filename:) build_phase_files = xcodeproj_target.frameworks_build_phase.files.select do |file| file.file_ref&.path&.include?(xcframework_filename) end build_phase_files.each do |file| file.remove_from_project Core::Console::Logger.verbose(message: "Removed #{xcframework_filename} from Link Binary With Libraries in target #{xcodeproj_target.name}") end end |
.remove_xcframework_from_groups(xcodeproj:, xcframework_filename:) ⇒ Object
Remove the XCFramework from groups (e.g., Frameworks Group)
113 114 115 116 117 118 119 120 121 |
# File 'lib/core/utils/swift/xcodeproj.rb', line 113 def remove_xcframework_from_groups(xcodeproj:, xcframework_filename:) frameworks_group = xcodeproj.frameworks_group group_references = frameworks_group.files.select { |file| file.path&.include?(xcframework_filename) } group_references.each do |file_ref| frameworks_group.remove_reference(file_ref) Core::Console::Logger.verbose(message: "Removed #{xcframework_filename} from Frameworks group") end end |
.remove_xcframework_from_search_paths(xcodeproj_target:, xcframework_filename:) ⇒ Object
Remove the XCFramework from FRAMEWORK_SEARCH_PATHS
126 127 128 129 130 131 132 |
# File 'lib/core/utils/swift/xcodeproj.rb', line 126 def remove_xcframework_from_search_paths(xcodeproj_target:, xcframework_filename:) xcodeproj_target.build_configurations.each do |config| framework_search_paths = config.build_settings['FRAMEWORK_SEARCH_PATHS'] || [] new_search_paths = framework_search_paths.reject { |path| path.include?(xcframework_filename) } config.build_settings['FRAMEWORK_SEARCH_PATHS'] = new_search_paths unless framework_search_paths == new_search_paths end end |
.xcframework_relative_path ⇒ Pathname
Get the XCFramework relative path
63 64 65 66 |
# File 'lib/core/utils/swift/xcodeproj.rb', line 63 def xcframework_relative_path Pathname.new(Globals.secure_keys_xcframework_path) .relative_path_from(Pathname.new(Globals.xcodeproj_path).dirname) end |
.xcodeproj ⇒ Xcodeproj
Get the Xcodeproj
44 45 46 |
# File 'lib/core/utils/swift/xcodeproj.rb', line 44 def xcodeproj ::Xcodeproj::Project.open(Globals.xcodeproj_path) end |
.xcodeproj_has_secure_keys_xcframework?(xcodeproj:) ⇒ Bool
Check if the Xcode project has the secure keys XCFramework
71 72 73 74 75 76 77 78 79 |
# File 'lib/core/utils/swift/xcodeproj.rb', line 71 def xcodeproj_has_secure_keys_xcframework?(xcodeproj:) xcodeproj.targets.any? do |target| target.frameworks_build_phase.files.any? do |file| return false if file.file_ref.nil? file.file_ref.path.include?(Globals.secure_keys_xcframework_path) end end end |
.xcodeproj_target_by_target_name(xcodeproj:, target_name:) ⇒ Xcodeproj
Get the Xcodeproj target by target name
35 36 37 38 39 40 |
# File 'lib/core/utils/swift/xcodeproj.rb', line 35 def xcodeproj_target_by_target_name(xcodeproj:, target_name:) xcodeproj_target = xcodeproj.targets.find { |target| target.name.eql?(target_name) } Core::Console::Logger.crash!(message: "The target #{target_name} was not found") if xcodeproj_target.nil? xcodeproj_target end |