cocoapods-binary-cache 0.1.6 → 0.1.11

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