Class: PodBuilder::Podfile
- Inherits:
-
Object
- Object
- PodBuilder::Podfile
- Defined in:
- lib/pod_builder/podfile.rb,
lib/pod_builder/podfile/post_actions.rb
Constant Summary collapse
- PODBUILDER_LOCK_ACTION =
["raise \"\\nšØ Do not launch 'pod install' manually, use `pod_builder` instead!\\n\" if !File.exist?('pod_builder.lock')"].freeze
- POST_INSTALL_ACTIONS =
["require 'pod_builder/podfile/post_actions'", "PodBuilder::Podfile::remove_target_support_duplicate_entries", "PodBuilder::Podfile::check_target_support_resource_collisions"].freeze
Class Method Summary collapse
- .add_install_block(podfile_path) ⇒ Object
- .check_target_support_resource_collisions ⇒ Object
- .deintegrate_install ⇒ Object
- .from_podfile_items(items, analyzer) ⇒ Object
- .pod_definition_in(line, include_commented) ⇒ Object
- .remove_target_support_duplicate_entries ⇒ Object
- .strip_line(line) ⇒ Object
- .write_prebuilt(all_buildable_items, analyzer) ⇒ Object
- .write_restorable(updated_pods, podfile_items, analyzer) ⇒ Object
Class Method Details
.add_install_block(podfile_path) ⇒ Object
187 188 189 |
# File 'lib/pod_builder/podfile.rb', line 187 def self.add_install_block(podfile_path) add(PODBUILDER_LOCK_ACTION, "pre_install", podfile_path) end |
.check_target_support_resource_collisions ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/pod_builder/podfile/post_actions.rb', line 16 def self.check_target_support_resource_collisions puts "[PodBuilder] Checking target support resource collisions".yellow targets = find_xcodeproj_targets targets.map(&:name).each do |target| check_for_colliding_resources("Pods/Target Support Files/Pods-#{target}/Pods-#{target}-resources.sh", target, targets) end end |
.deintegrate_install ⇒ Object
172 173 174 175 176 177 178 179 180 |
# File 'lib/pod_builder/podfile.rb', line 172 def self.deintegrate_install puts "Running pod install".yellow current_dir = Dir.pwd Dir.chdir(PodBuilder::project_path) system("pod install;") Dir.chdir(current_dir) end |
.from_podfile_items(items, analyzer) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/pod_builder/podfile.rb', line 11 def self.from_podfile_items(items, analyzer) raise "no items" unless items.count > 0 sources = analyzer.sources cwd = File.dirname(File.(__FILE__)) podfile = File.read("#{cwd}/templates/build_podfile.template") platform = analyzer.result.targets.first.platform podfile.sub!("%%%platform_name%%%", platform.name.to_s) podfile.sub!("%%%deployment_version%%%", platform.deployment_target.version) podfile.sub!("%%%sources%%%", sources.map { |x| "source '#{x.url}'" }.join("\n")) build_configurations = items.map(&:build_configuration).uniq raise "Found different build configurations in #{items}" if build_configurations.count != 1 podfile.sub!("%%%build_configuration%%%", build_configurations.first.capitalize) podfile_build_settings = "" pod_dependencies = {} items.each do |item| build_settings = Configuration.build_settings.dup item_build_settings = Configuration.build_settings_overrides[item.name] || {} # These settings need to be set as is to properly build frameworks build_settings['SWIFT_COMPILATION_MODE'] = 'singlefile' build_settings['CLANG_ENABLE_MODULE_DEBUGGING'] = 'NO' build_settings['ONLY_ACTIVE_ARCH'] = 'NO' build_settings['SWIFT_VERSION'] = item_build_settings["SWIFT_VERSION"] || project_swift_version(analyzer) if item.is_static # https://forums.developer.apple.com/thread/17921 build_settings['CLANG_ENABLE_MODULE_DEBUGGING'] = "NO" end item_build_settings.each do |k, v| build_settings[k] = v end podfile_build_settings += "set_build_settings(\"#{item.root_name}\", #{build_settings.to_s}, installer)\n " dependency_names = item.dependency_names.map { |x| if x.split("/").first == item.root_name next nil # remove dependency to parent spec end if overridded_module_name = Configuration.spec_overrides.fetch(x, {})["module_name"] next overridded_module_name end }.compact if dependency_names.count > 0 pod_dependencies[item.root_name] = dependency_names end end podfile.sub!("%%%build_settings%%%", podfile_build_settings) podfile.sub!("%%%build_system%%%", Configuration.build_system) podfile.sub!("%%%pods%%%", "\"#{items.map(&:name).join('", "')}\"") podfile.sub!("%%%pods_dependencies%%%", pod_dependencies.to_s) podfile.sub!("%%%targets%%%", items.map(&:entry).join("\n ")) return podfile end |
.pod_definition_in(line, include_commented) ⇒ Object
191 192 193 194 195 196 197 198 199 200 |
# File 'lib/pod_builder/podfile.rb', line 191 def self.pod_definition_in(line, include_commented) stripped_line = strip_line(line) matches = stripped_line.match(/(^pod')(.*?)(')/) if matches&.size == 4 && (include_commented || !stripped_line.start_with?("#")) return matches[2] else return nil end end |
.remove_target_support_duplicate_entries ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/pod_builder/podfile/post_actions.rb', line 7 def self.remove_target_support_duplicate_entries puts "[PodBuilder] Removing target support duplicated entries".yellow # Frameworks and resources find_xcodeproj_targets.map(&:name).each do |target| remove_duplicate_entries("Pods/Target Support Files/Pods-#{target}/Pods-#{target}-frameworks.sh") remove_duplicate_entries("Pods/Target Support Files/Pods-#{target}/Pods-#{target}-resources.sh") end end |
.strip_line(line) ⇒ Object
182 183 184 185 |
# File 'lib/pod_builder/podfile.rb', line 182 def self.strip_line(line) stripped_line = line.strip return stripped_line.gsub("\"", "'").gsub(" ", "").gsub("\t", "").gsub("\n", "") end |
.write_prebuilt(all_buildable_items, analyzer) ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/pod_builder/podfile.rb', line 134 def self.write_prebuilt(all_buildable_items, analyzer) puts "Updating Application Podfile".yellow podbuilder_podfile_path = PodBuilder::basepath("Podfile") rel_path = Pathname.new(podbuilder_podfile_path).relative_path_from(Pathname.new(PodBuilder::project_path)).to_s frameworks_base_path = PodBuilder::basepath("Rome") podfile_content = File.read(podbuilder_podfile_path) exclude_lines = Podfile::PODBUILDER_LOCK_ACTION.map { |x| Podfile.strip_line(x) } prebuilt_lines = ["# Autogenerated by PodBuilder (https://github.com/Subito-it/PodBuilder)\n", "# Any change to this file should be done on #{rel_path}\n", "\n"] podfile_content.each_line do |line| stripped_line = strip_line(line) if pod_name = pod_definition_in(line, true) if podfile_item = all_buildable_items.detect { |x| x.name == pod_name } if Podspec.include?(podfile_item.name) line = "#{line.detect_indentation}#{podfile_item.prebuilt_entry}\n" end end end if !exclude_lines.include?(stripped_line) prebuilt_lines.push(line) end end project_podfile_path = PodBuilder::project_path("Podfile") File.write(project_podfile_path, prebuilt_lines.join) Podfile.update_path_entires(project_podfile_path, false) Podfile.update_project_entries(project_podfile_path, false) add_pre_install_actions(project_podfile_path) add_post_install_checks(project_podfile_path) end |
.write_restorable(updated_pods, podfile_items, analyzer) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/pod_builder/podfile.rb', line 82 def self.write_restorable(updated_pods, podfile_items, analyzer) puts "Writing Restore Podfile".yellow podfile_items = podfile_items.dup podfile_restore_path = PodBuilder::basepath("Podfile.restore") podfile_path = PodBuilder::basepath("Podfile") if File.exist?(podfile_restore_path) restore_podfile_items = podfile_items_at(podfile_restore_path) podfile_items.map! { |podfile_item| if updated_pod = updated_pods.detect { |x| x.name == podfile_item.name } then updated_pod elsif updated_pods.any? { |x| podfile_item.root_name == x.root_name } == false && # podfile_item shouldn't be among those being updated (including root specification) restored_pod = restore_podfile_items.detect { |x| x.name == podfile_item.name } restored_pod else podfile_item end } end result_targets = analyzer.result.targets.map(&:name) podfile_content = ["# Autogenerated by PodBuilder (https://github.com/Subito-it/PodBuilder)", "# Please don't modify this file", "\n"] podfile_content += analyzer.podfile.sources.map { |x| "source '#{x}'" } podfile_content += ["", "use_frameworks!", ""] # multiple platforms not (yet) supported # https://github.com/CocoaPods/Rome/issues/37 platform = analyzer.result.targets.first.platform podfile_content += ["platform :#{platform.name}, '#{platform.deployment_target.version}'", ""] analyzer.result.specs_by_target.each do |target, specifications| target_name = target.name.to_s unless result_targets.select { |x| x.end_with?(target_name) }.count > 0 next end podfile_content.push("target '#{target_name}' do") specifications.each do |spec| item = podfile_items.detect { |x| x.name == spec.name } podfile_content.push("\t#{item.entry}") end podfile_content.push("end\n") end File.write(podfile_restore_path, podfile_content.join("\n")) end |