cocoapods-binary-cache 0.1.8 → 0.1.13

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.
@@ -1,43 +1,58 @@
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
+ DESTINATION_OF_SDK = {
12
+ "iphoneos" => "\"generic/platform=iOS\"",
13
+ "iphonesimulator" => "\"generic/platform=iOS Simulator\""
14
+ }.freeze
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(" ")
16
+ def self.xcodebuild(options)
17
+ sdk = options[:sdk] || "iphonesimulator"
18
+ targets = options[:targets] || [options[:target]]
19
+ platform = PLATFORM_OF_SDK[sdk]
22
20
 
23
- Pod::UI.puts_indented "$ #{cmd}"
24
- log = `#{cmd}`
21
+ cmd = ["xcodebuild"]
22
+ cmd << "-project" << options[:sandbox].project_path.realdirpath.shellescape
23
+ targets.each { |target| cmd << "-target" << target }
24
+ cmd << "-configuration" << options[:configuration]
25
+ cmd << "-sdk" << sdk
26
+ if DESTINATION_OF_SDK.key?(sdk)
27
+ cmd << "-destination" << DESTINATION_OF_SDK[sdk]
28
+ else
29
+ unless platform.nil?
30
+ cmd << Fourflusher::SimControl.new.destination(:oldest, platform, options[:deployment_target])
31
+ end
32
+ end
33
+ cmd += options[:args] if options[:args]
34
+ cmd << "build"
35
+ cmd << "2>&1"
36
+ cmd = cmd.join(" ")
37
+
38
+ Pod::UI.puts_indented "$ #{cmd}" unless PodPrebuild.config.silent_build?
25
39
 
26
- succeeded = $?.exitstatus.zero? # rubocop:disable Style/SpecialGlobalVars
27
- unless succeeded
28
- begin
29
- raise "Unexpected error" unless log.include?("** BUILD FAILED **")
40
+ log = `#{cmd}`
41
+ return if $?.exitstatus.zero? # rubocop:disable Style/SpecialGlobalVars
30
42
 
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)
43
+ begin
44
+ require "xcpretty" # TODO (thuyen): Revise this dependency
45
+ # use xcpretty to print build log
46
+ # 64 represent command invalid. http://www.manpagez.com/man/3/sysexits/
47
+ printer = XCPretty::Printer.new({:formatter => XCPretty::Simple, :colorize => "auto"})
48
+ log.each_line do |line|
49
+ printer.pretty_print(line)
50
+ end
51
+ rescue
52
+ Pod::UI.puts log.red
53
+ ensure
54
+ raise "Fail to build targets: #{targets}"
37
55
  end
38
- rescue
39
- Pod::UI.puts log.red
40
56
  end
41
57
  end
42
- [succeeded, log]
43
58
  end
@@ -29,6 +29,10 @@ module PodPrebuild
29
29
  @cache_repo ||= cache_repo_config["remote"]
30
30
  end
31
31
 
32
+ def local_cache?
33
+ cache_repo.nil?
34
+ end
35
+
32
36
  def cache_path
33
37
  @cache_path ||= File.expand_path(cache_repo_config["local"])
34
38
  end
@@ -54,7 +58,9 @@ module PodPrebuild
54
58
  end
55
59
 
56
60
  def prebuilt_path(path: nil)
57
- path.nil? ? "_Prebuilt" : "_Prebuilt/#{path}"
61
+ p = Pathname.new(path.nil? ? "_Prebuilt" : "_Prebuilt/#{path}")
62
+ p = p.sub_ext(".xcframework") if xcframework? && p.extname == ".framework"
63
+ p.to_s
58
64
  end
59
65
 
60
66
  def validate_dsl_config
@@ -99,6 +105,10 @@ module PodPrebuild
99
105
  @dsl_config[:device_build_enabled]
100
106
  end
101
107
 
108
+ def xcframework?
109
+ @dsl_config[:xcframework]
110
+ end
111
+
102
112
  def disable_dsym?
103
113
  @dsl_config[:disable_dsym]
104
114
  end
@@ -127,6 +137,10 @@ module PodPrebuild
127
137
  @dsl_config[:strict_diagnosis]
128
138
  end
129
139
 
140
+ def silent_build?
141
+ @dsl_config[:silent_build]
142
+ end
143
+
130
144
  def targets_to_prebuild_from_cli
131
145
  @cli_config[:prebuild_targets] || []
132
146
  end
@@ -161,13 +175,15 @@ module PodPrebuild
161
175
  :dev_pods_enabled,
162
176
  :bitcode_enabled,
163
177
  :device_build_enabled,
178
+ :xcframework,
164
179
  :disable_dsym,
165
180
  :dont_remove_source_code,
166
181
  :build_args,
167
182
  :save_cache_validation_to,
168
183
  :validate_prebuilt_settings,
169
184
  :prebuild_code_gen,
170
- :strict_diagnosis
185
+ :strict_diagnosis,
186
+ :silent_build
171
187
  ]
172
188
  end
173
189
 
@@ -2,6 +2,7 @@ module PodPrebuild
2
2
  class CommandExecutor
3
3
  def initialize(options)
4
4
  @config = options[:config]
5
+ prepare_cache_dir
5
6
  end
6
7
 
7
8
  def installer
@@ -11,13 +12,22 @@ module PodPrebuild
11
12
  end
12
13
  end
13
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
21
+ end
22
+
14
23
  def git(cmd, options = {})
15
24
  comps = ["git"]
16
25
  comps << "-C" << @config.cache_path unless options[:cache_repo] == false
17
26
  comps << cmd
18
27
  comps << "&> /dev/null" if options[:ignore_output]
19
28
  comps << "|| true" if options[:can_fail]
20
- `#{comps.join(" ")}`
29
+ cmd = comps.join(" ")
30
+ raise "Fail to run command '#{cmd}'" unless system(cmd)
21
31
  end
22
32
 
23
33
  def git_clone(cmd, options = {})
@@ -1,8 +1,11 @@
1
+ require "parallel"
1
2
  require_relative "base"
2
3
  require_relative "../helper/zip"
3
4
 
4
5
  module PodPrebuild
5
6
  class CacheFetcher < CommandExecutor
7
+ attr_reader :cache_branch
8
+
6
9
  def initialize(options)
7
10
  super(options)
8
11
  @cache_branch = options[:cache_branch]
@@ -10,14 +13,28 @@ module PodPrebuild
10
13
 
11
14
  def run
12
15
  Pod::UI.step("Fetching cache") do
13
- fetch_cache(@config.cache_repo, @cache_branch, @config.cache_path)
16
+ if @config.local_cache?
17
+ print_message_for_local_cache(@config.cache_path)
18
+ else
19
+ fetch_remote_cache(@config.cache_repo, @cache_branch, @config.cache_path)
20
+ end
14
21
  unzip_cache
15
22
  end
16
23
  end
17
24
 
18
25
  private
19
26
 
20
- def fetch_cache(repo, branch, dest_dir)
27
+ def print_message_for_local_cache(cache_dir)
28
+ Pod::UI.puts "You're using local cache at: #{cache_dir}.".yellow
29
+ message = <<~HEREDOC
30
+ To enable remote cache (with a git repo), add the `remote` field to the repo config in the `cache_repo` option.
31
+ For more details, check out this doc:
32
+ https://github.com/grab/cocoapods-binary-cache/blob/master/docs/configure_cocoapods_binary_cache.md#cache_repo-
33
+ HEREDOC
34
+ Pod::UI.puts message
35
+ end
36
+
37
+ def fetch_remote_cache(repo, branch, dest_dir)
21
38
  Pod::UI.puts "Fetching cache from #{repo} (branch: #{branch})".green
22
39
  if Dir.exist?(dest_dir + "/.git")
23
40
  git("fetch origin #{branch}")
@@ -41,7 +58,8 @@ module PodPrebuild
41
58
  @config.manifest_path
42
59
  )
43
60
  end
44
- Dir[@config.generated_frameworks_dir(in_cache: true) + "/*.zip"].each do |path|
61
+ zip_paths = Dir[@config.generated_frameworks_dir(in_cache: true) + "/*.zip"]
62
+ Parallel.each(zip_paths, in_threads: 8) do |path|
45
63
  ZipUtils.unzip(path, to_dir: @config.generated_frameworks_dir)
46
64
  end
47
65
  end
@@ -4,28 +4,30 @@ 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
30
+ installer.repo_update = @repo_update
29
31
  installer.install!
30
32
  end
31
33
  end
@@ -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]
@@ -9,11 +11,25 @@ module PodPrebuild
9
11
 
10
12
  def run
11
13
  Pod::UI.step("Pushing cache") do
12
- commit_message = "Update prebuilt cache".shellescape
13
- git("add .")
14
- git("commit -m '#{commit_message}'")
15
- git("push origin #{@cache_branch}")
14
+ if @config.local_cache?
15
+ print_message_for_local_cache
16
+ else
17
+ commit_and_push_cache
18
+ end
16
19
  end
17
20
  end
21
+
22
+ private
23
+
24
+ def print_message_for_local_cache
25
+ Pod::UI.puts "Skip pushing cache as you're using local cache".yellow
26
+ end
27
+
28
+ def commit_and_push_cache
29
+ commit_message = "Update prebuilt cache"
30
+ git("add .")
31
+ git("commit -m '#{commit_message}'")
32
+ git("push origin #{@cache_branch}")
33
+ end
18
34
  end
19
35
  end
@@ -5,10 +5,14 @@ module Pod
5
5
  class Command
6
6
  class Binary < Command
7
7
  class Prebuild < Binary
8
+ attr_reader :prebuilder
9
+
8
10
  self.arguments = [CLAide::Argument.new("CACHE-BRANCH", false)]
9
11
  def self.options
10
12
  [
11
13
  ["--config", "Config (Debug, Test...) to prebuild"],
14
+ ["--repo-update", "Update pod repo before installing"],
15
+ ["--no-fetch", "Do not perform a cache fetch beforehand"],
12
16
  ["--push", "Push cache to repo upon completion"],
13
17
  ["--all", "Prebuild all binary pods regardless of cache validation"],
14
18
  ["--targets", "Targets to prebuild. Use comma (,) to specify a list of targets"]
@@ -28,6 +32,8 @@ module Pod
28
32
  @prebuilder = PodPrebuild::CachePrebuilder.new(
29
33
  config: prebuild_config,
30
34
  cache_branch: argv.shift_argument || "master",
35
+ repo_update: argv.flag?("repo-update"),
36
+ no_fetch: argv.flag?("fetch") == false,
31
37
  push_cache: argv.flag?("push")
32
38
  )
33
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-binary-cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bang Nguyen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-09 00:00:00.000000000 Z
11
+ date: 2021-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocoapods
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: parallel
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -125,7 +139,6 @@ files:
125
139
  - lib/cocoapods-binary-cache/helper/lockfile.rb
126
140
  - lib/cocoapods-binary-cache/helper/path_utils.rb
127
141
  - lib/cocoapods-binary-cache/helper/podspec.rb
128
- - lib/cocoapods-binary-cache/helper/prebuild_order.rb
129
142
  - lib/cocoapods-binary-cache/hooks/post_install.rb
130
143
  - lib/cocoapods-binary-cache/hooks/pre_install.rb
131
144
  - lib/cocoapods-binary-cache/main.rb
@@ -153,7 +166,6 @@ files:
153
166
  - lib/cocoapods-binary-cache/pod-rome/xcodebuild_raw.rb
154
167
  - lib/cocoapods-binary-cache/prebuild_output/metadata.rb
155
168
  - lib/cocoapods-binary-cache/prebuild_output/output.rb
156
- - lib/cocoapods-binary-cache/scheme_editor.rb
157
169
  - lib/cocoapods-binary-cache/state_store.rb
158
170
  - lib/cocoapods-binary-cache/ui.rb
159
171
  - lib/cocoapods_plugin.rb
@@ -1,12 +0,0 @@
1
- module PodPrebuild
2
- module BuildOrder
3
- def self.order_targets(targets)
4
- # It's more efficient to build frameworks that have more dependencies first
5
- # so that the build parallelism is ultilized
6
- # >> --- MyFramework ----------------------------------|
7
- # >> --- ADependency ---|
8
- # >> --- AnotherADependency ---|
9
- targets.sort_by { |t| -t.recursive_dependent_targets.count }
10
- end
11
- end
12
- end
@@ -1,36 +0,0 @@
1
- # Copyright 2019 Grabtaxi Holdings PTE LTE (GRAB), All rights reserved.
2
- # Use of this source code is governed by an MIT-style license that can be found in the LICENSE file
3
-
4
- require "rexml/document"
5
-
6
- class SchemeEditor
7
- def self.edit_to_support_code_coverage(sandbox)
8
- pod_proj_path = sandbox.project_path
9
- Pod::UI.message "Modify schemes of pod project to support code coverage of prebuilt local pod: #{pod_proj_path}"
10
- scheme_files = Dir["#{pod_proj_path}/**/*.xcscheme"]
11
- scheme_files.each do |file_path|
12
- scheme_name = File.basename(file_path, ".*")
13
- next unless sandbox.local?(scheme_name)
14
-
15
- Pod::UI.message "Modify scheme to enable coverage symbol when prebuild: #{scheme_name}"
16
-
17
- doc = File.open(file_path, "r") { |f| REXML::Document.new(f) }
18
- scheme = doc.elements["Scheme"]
19
- test_action = scheme.elements["TestAction"]
20
- next if test_action.attributes["codeCoverageEnabled"] == "YES"
21
-
22
- test_action.add_attribute("codeCoverageEnabled", "YES")
23
- test_action.add_attribute("onlyGenerateCoverageForSpecifiedTargets", "YES")
24
- coverage_targets = REXML::Element.new("CodeCoverageTargets")
25
- buildable_ref = scheme
26
- .elements["BuildAction"]
27
- .elements["BuildActionEntries"]
28
- .elements["BuildActionEntry"]
29
- .elements["BuildableReference"]
30
- new_buildable_ref = buildable_ref.clone # Need to clone, otherwise the original one will be move to new place
31
- coverage_targets.add_element(new_buildable_ref)
32
- test_action.add_element(coverage_targets)
33
- File.open(file_path, "w") { |f| doc.write(f) }
34
- end
35
- end
36
- end