Class: PodBuilder::Podfile
- Inherits:
-
Object
- Object
- PodBuilder::Podfile
- Defined in:
- lib/pod_builder/podfile.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
- PRE_INSTALL_ACTIONS =
["Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_duplicate_framework_and_library_names) {}", "require 'pod_builder/podfile/pre_actions_swizzles'"].freeze
Class Method Summary collapse
- .from_podfile_items(items, analyzer, build_configuration, install_using_frameworks, build_catalyst, build_xcframeworks) ⇒ Object
- .install ⇒ Object
- .install_using_frameworks(analyzer) ⇒ Object
- .pod_definition_in(line, include_commented) ⇒ Object
- .resolve_pod_names(names, all_buildable_items) ⇒ Object
- .resolve_pod_names_from_podfile(names) ⇒ Object
- .restore_file_sanity_check ⇒ Object
- .restore_podfile_clean(pod_items) ⇒ Object
- .sanity_check ⇒ Object
- .strip_line(line) ⇒ Object
- .write_prebuilt(all_buildable_items, analyzer) ⇒ Object
- .write_prebuilt_react_native(all_buildable_items, analyzer) ⇒ Object
- .write_restorable(updated_pods, podfile_items, analyzer) ⇒ Object
Class Method Details
.from_podfile_items(items, analyzer, build_configuration, install_using_frameworks, build_catalyst, build_xcframeworks) ⇒ Object
8 9 10 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 81 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 |
# File 'lib/pod_builder/podfile.rb', line 8 def self.from_podfile_items(items, analyzer, build_configuration, install_using_frameworks, build_catalyst, build_xcframeworks) raise "\n\nno items\n".red unless items.count > 0 sources = analyzer.sources cwd = File.dirname(File.(__FILE__)) podfile = File.read("#{cwd}/templates/build_podfile.template") platform = analyzer.instance_variable_get("@result").targets.first.platform podfile.sub!("%%%use_frameworks%%%", install_using_frameworks ? "use_frameworks!" : "use_modular_headers!") podfile.sub!("%%%uses_frameworks%%%", install_using_frameworks ? "true" : "false") podfile.sub!("%%%build_xcframeworks%%%", build_xcframeworks ? "true" : "false") podfile.sub!("%%%build_catalyst%%%", build_catalyst ? "true" : "false") 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")) podfile.sub!("%%%build_configuration%%%", build_configuration.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].dup || {} # These settings need to be set as is to properly build frameworks build_settings["SWIFT_COMPILATION_MODE"] = "wholemodule" build_settings["ONLY_ACTIVE_ARCH"] = "NO" build_settings["DEBUG_INFORMATION_FORMAT"] = "dwarf-with-dsym" # https://thi.imhttps://thi.im/posts/swift-serialize-debugging-options/ build_settings["SWIFT_SERIALIZE_DEBUGGING_OPTIONS"] = "NO" build_settings["IPHONEOS_DEPLOYMENT_TARGET"] = platform.deployment_target.version # Fix compilation warnings on Xcode 12 # Ignore deprecation warnings build_settings["GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS"] = "NO" # Improve compile speed build_settings["COMPILER_INDEX_STORE_ENABLE"] = "NO" build_settings["SWIFT_INDEX_STORE_ENABLE"] = "NO" build_settings["MTL_ENABLE_INDEX_STORE"] = "NO" if Configuration.build_system == "Legacy" build_settings["BUILD_LIBRARY_FOR_DISTRIBUTION"] = "NO" elsif Configuration.library_evolution_support || item.build_xcframework build_settings["BUILD_LIBRARY_FOR_DISTRIBUTION"] = "YES" end build_settings["SWIFT_VERSION"] = item_build_settings["SWIFT_VERSION"] || item.swift_version || project_swift_version(analyzer) if build_settings["ENABLE_BITCODE"] == "YES" build_settings["BITCODE_GENERATION_MODE"] = "bitcode" end # Don't store .pcm info in binary, see https://forums.swift.org/t/swift-behavior-of-gmodules-and-dsyms/23211/3 build_settings["CLANG_ENABLE_MODULE_DEBUGGING"] = "NO" other_swift_flags_override = " $(inherited) -Xfrontend -no-clang-module-breadcrumbs" item_build_settings.each do |k, v| # Do not allow to override above settings which are mandatory for a correct compilation if build_settings[k].nil? build_settings[k] = v end end # All the below settings should be merged with global (Configuration.build_settings) or per pod build_settings (Configuration.build_settings_overrides) build_settings["OTHER_SWIFT_FLAGS"] = build_settings.fetch("OTHER_SWIFT_FLAGS", "") + other_swift_flags_override 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"] # this might no longer be needed after 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 |
.install ⇒ Object
264 265 266 267 268 269 270 271 |
# File 'lib/pod_builder/podfile.rb', line 264 def self.install puts "Running pod install".yellow Dir.chdir(PodBuilder::project_path) do bundler_prefix = Configuration.use_bundler ? "bundle exec " : "" system("#{bundler_prefix}pod install;") end end |
.install_using_frameworks(analyzer) ⇒ Object
400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/pod_builder/podfile.rb', line 400 def self.install_using_frameworks(analyzer) target_settings = analyzer.podfile.target_definition_list.map(&:uses_frameworks?).uniq if target_settings.count == 1 return target_settings.first elsif target_settings.count > 1 raise "\n\n'use_frameworks!' should be declared only once at Podfile root level (not nested in targets)\n".red else raise "\n\nFailed detecting use_frameworks!\n".red end return true end |
.pod_definition_in(line, include_commented) ⇒ Object
278 279 280 281 282 283 284 285 286 287 |
# File 'lib/pod_builder/podfile.rb', line 278 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 |
.resolve_pod_names(names, all_buildable_items) ⇒ Object
368 369 370 371 372 373 374 375 376 377 378 |
# File 'lib/pod_builder/podfile.rb', line 368 def self.resolve_pod_names(names, all_buildable_items) resolved_names = [] names.each do |name| if item = all_buildable_items.detect { |t| t.root_name.downcase == name.downcase } resolved_names.push(item.root_name) end end return resolved_names.uniq end |
.resolve_pod_names_from_podfile(names) ⇒ Object
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
# File 'lib/pod_builder/podfile.rb', line 380 def self.resolve_pod_names_from_podfile(names) resolved_names = [] # resolve potentially wrong pod name case podfile_path = PodBuilder::basepath("Podfile") content = File.read(podfile_path) current_section = "" content.each_line do |line| matches = line.gsub("\"", "'").match(/pod '(.*?)'/) if matches&.size == 2 if resolved_name = names.detect { |t| matches[1].split("/").first.downcase == t.downcase } resolved_names.push(matches[1].split("/").first) end end end resolved_names.uniq end |
.restore_file_sanity_check ⇒ Object
316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/pod_builder/podfile.rb', line 316 def self.restore_file_sanity_check unless Configuration.restore_enabled return nil end puts "Checking Podfile.restore".yellow podfile_restore_path = PodBuilder::basepath("Podfile.restore") unless File.exist?(podfile_restore_path) return end error = nil begin File.rename(PodBuilder::basepath("Podfile"), PodBuilder::basepath("Podfile.tmp2")) File.rename(podfile_restore_path, PodBuilder::basepath("Podfile")) Analyze.installer_at(PodBuilder::basepath, false) rescue Exception => e error = e.to_s ensure File.rename(PodBuilder::basepath("Podfile"), podfile_restore_path) File.rename(PodBuilder::basepath("Podfile.tmp2"), PodBuilder::basepath("Podfile")) end if !error.nil? FileUtils.rm(podfile_restore_path) end return error end |
.restore_podfile_clean(pod_items) ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/pod_builder/podfile.rb', line 289 def self.restore_podfile_clean(pod_items) unless Configuration.restore_enabled return end # remove pods that are no longer listed in pod_items podfile_restore_path = PodBuilder::basepath("Podfile.restore") unless File.exist?(podfile_restore_path) return end restore_content = File.read(podfile_restore_path) cleaned_lines = [] restore_content.each_line do |line| if pod_name = pod_definition_in(line, false) if pod_items.map(&:name).include?(pod_name) cleaned_lines.push(line) end else cleaned_lines.push(line) end end File.write(podfile_restore_path, cleaned_lines.join) end |
.sanity_check ⇒ Object
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/pod_builder/podfile.rb', line 349 def self.sanity_check podfile_path = PodBuilder::basepath("Podfile") unless File.exist?(podfile_path) return end File.read(podfile_path).each_line do |line| stripped_line = strip_line(line) unless !stripped_line.start_with?("#") next end if stripped_line.match(/(pod')(.*?)(')/) != nil starting_def_found = stripped_line.start_with?("def") && (line.match("\s*def\s") != nil) raise "\n\nUnsupported single line def/pod. `def` and `pod` shouldn't be on the same line, please modify the following line:\n#{line}\n".red if starting_def_found end end end |
.strip_line(line) ⇒ Object
273 274 275 276 |
# File 'lib/pod_builder/podfile.rb', line 273 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
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/pod_builder/podfile.rb', line 174 def self.write_prebuilt(all_buildable_items, analyzer) if Configuration.react_native_project return write_prebuilt_react_native(all_buildable_items, analyzer) end puts "Updating Application Podfile".yellow explicit_deps = analyzer.explicit_pods() explicit_deps.map! { |t| all_buildable_items.detect { |x| x.name == t.name } } explicit_deps.uniq! podbuilder_podfile_path = PodBuilder::basepath("Podfile") rel_path = Pathname.new(podbuilder_podfile_path).relative_path_from(Pathname.new(PodBuilder::project_path)).to_s podfile_content = File.read(podbuilder_podfile_path) exclude_lines = Podfile::PODBUILDER_LOCK_ACTION.map { |x| 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 exclude_lines.include?(stripped_line) next end if pod_name = pod_definition_in(line, true) if podfile_item = all_buildable_items.detect { |x| x.name == pod_name } marker = podfile_item.prebuilt_marker() non_explicit_dependencies = podfile_item.recursive_dependencies(all_buildable_items) - explicit_deps non_explicit_dependencies_root_names = non_explicit_dependencies.map(&:root_name).uniq.filter { |t| t != podfile_item.root_name } non_explicit_dependencies = non_explicit_dependencies_root_names.map { |x| if item = all_buildable_items.detect { |t| x == t.name } item else item = all_buildable_items.detect { |t| x == t.root_name } end }.compact non_explicit_dependencies.each do |dep| dep_item = all_buildable_items.detect { |x| x.name == dep.name } if File.exist?(dep_item.prebuilt_podspec_path) && !dep_item.is_prebuilt pod_name = dep_item.prebuilt_entry(false, false) prebuilt_lines.push("#{line.detect_indentation}#{pod_name}#{marker}\n") end explicit_deps.push(dep) end if File.exist?(podfile_item.prebuilt_podspec_path) && !podfile_item.is_prebuilt prebuilt_lines.push("#{line.detect_indentation}#{podfile_item.prebuilt_entry}\n") next end end end prebuilt_lines.push(line) end podfile_content = prebuilt_lines.join podfile_content = Podfile.update_path_entries(podfile_content, Podfile.method(:podfile_path_transform)) podfile_content = Podfile.update_project_entries(podfile_content, Podfile.method(:podfile_path_transform)) podfile_content = Podfile.update_require_entries(podfile_content, Podfile.method(:podfile_path_transform)) podfile_content = add_pre_install_actions(podfile_content) project_podfile_path = PodBuilder::project_path("Podfile") File.write(project_podfile_path, podfile_content) end |
.write_prebuilt_react_native(all_buildable_items, analyzer) ⇒ Object
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/pod_builder/podfile.rb', line 245 def self.write_prebuilt_react_native(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 podfile_content = ["# Autogenerated by PodBuilder (https://github.com/Subito-it/PodBuilder)\n", "# Any change to this file should be done on #{rel_path}\n", "\n"].join podfile_content += analyzer.podfile.pb_to_s(all_buildable_items) podfile_content = Podfile.update_path_entries(podfile_content, PodfileCP.method(:podfile_path_transform)) podfile_content = Podfile.update_project_entries(podfile_content, Podfile.method(:podfile_path_transform)) podfile_content = Podfile.update_require_entries(podfile_content, Podfile.method(:podfile_path_transform)) podfile_content = add_pre_install_actions(podfile_content) project_podfile_path = PodBuilder::project_path("Podfile") File.write(project_podfile_path, podfile_content) end |
.write_restorable(updated_pods, podfile_items, analyzer) ⇒ Object
112 113 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 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 171 172 |
# File 'lib/pod_builder/podfile.rb', line 112 def self.write_restorable(updated_pods, podfile_items, analyzer) unless Configuration.restore_enabled && (podfile_items.count + updated_pods.count) > 0 return end 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, include_prebuilt = true) 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.instance_variable_get("@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.instance_variable_get("@result").targets.first.platform podfile_content += ["platform :#{platform.name}, '#{platform.deployment_target.version}'", ""] analyzer.instance_variable_get("@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") if project_path = target.user_project_path podfile_content.push("\tproject '#{project_path}'") end specifications.each do |spec| item = podfile_items.detect { |x| x.name == spec.name } if podfile_items.map(&:name).include?(spec.name) podfile_content.push("\t#{item.entry}") end end podfile_content.push("end\n") end File.write(podfile_restore_path, podfile_content.join("\n")) end |