Class: Pod::Deintegrator
- Inherits:
-
Object
- Object
- Pod::Deintegrator
- Includes:
- Config::Mixin
- Defined in:
- lib/cocoapods/deintegrator.rb
Constant Summary collapse
- FRAMEWORK_NAMES =
/^(libPods.*\.a)|(Pods.*\.framework)$/i
- XCCONFIG_NAMES =
/^Pods.*\.xcconfig$/i
Instance Method Summary collapse
- #deintegrate_configuration_file_references(target) ⇒ Object
- #deintegrate_pods_libraries(target) ⇒ Object
- #deintegrate_project(project) ⇒ Object
- #deintegrate_shell_script_phase(target, phase_name) ⇒ Object
- #deintegrate_target(target) ⇒ Object
- #deintegrate_user_shell_script_phases(target) ⇒ Object
- #delete_empty_group(project, group_name) ⇒ Object
- #delete_pods_file_references(project) ⇒ Object
- #remove_sandbox ⇒ Object
Instance Method Details
#deintegrate_configuration_file_references(target) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/cocoapods/deintegrator.rb', line 99 def deintegrate_configuration_file_references(target) config_files = target.build_configurations.map do |config| config_file = config.base_configuration_reference config_file if config_file && config_file.name =~ XCCONFIG_NAMES end.compact unless config_files.empty? UI.section('Deleting configuration file references') do config_files.each do |file_reference| UI.puts("- #{file_reference.name}") file_reference.remove_from_project end end end end |
#deintegrate_pods_libraries(target) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/cocoapods/deintegrator.rb', line 42 def deintegrate_pods_libraries(target) frameworks_build_phase = target.frameworks_build_phase pods_build_files = frameworks_build_phase.files.select do |build_file| build_file.display_name =~ FRAMEWORK_NAMES end unless pods_build_files.empty? UI.section('Removing Pod libraries from build phase:') do pods_build_files.each do |build_file| UI.puts("- #{build_file.display_name}") frameworks_build_phase.remove_build_file(build_file) end end end end |
#deintegrate_project(project) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/cocoapods/deintegrator.rb', line 8 def deintegrate_project(project) UI.section("Deintegrating #{UI.path project.path}") do project.native_targets.each do |target| deintegrate_target(target) end end delete_pods_file_references(project) remove_sandbox UI.puts UI.puts('Project has been deintegrated. No traces of CocoaPods left in project.'.green) UI.puts('Note: The workspace referencing the Pods project still remains.') end |
#deintegrate_shell_script_phase(target, phase_name) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/cocoapods/deintegrator.rb', line 74 def deintegrate_shell_script_phase(target, phase_name) phases = target.shell_script_build_phases.select do |phase| phase.name && phase.name =~ /#{Regexp.escape(phase_name)}\z$/ end unless phases.empty? phases.each do |phase| target.build_phases.delete(phase) end UI.puts("Deleted #{phases.count} '#{phase_name}' build phases.") end end |
#deintegrate_target(target) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cocoapods/deintegrator.rb', line 23 def deintegrate_target(target) UI.section("Deintegrating target `#{target.name}`") do deintegrate_shell_script_phase(target, 'Copy Pods Resources') deintegrate_shell_script_phase(target, 'Check Pods Manifest.lock') deintegrate_shell_script_phase(target, 'Embed Pods Frameworks') deintegrate_user_shell_script_phases(target) deintegrate_pods_libraries(target) deintegrate_configuration_file_references(target) end end |
#deintegrate_user_shell_script_phases(target) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/cocoapods/deintegrator.rb', line 59 def deintegrate_user_shell_script_phases(target) user_script_phases = target.shell_script_build_phases.select do |phase| next unless phase.name phase.name.start_with?('[CP-User] ') end unless user_script_phases.empty? user_script_phases.each do |phase| target.build_phases.delete(phase) end UI.puts("Deleted #{user_script_phases.count} user build phases.") end end |
#delete_empty_group(project, group_name) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/cocoapods/deintegrator.rb', line 88 def delete_empty_group(project, group_name) groups = project.main_group.recursive_children_groups.select do |group| group.name == group_name && group.children.empty? end unless groups.empty? groups.each(&:remove_from_project) UI.puts "Deleted #{groups.count} empty `#{group_name}` groups from project." end end |
#delete_pods_file_references(project) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/cocoapods/deintegrator.rb', line 114 def delete_pods_file_references(project) # The following implementation goes for files and empty groups so it # should catch cases where a user has changed the structure manually. groups = project.main_group.recursive_children_groups groups << project.main_group pod_files = groups.flat_map do |group| group.files.select do |obj| obj.name =~ XCCONFIG_NAMES || obj.path =~ /^(libPods.*\.a)|(Pods_.*\.framework)$/i end end unless pod_files.empty? UI.section('Deleting Pod file references from project') do pod_files.each do |file_reference| UI.puts("- #{file_reference.name || file_reference.path}") file_reference.remove_from_project end end end # Delete empty `Pods` group if exists delete_empty_group(project, 'Pods') delete_empty_group(project, 'Frameworks') end |
#remove_sandbox ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/cocoapods/deintegrator.rb', line 34 def remove_sandbox pods_directory = config.sandbox.root if pods_directory.exist? UI.puts("Removing #{UI.path pods_directory} directory.") pods_directory.rmtree end end |