cocoapods-binary-cache 0.1.5 → 0.1.10

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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cocoapods-binary-cache/cache/validation_result.rb +4 -0
  3. data/lib/cocoapods-binary-cache/cache/validator.rb +1 -1
  4. data/lib/cocoapods-binary-cache/cache/validator_dependencies_graph.rb +7 -2
  5. data/lib/cocoapods-binary-cache/dependencies_graph/dependencies_graph.rb +20 -25
  6. data/lib/cocoapods-binary-cache/dependencies_graph/graph_visualizer.rb +29 -38
  7. data/lib/cocoapods-binary-cache/diagnosis/diagnosis.rb +9 -1
  8. data/lib/cocoapods-binary-cache/diagnosis/integration.rb +7 -3
  9. data/lib/cocoapods-binary-cache/env.rb +1 -1
  10. data/lib/cocoapods-binary-cache/helper/checksum.rb +10 -4
  11. data/lib/cocoapods-binary-cache/helper/lockfile.rb +1 -1
  12. data/lib/cocoapods-binary-cache/helper/podspec.rb +4 -2
  13. data/lib/cocoapods-binary-cache/hooks/post_install.rb +2 -12
  14. data/lib/cocoapods-binary-cache/hooks/pre_install.rb +22 -39
  15. data/lib/cocoapods-binary-cache/main.rb +0 -1
  16. data/lib/cocoapods-binary-cache/pod-binary/helper/build.rb +37 -0
  17. data/lib/cocoapods-binary-cache/pod-binary/helper/detected_prebuilt_pods/installer.rb +2 -2
  18. data/lib/cocoapods-binary-cache/pod-binary/helper/detected_prebuilt_pods/target_definition.rb +2 -9
  19. data/lib/cocoapods-binary-cache/pod-binary/helper/prebuild_sandbox.rb +15 -14
  20. data/lib/cocoapods-binary-cache/pod-binary/helper/target_checker.rb +7 -10
  21. data/lib/cocoapods-binary-cache/pod-binary/integration.rb +1 -2
  22. data/lib/cocoapods-binary-cache/pod-binary/integration/alter_specs.rb +4 -1
  23. data/lib/cocoapods-binary-cache/pod-binary/integration/patch/embed_framework_script.rb +1 -1
  24. data/lib/cocoapods-binary-cache/pod-binary/integration/patch/resolve_dependencies.rb +0 -3
  25. data/lib/cocoapods-binary-cache/pod-binary/integration/patch/sandbox_analyzer_state.rb +29 -0
  26. data/lib/cocoapods-binary-cache/pod-binary/integration/patch/source_installation.rb +27 -12
  27. data/lib/cocoapods-binary-cache/pod-binary/integration/source_installer.rb +57 -62
  28. data/lib/cocoapods-binary-cache/pod-binary/prebuild.rb +45 -121
  29. data/lib/cocoapods-binary-cache/pod-binary/prebuild_dsl.rb +2 -63
  30. data/lib/cocoapods-binary-cache/pod-binary/prebuild_hook.rb +0 -1
  31. data/lib/cocoapods-binary-cache/pod-rome/xcodebuild_command.rb +195 -0
  32. data/lib/cocoapods-binary-cache/pod-rome/xcodebuild_raw.rb +48 -0
  33. data/lib/cocoapods-binary-cache/prebuild_output/output.rb +7 -5
  34. data/lib/cocoapods-binary-cache/state_store.rb +16 -6
  35. data/lib/command/binary.rb +20 -1
  36. data/lib/command/config.rb +177 -8
  37. data/lib/command/executor/base.rb +9 -1
  38. data/lib/command/executor/fetcher.rb +5 -3
  39. data/lib/command/executor/prebuilder.rb +9 -7
  40. data/lib/command/executor/pusher.rb +2 -0
  41. data/lib/command/executor/visualizer.rb +3 -2
  42. data/lib/command/fetch.rb +0 -1
  43. data/lib/command/prebuild.rb +19 -3
  44. data/lib/command/push.rb +0 -1
  45. metadata +9 -11
  46. data/lib/cocoapods-binary-cache/pod-binary/helper/feature_switches.rb +0 -52
  47. data/lib/cocoapods-binary-cache/pod-binary/helper/passer.rb +0 -25
  48. data/lib/cocoapods-binary-cache/pod-binary/integration/remove_target_files.rb +0 -29
  49. data/lib/cocoapods-binary-cache/pod-binary/tool/tool.rb +0 -12
  50. data/lib/cocoapods-binary-cache/pod-rome/build_framework.rb +0 -248
  51. data/lib/cocoapods-binary-cache/scheme_editor.rb +0 -35
@@ -0,0 +1,48 @@
1
+ require "fourflusher"
2
+
3
+ module PodPrebuild
4
+ class XcodebuildCommand
5
+ PLATFORM_OF_SDK = {
6
+ "iphonesimulator" => "iOS",
7
+ "appletvsimulator" => "tvOS",
8
+ "watchsimulator" => "watchOS"
9
+ }.freeze
10
+
11
+ def self.xcodebuild(options)
12
+ sdk = options[:sdk] || "iphonesimulator"
13
+ targets = options[:targets] || [options[:target]]
14
+ platform = PLATFORM_OF_SDK[sdk]
15
+
16
+ cmd = ["xcodebuild"]
17
+ cmd << "-project" << options[:sandbox].project_path.realdirpath
18
+ targets.each { |target| cmd << "-target" << target }
19
+ cmd << "-configuration" << options[:configuration]
20
+ cmd << "-sdk" << sdk
21
+ unless platform.nil?
22
+ cmd << Fourflusher::SimControl.new.destination(:oldest, platform, options[:deployment_target])
23
+ end
24
+ cmd += options[:args] if options[:args]
25
+ cmd << "build"
26
+ cmd << "2>&1"
27
+ cmd = cmd.join(" ")
28
+
29
+ Pod::UI.puts_indented "$ #{cmd}"
30
+ log = `#{cmd}`
31
+ return if $?.exitstatus.zero? # rubocop:disable Style/SpecialGlobalVars
32
+
33
+ begin
34
+ require "xcpretty" # TODO (thuyen): Revise this dependency
35
+ # use xcpretty to print build log
36
+ # 64 represent command invalid. http://www.manpagez.com/man/3/sysexits/
37
+ printer = XCPretty::Printer.new({:formatter => XCPretty::Simple, :colorize => "auto"})
38
+ log.each_line do |line|
39
+ printer.pretty_print(line)
40
+ end
41
+ rescue
42
+ Pod::UI.puts log.red
43
+ ensure
44
+ raise "Fail to build targets: #{targets}"
45
+ end
46
+ end
47
+ end
48
+ end
@@ -8,7 +8,7 @@ module PodPrebuild
8
8
  end
9
9
 
10
10
  def prebuild_delta_path
11
- @prebuild_delta_path ||= PodPrebuild::Config.instance.prebuild_delta_path
11
+ @prebuild_delta_path ||= PodPrebuild.config.prebuild_delta_path
12
12
  end
13
13
 
14
14
  def delta_dir
@@ -16,7 +16,7 @@ module PodPrebuild
16
16
  end
17
17
 
18
18
  def clean_delta_file
19
- puts "Clean delta file: #{prebuild_delta_path}"
19
+ Pod::UI.message "Clean delta file: #{prebuild_delta_path}"
20
20
  FileUtils.rm_rf(prebuild_delta_path)
21
21
  end
22
22
 
@@ -24,14 +24,16 @@ module PodPrebuild
24
24
  FileUtils.mkdir_p dir unless File.directory?(dir)
25
25
  end
26
26
 
27
- # Input 2 arrays of library names
28
- def write_delta_file(updated, deleted)
27
+ def write_delta_file(options)
28
+ updated = options[:updated]
29
+ deleted = options[:deleted]
30
+
29
31
  if updated.empty? && deleted.empty?
30
32
  Pod::UI.puts "No changes in prebuild"
31
33
  return
32
34
  end
33
35
 
34
- Pod::UI.puts "Write prebuild changes to: #{prebuild_delta_path}"
36
+ Pod::UI.message "Write prebuild changes to: #{prebuild_delta_path}"
35
37
  create_dir_if_needed(delta_dir)
36
38
  changes = PodPrebuild::JSONFile.new(prebuild_delta_path)
37
39
  changes["updated"] = updated
@@ -1,11 +1,21 @@
1
1
  module PodPrebuild
2
- class StateStore
3
- @excluded_pods = Set.new
4
- @cache_validation = CacheValidationResult.new
2
+ def self.state
3
+ @state ||= State.new
4
+ end
5
+
6
+ class State
7
+ def initialize
8
+ @store = {
9
+ :cache_validation => CacheValidationResult.new
10
+ }
11
+ end
12
+
13
+ def update(data)
14
+ @store.merge!(data)
15
+ end
5
16
 
6
- class << self
7
- attr_accessor :excluded_pods
8
- attr_accessor :cache_validation
17
+ def cache_validation
18
+ @store[:cache_validation]
9
19
  end
10
20
  end
11
21
  end
@@ -9,9 +9,28 @@ module Pod
9
9
  class Command
10
10
  class Binary < Command
11
11
  self.abstract_command = true
12
+ def self.options
13
+ [
14
+ ["--repo", "Cache repo (in accordance with `cache_repo` in `config_cocoapods_binary_cache`)"]
15
+ ]
16
+ end
17
+
18
+ def initialize(argv)
19
+ super
20
+ load_podfile
21
+ update_cli_config(:repo => argv.option("repo"))
22
+ end
12
23
 
13
24
  def prebuild_config
14
- @prebuild_config ||= PodPrebuild::Config.instance
25
+ @prebuild_config ||= PodPrebuild.config
26
+ end
27
+
28
+ def load_podfile
29
+ Pod::Config.instance.podfile
30
+ end
31
+
32
+ def update_cli_config(options)
33
+ PodPrebuild.config.cli_config.merge!(options)
15
34
  end
16
35
  end
17
36
  end
@@ -1,31 +1,200 @@
1
1
  require_relative "../cocoapods-binary-cache/helper/json"
2
2
 
3
3
  module PodPrebuild
4
- class Config
5
- attr_reader :cache_repo, :cache_path, :prebuild_path, :prebuild_delta_path
4
+ def self.config
5
+ PodPrebuild::Config.instance
6
+ end
7
+
8
+ class Config # rubocop:disable Metrics/ClassLength
9
+ attr_accessor :dsl_config, :cli_config
6
10
 
7
11
  def initialize(path)
8
- @data = PodPrebuild::JSONFile.new(path)
9
- @cache_repo = @data["cache_repo"] || @data["prebuilt_cache_repo"]
10
- @cache_path = File.expand_path(@data["cache_path"])
11
- @prebuild_path = @data["prebuild_path"] || "_Prebuild"
12
- @prebuild_delta_path = @data["prebuild_delta_path"] || "_Prebuild_delta/changes.json"
12
+ @deprecated_config = File.exist?(path) ? PodPrebuild::JSONFile.new(path).data : {}
13
+ @dsl_config = {}
14
+ @cli_config = {}
15
+ @detected_config = {}
13
16
  end
14
17
 
15
18
  def self.instance
16
19
  @instance ||= new("PodBinaryCacheConfig.json")
17
20
  end
18
21
 
22
+ def reset!
23
+ @deprecated_config = {}
24
+ @dsl_config = {}
25
+ @cli_config = {}
26
+ end
27
+
28
+ def cache_repo
29
+ @cache_repo ||= cache_repo_config["remote"]
30
+ end
31
+
32
+ def cache_path
33
+ @cache_path ||= File.expand_path(cache_repo_config["local"])
34
+ end
35
+
36
+ def prebuild_sandbox_path
37
+ @dsl_config[:prebuild_sandbox_path] || @deprecated_config["prebuild_path"] || "_Prebuild"
38
+ end
39
+
40
+ def prebuild_delta_path
41
+ @dsl_config[:prebuild_delta_path] || @deprecated_config["prebuild_delta_path"] || "_Prebuild_delta/changes.json"
42
+ end
43
+
19
44
  def manifest_path(in_cache: false)
20
45
  root_dir(in_cache) + "/Manifest.lock"
21
46
  end
22
47
 
23
48
  def root_dir(in_cache)
24
- in_cache ? @cache_path : @prebuild_path
49
+ in_cache ? cache_path : prebuild_sandbox_path
25
50
  end
26
51
 
27
52
  def generated_frameworks_dir(in_cache: false)
28
53
  root_dir(in_cache) + "/GeneratedFrameworks"
29
54
  end
55
+
56
+ def prebuilt_path(path: nil)
57
+ path.nil? ? "_Prebuilt" : "_Prebuilt/#{path}"
58
+ end
59
+
60
+ def validate_dsl_config
61
+ inapplicable_options = @dsl_config.keys - applicable_dsl_config
62
+ return if inapplicable_options.empty?
63
+
64
+ message = <<~HEREDOC
65
+ [WARNING] The following options (in `config_cocoapods_binary_cache`) are not correct: #{inapplicable_options}.
66
+ Available options: #{applicable_dsl_config}.
67
+ Check out the following doc for more details
68
+ https://github.com/grab/cocoapods-binary-cache/blob/master/docs/configure_cocoapods_binary_cache.md
69
+ HEREDOC
70
+
71
+ Pod::UI.puts message.yellow
72
+ end
73
+
74
+ def prebuild_config
75
+ @cli_config[:prebuild_config] || @dsl_config[:prebuild_config] || "Debug"
76
+ end
77
+
78
+ def prebuild_job?
79
+ @cli_config[:prebuild_job] || @dsl_config[:prebuild_job]
80
+ end
81
+
82
+ def prebuild_all_pods?
83
+ @cli_config[:prebuild_all_pods] || @dsl_config[:prebuild_all_pods]
84
+ end
85
+
86
+ def excluded_pods
87
+ ((@dsl_config[:excluded_pods] || Set.new) + (@detected_config[:excluded_pods] || Set.new)).to_set
88
+ end
89
+
90
+ def dev_pods_enabled?
91
+ @dsl_config[:dev_pods_enabled]
92
+ end
93
+
94
+ def bitcode_enabled?
95
+ @dsl_config[:bitcode_enabled]
96
+ end
97
+
98
+ def device_build_enabled?
99
+ @dsl_config[:device_build_enabled]
100
+ end
101
+
102
+ def disable_dsym?
103
+ @dsl_config[:disable_dsym]
104
+ end
105
+
106
+ def still_download_sources?(name)
107
+ option = @dsl_config[:still_download_sources]
108
+ option.is_a?(Array) ? option.include?(name) : option
109
+ end
110
+
111
+ def dont_remove_source_code?
112
+ @dsl_config[:dont_remove_source_code]
113
+ end
114
+
115
+ def build_args
116
+ @dsl_config[:build_args]
117
+ end
118
+
119
+ def save_cache_validation_to
120
+ @dsl_config[:save_cache_validation_to]
121
+ end
122
+
123
+ def validate_prebuilt_settings
124
+ @dsl_config[:validate_prebuilt_settings]
125
+ end
126
+
127
+ def prebuild_code_gen
128
+ @dsl_config[:prebuild_code_gen]
129
+ end
130
+
131
+ def strict_diagnosis?
132
+ @dsl_config[:strict_diagnosis]
133
+ end
134
+
135
+ def targets_to_prebuild_from_cli
136
+ @cli_config[:prebuild_targets] || []
137
+ end
138
+
139
+ def update_detected_prebuilt_pod_names!(value)
140
+ @detected_config[:prebuilt_pod_names] = value
141
+ end
142
+
143
+ def update_detected_excluded_pods!(value)
144
+ @detected_config[:excluded_pods] = value
145
+ end
146
+
147
+ def prebuilt_pod_names
148
+ @detected_config[:prebuilt_pod_names] || Set.new
149
+ end
150
+
151
+ def tracked_prebuilt_pod_names
152
+ prebuilt_pod_names - excluded_pods
153
+ end
154
+
155
+ private
156
+
157
+ def applicable_dsl_config
158
+ [
159
+ :cache_repo,
160
+ :prebuild_sandbox_path,
161
+ :prebuild_delta_path,
162
+ :prebuild_config,
163
+ :prebuild_job,
164
+ :prebuild_all_pods,
165
+ :excluded_pods,
166
+ :dev_pods_enabled,
167
+ :bitcode_enabled,
168
+ :device_build_enabled,
169
+ :disable_dsym,
170
+ :still_download_sources,
171
+ :dont_remove_source_code,
172
+ :build_args,
173
+ :save_cache_validation_to,
174
+ :validate_prebuilt_settings,
175
+ :prebuild_code_gen,
176
+ :strict_diagnosis
177
+ ]
178
+ end
179
+
180
+ def cache_repo_config
181
+ @cache_repo_config ||= begin
182
+ repo = @cli_config[:repo] || "default"
183
+ config_ = @dsl_config[:cache_repo] || {}
184
+ if config_[repo].nil?
185
+ message = <<~HEREDOC
186
+ [Deprecated] Configs in `PodBinaryCacheConfig.json` are deprecated.
187
+ Declare option `cache_repo` in `config_cocoapods_binary_cache` instead.
188
+ Check out the following doc for more details
189
+ https://github.com/grab/cocoapods-binary-cache/blob/master/docs/configure_cocoapods_binary_cache.md
190
+ HEREDOC
191
+ Pod::UI.puts message.yellow
192
+ end
193
+ config_[repo] || {
194
+ "remote" => @deprecated_config["cache_repo"] || @deprecated_config["prebuilt_cache_repo"],
195
+ "local" => @deprecated_config["cache_path"] || "~/.cocoapods-binary-cache/prebuilt-frameworks"
196
+ }
197
+ end
198
+ end
30
199
  end
31
200
  end
@@ -4,13 +4,21 @@ module PodPrebuild
4
4
  @config = options[:config]
5
5
  end
6
6
 
7
+ def installer
8
+ @installer ||= begin
9
+ pod_config = Pod::Config.instance
10
+ Pod::Installer.new(pod_config.sandbox, pod_config.podfile, pod_config.lockfile)
11
+ end
12
+ end
13
+
7
14
  def git(cmd, options = {})
8
15
  comps = ["git"]
9
16
  comps << "-C" << @config.cache_path unless options[:cache_repo] == false
10
17
  comps << cmd
11
18
  comps << "&> /dev/null" if options[:ignore_output]
12
19
  comps << "|| true" if options[:can_fail]
13
- `#{comps.join(" ")}`
20
+ cmd = comps.join(" ")
21
+ raise "Fail to run command '#{cmd}'" unless system(cmd)
14
22
  end
15
23
 
16
24
  def git_clone(cmd, options = {})
@@ -3,6 +3,8 @@ require_relative "../helper/zip"
3
3
 
4
4
  module PodPrebuild
5
5
  class CacheFetcher < CommandExecutor
6
+ attr_reader :cache_branch
7
+
6
8
  def initialize(options)
7
9
  super(options)
8
10
  @cache_branch = options[:cache_branch]
@@ -31,9 +33,9 @@ module PodPrebuild
31
33
  end
32
34
 
33
35
  def unzip_cache
34
- Pod::UI.puts "Unzipping cache: #{@config.cache_path} -> #{@config.prebuild_path}".green
35
- FileUtils.rm_rf(@config.prebuild_path)
36
- FileUtils.mkdir_p(@config.prebuild_path)
36
+ Pod::UI.puts "Unzipping cache: #{@config.cache_path} -> #{@config.prebuild_sandbox_path}".green
37
+ FileUtils.rm_rf(@config.prebuild_sandbox_path)
38
+ FileUtils.mkdir_p(@config.prebuild_sandbox_path)
37
39
 
38
40
  if File.exist?(@config.manifest_path(in_cache: true))
39
41
  FileUtils.cp(
@@ -4,29 +4,31 @@ require_relative "pusher"
4
4
 
5
5
  module PodPrebuild
6
6
  class CachePrebuilder < CommandExecutor
7
+ attr_reader :repo_update, :fetcher, :pusher
8
+
7
9
  def initialize(options)
8
10
  super(options)
9
- @cache_branch = options[:cache_branch]
10
- @push_cache = options[:push_cache]
11
- @fetcher = PodPrebuild::CacheFetcher.new(options)
12
- @pusher = PodPrebuild::CachePusher.new(options)
11
+ @repo_update = options[:repo_update]
12
+ @fetcher = PodPrebuild::CacheFetcher.new(options) unless options[:no_fetch]
13
+ @pusher = PodPrebuild::CachePusher.new(options) if options[:push_cache]
13
14
  end
14
15
 
15
16
  def run
16
- @fetcher.run
17
+ @fetcher&.run
17
18
  prebuild
18
19
  changes = PodPrebuild::JSONFile.new(@config.prebuild_delta_path)
19
20
  return if changes.empty?
20
21
 
21
22
  sync_cache(changes)
22
- @pusher.run if @push_cache
23
+ @pusher&.run
23
24
  end
24
25
 
25
26
  private
26
27
 
27
28
  def prebuild
28
29
  Pod::UI.step("Installation") do
29
- Pod::Command::Install.new(CLAide::ARGV.new([])).run
30
+ installer.repo_update = @repo_update
31
+ installer.install!
30
32
  end
31
33
  end
32
34
 
@@ -2,6 +2,8 @@ require_relative "base"
2
2
 
3
3
  module PodPrebuild
4
4
  class CachePusher < CommandExecutor
5
+ attr_reader :cache_branch
6
+
5
7
  def initialize(options)
6
8
  super(options)
7
9
  @cache_branch = options[:cache_branch]