Class: PodBuilder::Command::InstallSources

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

Class Method Summary collapse

Class Method Details

.callObject



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

def self.call
  Configuration.check_inited
  if Configuration.build_using_repo_paths
    raise "\n\nSource cannot be installed because lldb shenanigans not supported when 'build_using_repo_paths' is enabled".red
  end

  PodBuilder::prepare_basepath

  argument_pods = ARGV.dup

  install_update_repo = OPTIONS.fetch(:update_repos, true)
  installer, analyzer = Analyze.installer_at(PodBuilder::basepath, install_update_repo)
  podfile_items = Analyze.podfile_items(installer, analyzer).select { |x| !x.is_prebuilt }
  podspec_names = podfile_items.map(&:podspec_name)

  base_path = PodBuilder::prebuiltpath
  framework_files = Dir.glob("#{base_path}/**/*.framework")
  
  framework_files.each do |path|
    next if !OPTIONS.has_key?(:all) && !argument_pods.include?(File.basename(path, ".*"))

    if podfile_spec = podfile_items.detect { |x| x.root_name == File.basename(path, ".*") }
      update_repo(podfile_spec)
    end
  end

  Clean::install_sources(podfile_items)

  ARGV << PodBuilder::basepath("Sources")

  puts "\n\nšŸŽ‰ done!\n".green
  return 0
end

.git_hard_checkout_cmd(spec) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/pod_builder/command/install_sources.rb', line 63

def self.git_hard_checkout_cmd(spec)
  prefix = "git fetch --all --tags --prune; git reset --hard"
  if spec.tag
    return "#{prefix} tags/#{spec.tag}"
  end
  if spec.commit
    return "#{prefix} #{spec.commit}"
  end
  if spec.branch
    return "#{prefix} origin/#{spec.branch}"
  end
  
  return nil
end

.update_repo(spec) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pod_builder/command/install_sources.rb', line 42

def self.update_repo(spec)
  if spec.path != nil || spec.podspec_path != nil
    return
  end

  dest_path = PodBuilder::basepath("Sources")
  FileUtils.mkdir_p(dest_path)

  repo_dir = File.join(dest_path, spec.podspec_name)
  Dir.chdir(dest_path) do
    if !File.directory?(repo_dir)
      raise "\n\nFailed cloning #{spec.name}".red if !system("git clone #{spec.repo} #{spec.podspec_name}")
    end
  end

  Dir.chdir(repo_dir) do
    puts "Checking out #{spec.podspec_name}".yellow
    raise "\n\nFailed cheking out #{spec.name}".red if !system(git_hard_checkout_cmd(spec))
  end
end