Class: PodBuilder::Command::Build

Inherits:
Object
  • Object
show all
Defined in:
lib/pod_builder/command/build.rb

Class Method Summary collapse

Class Method Details

.call(options) ⇒ Object



6
7
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
# File 'lib/pod_builder/command/build.rb', line 6

def self.call(options)          
  Configuration.check_inited
  PodBuilder::prepare_basepath

  argument_pods = ARGV.dup

  unless argument_pods.count > 0 
    return -1
  end

  Podfile.sanity_check()
  check_not_building_subspecs(argument_pods)

  install_update_repo = options.fetch(:update_repos, true)
  installer, analyzer = Analyze.installer_at(PodBuilder::basepath, install_update_repo)

  all_buildable_items = Analyze.podfile_items(installer, analyzer)
  prebuilt_items = all_buildable_items.select { |x| x.is_prebuilt }
  buildable_items = all_buildable_items - prebuilt_items

  if argument_pods.first == "*"
    argument_pods = buildable_items.map(&:root_name)
  end

  available_argument_pods = argument_pods.select { |x| all_buildable_items.map(&:root_name).include?(x) }     
  (argument_pods - available_argument_pods).each { |x|
    puts "'#{x}' not found, skipping".magenta
  }
  argument_pods = available_argument_pods.uniq
  
  prebuilt_pods_to_install = prebuilt_items.select { |x| argument_pods.include?(x.root_name) }

  Podfile.restore_podfile_clean(all_buildable_items)

  restore_file_error = Podfile.restore_file_sanity_check
  
  check_splitted_subspecs_are_static(all_buildable_items, options)
  check_pods_exists(argument_pods, all_buildable_items)

  pods_to_build = resolve_pods_to_build(argument_pods, buildable_items, options)
  buildable_items -= pods_to_build

  # Remove dependencies from pods to build
  all_dependencies_name = pods_to_build.map(&:dependency_names).flatten.uniq
  pods_to_build.select! { |x| !all_dependencies_name.include?(x.name) }

  # We need to split pods to build in 3 groups
  # 1. subspecs: because the resulting .framework path is treated differently when added to Configuration.subspecs_to_split
  # 2. pods to build in release
  # 3. pods to build in debug

  pods_to_build_subspecs = pods_to_build.select { |x| x.is_subspec && Configuration.subspecs_to_split.include?(x.name) }
  pods_to_build -= pods_to_build_subspecs
  pods_to_build_debug = pods_to_build.select { |x| x.build_configuration == "debug" }
  pods_to_build_release = pods_to_build - pods_to_build_debug

  check_dependencies_build_configurations(all_buildable_items)

  podfiles_items = pods_to_build_subspecs.map { |x| [x] }
  podfiles_items.push(pods_to_build_debug)
  podfiles_items.push(pods_to_build_release)   

  licenses = []
  
  podfiles_items.select { |x| x.count > 0 }.each do |podfile_items|
    podfile_items = add_dependencies(podfile_items, all_buildable_items)
    podfile_content = Podfile.from_podfile_items(podfile_items, analyzer)
    
    Install.podfile(podfile_content, podfile_items, podfile_items.first.build_configuration)

    licenses += license_specifiers
    
    # remove lockfile which gets unexplicably created
    FileUtils.rm_f(PodBuilder::basepath("Podfile.lock"))
  end

  Licenses::write(licenses, all_buildable_items)

  GenerateLFS::call(nil)
  Podspec::generate(analyzer)

  builded_pods = podfiles_items.flatten
  builded_pods_and_deps = add_dependencies(builded_pods, all_buildable_items).select { |x| !x.is_prebuilt }
  Podfile::write_restorable(builded_pods_and_deps + prebuilt_pods_to_install, all_buildable_items, analyzer)     
  if !options.has_key?(:skip_prebuild_update)   
    Podfile::write_prebuilt(all_buildable_items, analyzer)
  end

  Podfile::install

  sanity_checks(options)

  if (restore_file_error = restore_file_error) && Configuration.restore_enabled
    puts "\n\n⚠️ Podfile.restore was found invalid and was overwritten. Error:\n #{restore_file_error}".red
  end

  puts "\n\n🎉 done!\n".green
  return 0
end