pod-builder 1.9.4 → 2.0.0.beta.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +9 -0
  3. data/README.md +50 -13
  4. data/exe/pod_builder +39 -28
  5. data/lib/pod_builder/analyze.rb +32 -7
  6. data/lib/pod_builder/analyzer.rb +16 -0
  7. data/lib/pod_builder/command/build.rb +44 -174
  8. data/lib/pod_builder/command/build_all.rb +2 -2
  9. data/lib/pod_builder/command/clean.rb +34 -55
  10. data/lib/pod_builder/command/clear_lldbinit.rb +7 -3
  11. data/lib/pod_builder/command/deintegrate.rb +29 -7
  12. data/lib/pod_builder/command/generate_lfs.rb +3 -3
  13. data/lib/pod_builder/command/generate_podspec.rb +3 -2
  14. data/lib/pod_builder/command/info.rb +1 -1
  15. data/lib/pod_builder/command/init.rb +37 -14
  16. data/lib/pod_builder/command/install_sources.rb +21 -14
  17. data/lib/pod_builder/command/none.rb +2 -2
  18. data/lib/pod_builder/command/restore_all.rb +4 -4
  19. data/lib/pod_builder/command/switch.rb +137 -95
  20. data/lib/pod_builder/command/sync_podfile.rb +5 -3
  21. data/lib/pod_builder/command/update.rb +5 -6
  22. data/lib/pod_builder/command/update_lldbinit.rb +11 -9
  23. data/lib/pod_builder/configuration.rb +88 -13
  24. data/lib/pod_builder/core.rb +95 -14
  25. data/lib/pod_builder/info.rb +32 -98
  26. data/lib/pod_builder/install.rb +255 -195
  27. data/lib/pod_builder/licenses.rb +4 -4
  28. data/lib/pod_builder/podfile.rb +300 -73
  29. data/lib/pod_builder/podfile/post_actions.rb +9 -15
  30. data/lib/pod_builder/podfile_cp.rb +93 -0
  31. data/lib/pod_builder/podfile_item.rb +181 -82
  32. data/lib/pod_builder/podspec.rb +144 -135
  33. data/lib/pod_builder/rome/post_install.rb +240 -0
  34. data/lib/pod_builder/rome/pre_install.rb +6 -0
  35. data/lib/pod_builder/templates/build_podfile.template +3 -3
  36. data/lib/pod_builder/version.rb +1 -1
  37. data/pod-builder.gemspec +5 -5
  38. metadata +23 -76
  39. data/Example/Frameworks/PodBuilder.json +0 -32
  40. data/Example/PodBuilderExample.xcodeproj/project.pbxproj +0 -416
  41. data/Example/PodBuilderExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  42. data/Example/PodBuilderExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  43. data/Example/PodBuilderExample.xcodeproj/project.xcworkspace/xcuserdata/tomas.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  44. data/Example/PodBuilderExample.xcodeproj/xcuserdata/tomas.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  45. data/Example/PodBuilderExample.xcworkspace/contents.xcworkspacedata +0 -10
  46. data/Example/PodBuilderExample/AppDelegate.swift +0 -47
  47. data/Example/PodBuilderExample/Assets.xcassets/AppIcon.appiconset/Contents.json +0 -98
  48. data/Example/PodBuilderExample/Assets.xcassets/Contents.json +0 -6
  49. data/Example/PodBuilderExample/Base.lproj/LaunchScreen.storyboard +0 -25
  50. data/Example/PodBuilderExample/Base.lproj/Main.storyboard +0 -24
  51. data/Example/PodBuilderExample/Info.plist +0 -45
  52. data/Example/PodBuilderExample/ViewController.swift +0 -25
  53. data/Example/Podfile +0 -8
  54. data/Example/Podfile.lock +0 -16
  55. data/Example/Pods/Alamofire/LICENSE +0 -19
  56. data/Example/Pods/Alamofire/README.md +0 -242
  57. data/Example/Pods/Alamofire/Source/AFError.swift +0 -460
  58. data/Example/Pods/Alamofire/Source/Alamofire.swift +0 -465
  59. data/Example/Pods/Alamofire/Source/DispatchQueue+Alamofire.swift +0 -37
  60. data/Example/Pods/Alamofire/Source/MultipartFormData.swift +0 -580
  61. data/Example/Pods/Alamofire/Source/NetworkReachabilityManager.swift +0 -233
  62. data/Example/Pods/Alamofire/Source/Notifications.swift +0 -55
  63. data/Example/Pods/Alamofire/Source/ParameterEncoding.swift +0 -483
  64. data/Example/Pods/Alamofire/Source/Request.swift +0 -654
  65. data/Example/Pods/Alamofire/Source/Response.swift +0 -567
  66. data/Example/Pods/Alamofire/Source/ResponseSerialization.swift +0 -715
  67. data/Example/Pods/Alamofire/Source/Result.swift +0 -300
  68. data/Example/Pods/Alamofire/Source/ServerTrustPolicy.swift +0 -307
  69. data/Example/Pods/Alamofire/Source/SessionDelegate.swift +0 -725
  70. data/Example/Pods/Alamofire/Source/SessionManager.swift +0 -896
  71. data/Example/Pods/Alamofire/Source/TaskDelegate.swift +0 -466
  72. data/Example/Pods/Alamofire/Source/Timeline.swift +0 -136
  73. data/Example/Pods/Alamofire/Source/Validation.swift +0 -315
  74. data/Example/Pods/Manifest.lock +0 -16
  75. data/Example/Pods/Pods.xcodeproj/project.pbxproj +0 -673
  76. data/Example/Pods/Pods.xcodeproj/xcuserdata/tomas.xcuserdatad/xcschemes/Alamofire.xcscheme +0 -60
  77. data/Example/Pods/Pods.xcodeproj/xcuserdata/tomas.xcuserdatad/xcschemes/Pods-PodBuilderExample.xcscheme +0 -60
  78. data/Example/Pods/Pods.xcodeproj/xcuserdata/tomas.xcuserdatad/xcschemes/xcschememanagement.plist +0 -21
  79. data/Example/Pods/Target Support Files/Alamofire/Alamofire-dummy.m +0 -5
  80. data/Example/Pods/Target Support Files/Alamofire/Alamofire-prefix.pch +0 -12
  81. data/Example/Pods/Target Support Files/Alamofire/Alamofire-umbrella.h +0 -16
  82. data/Example/Pods/Target Support Files/Alamofire/Alamofire.modulemap +0 -6
  83. data/Example/Pods/Target Support Files/Alamofire/Alamofire.xcconfig +0 -9
  84. data/Example/Pods/Target Support Files/Alamofire/Info.plist +0 -26
  85. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Info.plist +0 -26
  86. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample-acknowledgements.markdown +0 -26
  87. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample-acknowledgements.plist +0 -58
  88. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample-dummy.m +0 -5
  89. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample-frameworks.sh +0 -153
  90. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample-resources.sh +0 -118
  91. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample-umbrella.h +0 -16
  92. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample.debug.xcconfig +0 -11
  93. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample.modulemap +0 -6
  94. data/Example/Pods/Target Support Files/Pods-PodBuilderExample/Pods-PodBuilderExample.release.xcconfig +0 -11
  95. data/lib/pod_builder/cocoapods/specification.rb +0 -27
@@ -12,19 +12,19 @@
12
12
 
13
13
  if current_licenses.count > 0
14
14
  licenses_header = current_licenses.shift
15
- raise "Unexpected license found in header" if licenses_header.has_key?("License")
15
+ raise "\n\nUnexpected license found in header".red if licenses_header.has_key?("License")
16
16
  end
17
17
  if current_licenses.count > 0
18
18
  license_footer = current_licenses.pop
19
- raise "Unexpected license found in footer" if license_footer.has_key?("License")
19
+ raise "\n\nUnexpected license found in footer".red if license_footer.has_key?("License")
20
20
  end
21
21
  end
22
22
 
23
23
  if licenses.count > 0
24
24
  licenses_header = licenses.shift
25
- raise "Unexpected license found in header" if licenses_header.has_key?("License")
25
+ raise "\n\nUnexpected license found in header".red if licenses_header.has_key?("License")
26
26
  license_footer = licenses.pop
27
- raise "Unexpected license found in footer" if license_footer.has_key?("License")
27
+ raise "\n\nUnexpected license found in footer".red if license_footer.has_key?("License")
28
28
 
29
29
  lincenses_titles = licenses.map { |x| x["Title"] }
30
30
  current_licenses.select! { |x| !lincenses_titles.include?(x["Title"]) }
@@ -1,13 +1,14 @@
1
+ require 'json'
1
2
  module PodBuilder
2
3
  class Podfile
3
4
  PODBUILDER_LOCK_ACTION = ["raise \"\\n🚨 Do not launch 'pod install' manually, use `pod_builder` instead!\\n\" if !File.exist?('pod_builder.lock')"].freeze
4
- POST_INSTALL_ACTIONS = ["require 'pod_builder/podfile/post_actions'", "PodBuilder::Podfile::remove_target_support_duplicate_entries", "PodBuilder::Podfile::check_target_support_resource_collisions"].freeze
5
+ POST_INSTALL_ACTIONS = ["require 'pod_builder/podfile/post_actions'", "PodBuilder::Podfile::pod_builder_post_process"].freeze
5
6
 
6
7
  PRE_INSTALL_ACTIONS = ["Pod::Installer::Xcode::TargetValidator.send(:define_method, :verify_no_duplicate_framework_and_library_names) {}"].freeze
7
8
  private_constant :PRE_INSTALL_ACTIONS
8
9
 
9
- def self.from_podfile_items(items, analyzer)
10
- raise "no items" unless items.count > 0
10
+ def self.from_podfile_items(items, analyzer, build_configuration)
11
+ raise "\n\nno items".red unless items.count > 0
11
12
 
12
13
  sources = analyzer.sources
13
14
 
@@ -15,14 +16,17 @@ module PodBuilder
15
16
  podfile = File.read("#{cwd}/templates/build_podfile.template")
16
17
 
17
18
  platform = analyzer.instance_variable_get("@result").targets.first.platform
19
+
20
+ install_using_frameworks = install_using_frameworks(analyzer)
21
+
22
+ podfile.sub!("%%%use_frameworks%%%", install_using_frameworks ? "use_frameworks!" : "")
23
+
18
24
  podfile.sub!("%%%platform_name%%%", platform.name.to_s)
19
25
  podfile.sub!("%%%deployment_version%%%", platform.deployment_target.version)
20
26
 
21
27
  podfile.sub!("%%%sources%%%", sources.map { |x| "source '#{x.url}'" }.join("\n"))
22
28
 
23
- build_configurations = items.map(&:build_configuration).uniq
24
- raise "Found different build configurations in #{items}" if build_configurations.count != 1
25
- podfile.sub!("%%%build_configuration%%%", build_configurations.first.capitalize)
29
+ podfile.sub!("%%%build_configuration%%%", build_configuration.capitalize)
26
30
 
27
31
  podfile_build_settings = ""
28
32
 
@@ -35,12 +39,25 @@ module PodBuilder
35
39
 
36
40
  # These settings need to be set as is to properly build frameworks
37
41
  build_settings['SWIFT_COMPILATION_MODE'] = 'wholemodule'
38
- build_settings['CLANG_ENABLE_MODULE_DEBUGGING'] = 'NO'
39
42
  build_settings['ONLY_ACTIVE_ARCH'] = 'NO'
40
43
  build_settings['DEBUG_INFORMATION_FORMAT'] = "dwarf-with-dsym"
41
44
 
45
+ build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = platform.deployment_target.version # Fix compilation warnings on Xcode 12
46
+
47
+ # Don't store .pcm info in binary, see https://forums.swift.org/t/swift-behavior-of-gmodules-and-dsyms/23211/3
48
+ build_settings['CLANG_ENABLE_MODULE_DEBUGGING'] = 'NO'
49
+ build_settings['OTHER_SWIFT_FLAGS'] = "-Xfrontend -no-clang-module-breadcrumbs"
50
+
51
+ # Improve compile speed
52
+ build_settings['COMPILER_INDEX_STORE_ENABLE'] = 'NO'
53
+ build_settings['SWIFT_INDEX_STORE_ENABLE'] = 'NO'
54
+ build_settings['MTL_ENABLE_INDEX_STORE'] = 'NO'
55
+
42
56
  if Configuration.build_system == "Legacy"
43
57
  build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = "NO"
58
+ raise "\n\nCan't enable library evolution support with legacy build system!".red if Configuration.library_evolution_support
59
+ elsif Configuration.library_evolution_support
60
+ build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = "YES"
44
61
  end
45
62
 
46
63
  build_settings['SWIFT_VERSION'] = item_build_settings["SWIFT_VERSION"] || item.swift_version || project_swift_version(analyzer)
@@ -55,7 +72,7 @@ module PodBuilder
55
72
  if x.split("/").first == item.root_name
56
73
  next nil # remove dependency to parent spec
57
74
  end
58
- if overridded_module_name = Configuration.spec_overrides.fetch(x, {})["module_name"]
75
+ if overridded_module_name = Configuration.spec_overrides.fetch(x, {})["module_name"] # this might no longer be needed after
59
76
  next overridded_module_name
60
77
  end
61
78
  }.compact
@@ -104,9 +121,6 @@ module PodBuilder
104
121
  }
105
122
  end
106
123
 
107
- multiple_buildable_items = podfile_items.uniq { |t| t.root_name }
108
- buildable_items = podfile_items.reject { |t| multiple_buildable_items.map(&:root_name).include?(t.root_name) && t.is_external == false }
109
-
110
124
  result_targets = analyzer.instance_variable_get("@result").targets.map(&:name)
111
125
  podfile_content = ["# Autogenerated by PodBuilder (https://github.com/Subito-it/PodBuilder)", "# Please don't modify this file", "\n"]
112
126
  podfile_content += analyzer.podfile.sources.map { |x| "source '#{x}'" }
@@ -132,7 +146,7 @@ module PodBuilder
132
146
 
133
147
  specifications.each do |spec|
134
148
  item = podfile_items.detect { |x| x.name == spec.name }
135
- if buildable_items.map(&:name).include?(spec.name)
149
+ if podfile_items.map(&:name).include?(spec.name)
136
150
  podfile_content.push("\t#{item.entry}")
137
151
  end
138
152
  end
@@ -143,9 +157,16 @@ module PodBuilder
143
157
  File.write(podfile_restore_path, podfile_content.join("\n"))
144
158
  end
145
159
 
146
- def self.write_prebuilt(all_buildable_items, analyzer)
160
+ def self.write_prebuilt(all_buildable_items, analyzer)
161
+ if Configuration.react_native_project
162
+ return write_prebuilt_react_native(all_buildable_items, analyzer)
163
+ end
164
+
147
165
  puts "Updating Application Podfile".yellow
148
166
 
167
+ explicit_deps = analyzer.explicit_pods()
168
+ explicit_deps.map! { |t| all_buildable_items.detect { |x| x.name == t.name } }
169
+ explicit_deps.uniq!
149
170
  podbuilder_podfile_path = PodBuilder::basepath("Podfile")
150
171
  rel_path = Pathname.new(podbuilder_podfile_path).relative_path_from(Pathname.new(PodBuilder::project_path)).to_s
151
172
 
@@ -160,22 +181,33 @@ module PodBuilder
160
181
  next
161
182
  end
162
183
 
163
- if pod_name = pod_definition_in(line, true)
184
+ if pod_name = pod_definition_in(line, true)
164
185
  if podfile_item = all_buildable_items.detect { |x| x.name == pod_name }
165
- if Podspec.include?(podfile_item.name)
166
- if podfile_item.vendored_framework_path.nil?
167
- marker = podfile_item.prebuilt_marker()
168
-
169
- podfile_item_dependency_items = all_buildable_items.select { |x| podfile_item.dependency_names.include?(x.name) && x.vendored_framework_path.nil? == false }
170
- if podfile_item_dependency_items.count > 0
171
- prebuilt_lines += podfile_item_dependency_items.map { |x| "#{line.detect_indentation}#{x.prebuilt_entry(include_pb_entry = false)}#{marker}\n" }.uniq
172
- else
173
- prebuilt_lines.push(line)
174
- end
175
- else
176
- prebuilt_lines.push("#{line.detect_indentation}#{podfile_item.prebuilt_entry}\n")
186
+ marker = podfile_item.prebuilt_marker()
187
+
188
+ non_explicit_dependencies = podfile_item.recursive_dependencies(all_buildable_items) - explicit_deps
189
+ non_explicit_dependencies_root_names = non_explicit_dependencies.map(&:root_name).uniq.filter { |t| t != podfile_item.root_name }
190
+ non_explicit_dependencies = non_explicit_dependencies_root_names.map { |x|
191
+ if item = all_buildable_items.detect { |t| x == t.name }
192
+ item
193
+ else
194
+ item = all_buildable_items.detect { |t| x == t.root_name }
195
+ end
196
+ }.compact
197
+
198
+ non_explicit_dependencies.each do |dep|
199
+ dep_item = all_buildable_items.detect { |x| x.name == dep.name }
200
+
201
+ if File.exist?(dep_item.prebuilt_podspec_path) && !dep_item.is_prebuilt
202
+ pod_name = dep_item.prebuilt_entry(false, false)
203
+ prebuilt_lines.push("#{line.detect_indentation}#{pod_name}#{marker}\n")
177
204
  end
178
205
 
206
+ explicit_deps.push(dep)
207
+ end
208
+
209
+ if File.exist?(podfile_item.prebuilt_podspec_path) && !podfile_item.is_prebuilt
210
+ prebuilt_lines.push("#{line.detect_indentation}#{podfile_item.prebuilt_entry}\n")
179
211
  next
180
212
  end
181
213
  end
@@ -184,20 +216,45 @@ module PodBuilder
184
216
  prebuilt_lines.push(line)
185
217
  end
186
218
 
219
+ podfile_content = prebuilt_lines.join
220
+
221
+ podfile_content = Podfile.update_path_entries(podfile_content, Podfile.method(:podfile_path_transform))
222
+ podfile_content = Podfile.update_project_entries(podfile_content, Podfile.method(:podfile_path_transform))
223
+ podfile_content = Podfile.update_require_entries(podfile_content, Podfile.method(:podfile_path_transform))
224
+
225
+ podfile_content = add_pre_install_actions(podfile_content)
226
+ podfile_content = add_post_install_checks(podfile_content)
227
+
187
228
  project_podfile_path = PodBuilder::project_path("Podfile")
188
- File.write(project_podfile_path, prebuilt_lines.join)
189
- Podfile.update_path_entires(project_podfile_path, false)
190
- Podfile.update_project_entries(project_podfile_path, false)
229
+ File.write(project_podfile_path, podfile_content)
230
+ end
231
+
232
+ def self.write_prebuilt_react_native(all_buildable_items, analyzer)
233
+ puts "Updating Application Podfile".yellow
234
+
235
+ podbuilder_podfile_path = PodBuilder::basepath("Podfile")
236
+ rel_path = Pathname.new(podbuilder_podfile_path).relative_path_from(Pathname.new(PodBuilder::project_path)).to_s
237
+
238
+ 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
239
+ podfile_content += analyzer.podfile.pb_to_s(all_buildable_items)
191
240
 
192
- add_pre_install_actions(project_podfile_path)
193
- add_post_install_checks(project_podfile_path)
241
+ podfile_content = Podfile.update_path_entries(podfile_content, PodfileCP.method(:podfile_path_transform))
242
+ podfile_content = Podfile.update_project_entries(podfile_content, Podfile.method(:podfile_path_transform))
243
+ podfile_content = Podfile.update_require_entries(podfile_content, Podfile.method(:podfile_path_transform))
244
+
245
+ podfile_content = add_pre_install_actions(podfile_content)
246
+ podfile_content = add_post_install_checks(podfile_content)
247
+
248
+ project_podfile_path = PodBuilder::project_path("Podfile")
249
+ File.write(project_podfile_path, podfile_content)
194
250
  end
195
251
 
196
252
  def self.install
197
253
  puts "Running pod install".yellow
198
254
 
199
255
  Dir.chdir(PodBuilder::project_path) do
200
- system("pod install;")
256
+ bundler_prefix = Configuration.use_bundler ? "bundle exec " : ""
257
+ system("#{bundler_prefix}pod install;")
201
258
  end
202
259
  end
203
260
 
@@ -206,10 +263,6 @@ module PodBuilder
206
263
  return stripped_line.gsub("\"", "'").gsub(" ", "").gsub("\t", "").gsub("\n", "")
207
264
  end
208
265
 
209
- def self.add_install_block(podfile_path)
210
- add(PODBUILDER_LOCK_ACTION, "pre_install", podfile_path)
211
- end
212
-
213
266
  def self.pod_definition_in(line, include_commented)
214
267
  stripped_line = strip_line(line)
215
268
  matches = stripped_line.match(/(^pod')(.*?)(')/)
@@ -253,6 +306,8 @@ module PodBuilder
253
306
  return nil
254
307
  end
255
308
 
309
+ puts "Checking Podfile.restore".yellow
310
+
256
311
  podfile_restore_path = PodBuilder::basepath("Podfile.restore")
257
312
  unless File.exist?(podfile_restore_path)
258
313
  return
@@ -293,16 +348,62 @@ module PodBuilder
293
348
 
294
349
  if stripped_line.match(/(pod')(.*?)(')/) != nil
295
350
  starting_def_found = stripped_line.start_with?("def") && (line.match("\s*def\s") != nil)
296
- raise "Unsupported single line def/pod. `def` and `pod` shouldn't be on the same line, please modify the following line:\n#{line}" if starting_def_found
351
+ raise "\n\nUnsupported single line def/pod. `def` and `pod` shouldn't be on the same line, please modify the following line:\n#{line}".red if starting_def_found
352
+ end
353
+ end
354
+ end
355
+
356
+ def self.resolve_pod_names(names, all_buildable_items)
357
+ resolved_names = []
358
+
359
+ names.each do |name|
360
+ if item = all_buildable_items.detect { |t| t.root_name.downcase == name.downcase }
361
+ resolved_names.push(item.root_name)
297
362
  end
298
363
  end
364
+
365
+ return resolved_names.uniq
366
+ end
367
+
368
+ def self.resolve_pod_names_from_podfile(names)
369
+ resolved_names = []
370
+
371
+ # resolve potentially wrong pod name case
372
+ podfile_path = PodBuilder::basepath("Podfile")
373
+ content = File.read(podfile_path)
374
+
375
+ current_section = ""
376
+ content.each_line do |line|
377
+ matches = line.gsub("\"", "'").match(/pod '(.*?)'/)
378
+ if matches&.size == 2
379
+ if resolved_name = names.detect { |t| matches[1].split("/").first.downcase == t.downcase }
380
+ resolved_names.push(matches[1].split("/").first)
381
+ end
382
+ end
383
+ end
384
+
385
+ resolved_names.uniq
299
386
  end
300
387
 
301
388
  private
302
389
 
303
- def self.indentation_from_file(path)
304
- content = File.read(path)
390
+ def self.podfile_path_transform(path)
391
+ use_absolute_paths = false
392
+ podfile_path = PodBuilder::project_path("Podfile")
393
+ original_basepath = PodBuilder::basepath
394
+
395
+ podfile_base_path = Pathname.new(File.dirname(podfile_path))
305
396
 
397
+ original_path = Pathname.new(File.join(original_basepath, path))
398
+ replace_path = original_path.relative_path_from(podfile_base_path)
399
+ if use_absolute_paths
400
+ replace_path = replace_path.expand_path(podfile_base_path)
401
+ end
402
+
403
+ return replace_path
404
+ end
405
+
406
+ def self.indentation_from_string(content)
306
407
  lines = content.split("\n").select { |x| !x.empty? }
307
408
 
308
409
  if lines.count > 2
@@ -323,13 +424,13 @@ module PodBuilder
323
424
  def self.project_swift_version(analyzer)
324
425
  swift_versions = analyzer.instance_variable_get("@result").targets.map { |x| x.target_definition.swift_version }.compact.uniq
325
426
 
326
- raise "Found different Swift versions in targets. Expecting one, got `#{swift_versions}`" if swift_versions.count > 1
427
+ raise "\n\nFound different Swift versions in targets. Expecting one, got `#{swift_versions}`".red if swift_versions.count > 1
327
428
 
328
429
  return swift_versions.first || PodBuilder::system_swift_version
329
430
  end
330
431
 
331
432
  def self.podfile_items_at(podfile_path, include_prebuilt = false)
332
- raise "Expecting basepath folder!" if !File.exist?(PodBuilder::basepath("Podfile"))
433
+ raise "\n\nExpecting basepath folder!".red if !File.exist?(PodBuilder::basepath("Podfile"))
333
434
 
334
435
  if File.basename(podfile_path) != "Podfile"
335
436
  File.rename(PodBuilder::basepath("Podfile"), PodBuilder::basepath("Podfile.tmp"))
@@ -358,18 +459,20 @@ module PodBuilder
358
459
  return buildable_items
359
460
  end
360
461
 
361
- def self.add_pre_install_actions(podfile_path)
362
- add(PRE_INSTALL_ACTIONS + [" "], "pre_install", podfile_path)
462
+ def self.add_install_block(podfile_content)
463
+ return add(PODBUILDER_LOCK_ACTION, "pre_install", podfile_content)
363
464
  end
364
465
 
365
- def self.add_post_install_checks(podfile_path)
366
- add(POST_INSTALL_ACTIONS + [" "], "post_install", podfile_path)
466
+ def self.add_pre_install_actions(podfile_content)
467
+ return add(PRE_INSTALL_ACTIONS + [" "], "pre_install", podfile_content)
367
468
  end
368
469
 
369
- def self.add(entries, marker, podfile_path)
370
- podfile_content = File.read(podfile_path)
470
+ def self.add_post_install_checks(podfile_content)
471
+ return add(POST_INSTALL_ACTIONS + [" "], "post_install", podfile_content)
472
+ end
371
473
 
372
- file_indentation = indentation_from_file(podfile_path)
474
+ def self.add(entries, marker, podfile_content)
475
+ file_indentation = indentation_from_string(podfile_content)
373
476
 
374
477
  entries = entries.map { |x| "#{file_indentation}#{x}\n"}
375
478
 
@@ -386,55 +489,48 @@ module PodBuilder
386
489
  end
387
490
 
388
491
  if !marker_found
492
+ if podfile_lines.last.strip.length > 0
493
+ podfile_lines.push("\n")
494
+ end
389
495
  podfile_lines.push("\n#{marker} do |installer|\n")
390
496
  podfile_lines.push(entries)
391
497
  podfile_lines.push("end\n")
392
498
  end
393
499
 
394
- File.write(podfile_path, podfile_lines.join)
500
+ return podfile_lines.join
395
501
  end
396
502
 
397
- def self.update_path_entires(podfile_path, use_absolute_paths = false, path_base = PodBuilder::basepath(""))
398
- podfile_content = File.read(podfile_path)
399
-
400
- base_path = Pathname.new(File.dirname(podfile_path))
401
- regex = "(\s*pod\s*['|\"])(.*?)(['|\"])(.*?)(:path\s*=>\s*['|\"])(.*?)(['|\"])"
503
+ def self.update_path_entries(podfile_content, path_transform)
504
+ regex = "(\s*pod\s*['|\"])(.*?)(['|\"])(.*?):(path|podspec)(\s*=>\s*['|\"])(.*?)(['|\"])"
402
505
 
403
506
  podfile_lines = []
404
507
  podfile_content.each_line do |line|
405
508
  stripped_line = strip_line(line)
406
509
  matches = line.match(/#{regex}/)
407
510
 
408
- if matches&.size == 8 && !stripped_line.start_with?("#")
511
+ if matches&.size == 9 && !stripped_line.start_with?("#")
409
512
  pod_name = matches[2]
410
- path = matches[6]
513
+ path = matches[7]
411
514
 
412
515
  is_absolute = ["~", "/"].include?(path[0])
413
- unless !pod_name.start_with?("PodBuilder/") && !is_absolute
516
+ unless !PodBuilder::prebuiltpath.end_with?(path) && !is_absolute
414
517
  podfile_lines.push(line)
415
518
  next
416
519
  end
417
520
 
418
- original_path = Pathname.new(File.join(path_base, path))
419
- replace_path = original_path.relative_path_from(base_path)
420
- if use_absolute_paths
421
- replace_path = replace_path.expand_path(base_path)
422
- end
521
+ replace_path = path_transform.call(path)
423
522
 
424
- updated_path_line = line.gsub(/#{regex}/, '\1\2\3\4\5' + replace_path.to_s + '\7\8')
523
+ updated_path_line = line.gsub(/#{regex}/, '\1\2\3\4:\5\6' + replace_path.to_s + '\8\9')
425
524
  podfile_lines.push(updated_path_line)
426
525
  else
427
526
  podfile_lines.push(line)
428
527
  end
429
528
  end
430
529
 
431
- File.write(podfile_path, podfile_lines.join)
530
+ return podfile_lines.join
432
531
  end
433
532
 
434
- def self.update_project_entries(podfile_path, use_absolute_paths = false, path_base = PodBuilder::basepath(""))
435
- podfile_content = File.read(podfile_path)
436
-
437
- base_path = Pathname.new(File.dirname(podfile_path))
533
+ def self.update_project_entries(podfile_content, path_transform)
438
534
  regex = "(\s*project\s*['|\"])(.*?)(['|\"])"
439
535
 
440
536
  podfile_lines = []
@@ -451,11 +547,36 @@ module PodBuilder
451
547
  next
452
548
  end
453
549
 
454
- original_path = Pathname.new(File.join(path_base, path))
455
- replace_path = original_path.relative_path_from(base_path)
456
- if use_absolute_paths
457
- replace_path = replace_path.expand_path(base_path)
550
+ replace_path = path_transform.call(path)
551
+
552
+ updated_path_line = line.gsub(/#{regex}/, '\1' + replace_path.to_s + '\3\4')
553
+ podfile_lines.push(updated_path_line)
554
+ else
555
+ podfile_lines.push(line)
556
+ end
557
+ end
558
+
559
+ return podfile_lines.join
560
+ end
561
+
562
+ def self.update_require_entries(podfile_content, path_transform)
563
+ regex = "(\s*require_relative\s*['|\"])(.*?)(['|\"])"
564
+
565
+ podfile_lines = []
566
+ podfile_content.each_line do |line|
567
+ stripped_line = strip_line(line)
568
+ matches = line.match(/#{regex}/)
569
+
570
+ if matches&.size == 4 && !stripped_line.start_with?("#")
571
+ path = matches[2]
572
+
573
+ is_absolute = ["~", "/"].include?(path[0])
574
+ unless !is_absolute
575
+ podfile_lines.push(line)
576
+ next
458
577
  end
578
+
579
+ replace_path = path_transform.call(path)
459
580
 
460
581
  updated_path_line = line.gsub(/#{regex}/, '\1' + replace_path.to_s + '\3\4')
461
582
  podfile_lines.push(updated_path_line)
@@ -464,7 +585,113 @@ module PodBuilder
464
585
  end
465
586
  end
466
587
 
467
- File.write(podfile_path, podfile_lines.join)
588
+ return podfile_lines.join
589
+ end
590
+
591
+ def self.prepare_for_react_native_write_pb_configuration(podfile_content)
592
+ base = File.expand_path(File.join(PodBuilder::project_path, ".."))
593
+ bin_js = Dir.glob("#{base}/node_modules/@react-native-community/cli/build/bin.js")
594
+
595
+ raise "\n\nReact native cli bin_js not found!".red unless bin_js.count == 1
596
+ bin_js = bin_js.first
597
+
598
+ config_dest_path = PodBuilder::basepath("rn_config.json")
599
+
600
+ raise "\n\nFailed generating react native configuration file".red unless system("node '#{bin_js}' config > #{config_dest_path}")
601
+
602
+ content = File.read(config_dest_path)
603
+
604
+ content.gsub!(PodBuilder::project_path, "..")
605
+ content.gsub!(File.expand_path(PodBuilder::project_path("..")), "../..")
606
+
607
+ json = JSON.parse(content)
608
+ begin
609
+ json["project"]["ios"]["sourceDir"] = "./"
610
+ json["project"]["ios"]["podfile"] = "./"
611
+ rescue => exception
612
+ raise "\n\nFailed updating react native configuration json".red
613
+ end
614
+
615
+ File.write(config_dest_path, JSON.pretty_generate(json))
616
+
617
+ return "rn_config = JSON.load(File.read(\"rn_config.json\")) # pb added\n\n" + podfile_content
618
+ end
619
+
620
+ def self.prepare_for_react_native_rn_pods_file(podfile_content)
621
+ lines = []
622
+ podfile_content.each_line do |line|
623
+ if line.include?("use_react_native!")
624
+ matches = line.match(/(\s*)/)
625
+ unless matches&.size == 2
626
+ return podfile_content
627
+ end
628
+
629
+ indentation = matches[1]
630
+ lines.push("#{indentation}use_react_native!(:path => rn_config[\"reactNativePath\"]) # pb added\n")
631
+ lines.push("#{indentation}# #{line.strip} # pb removed\n")
632
+ else
633
+ lines.push(line)
634
+ end
635
+ end
636
+
637
+ return lines.join
638
+ end
639
+
640
+ def self.prepare_for_react_native_native_modules_file(podfile_content)
641
+ lines = []
642
+ podfile_content.each_line do |line|
643
+ if line.include?("use_native_modules!")
644
+ matches = line.match(/(\s*)/)
645
+ unless matches&.size == 2
646
+ return podfile_content
647
+ end
648
+
649
+ indentation = matches[1]
650
+ lines.push("#{indentation}use_native_modules!(rn_config) # pb added\n")
651
+ lines.push("#{indentation}# #{line.strip} # pb removed\n")
652
+ else
653
+ lines.push(line)
654
+ end
655
+ end
656
+
657
+ return lines.join
658
+ end
659
+
660
+ def self.prepare_for_react_native(podfile_content)
661
+ original_podfile_content = podfile_content.dup
662
+
663
+ podfile_content = prepare_for_react_native_write_pb_configuration(podfile_content)
664
+ content = prepare_for_react_native_rn_pods_file(podfile_content)
665
+ if content == podfile_content
666
+ return original_podfile_content
667
+ end
668
+ podfile_content = content
669
+ content = prepare_for_react_native_native_modules_file(podfile_content)
670
+ if content == podfile_content
671
+ return original_podfile_content
672
+ end
673
+ podfile_content = content
674
+
675
+ Configuration.build_using_repo_paths = true
676
+ Configuration.react_native_project = true
677
+
678
+ return podfile_content
679
+ end
680
+
681
+ def self.install_using_frameworks(analyzer)
682
+ target_settings = analyzer.podfile.target_definition_list.map(&:uses_frameworks?).uniq
683
+ if target_settings.count == 1
684
+ if target_settings.first == false
685
+ raise "\n\nOnly framework packaging currently supported. Please add 'use_frameworks!' at Podfile root level (not nested in targets)".red
686
+ end
687
+ return target_settings.first
688
+ elsif target_settings.count > 1
689
+ raise "\n\n'use_frameworks!' should be declared only once at Podfile root level (not nested in targets)".red
690
+ else
691
+ raise "\n\nFailed detecting use_frameworks!"
692
+ end
693
+
694
+ return true
468
695
  end
469
696
  end
470
697
  end