cocoapods-sled 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 43c917cafb47d678f2239fb021da3f310553b050109042099e7880a7198789d4
4
+ data.tar.gz: 0d4666749551dd568db76273d1d917527c39fcbbc245578cc42809a7713c1e21
5
+ SHA512:
6
+ metadata.gz: 456e1bb2892aae9419d9221a85aab332df74c79966bdfd959a03486f3d6ddc2c1e9cce45eb92333e7f2b2b78e568626fbb805f827d5770976f77d93de414e6b6
7
+ data.tar.gz: bb1213c0390b8b7f04195821b3f96b5ee32f3afe6aaaf654a8948824e3234588dcb4337a7abf5fb9884271f417d26e2050cd557a84839070be741b944b5ddebf
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Cocoapods
4
+ module Sled
5
+ VERSION = "0.1.0"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "sled/version"
4
+
5
+ module Cocoapods
6
+ module Sled
7
+ class Error < StandardError; end
8
+ # Your code goes here...
9
+ end
10
+ end
@@ -0,0 +1,31 @@
1
+ module Pod
2
+ class Command
3
+ class Install < Command
4
+ class Device < Install
5
+ require 'cocoapods-sled/installer_options'
6
+ require 'cocoapods-sled/command/options/sled_options'
7
+
8
+ include SledOptions
9
+
10
+ self.summary = '查找真机二进制缓存'
11
+
12
+ self.description = <<-DESC
13
+ #{self.summary},缓存目录: `#{Config.instance.cache_root + 'Frameworks'}`.
14
+ DESC
15
+
16
+ def initialize(argv)
17
+ super
18
+ end
19
+
20
+ def validate!
21
+ super
22
+ end
23
+
24
+ def run
25
+ Pod::Installer.sled_reuse_type = :device
26
+ super
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ module Pod
2
+ class Command
3
+ class Install < Command
4
+ class Simulator < Install
5
+ require 'cocoapods-sled/installer_options'
6
+
7
+ require 'cocoapods-sled/command/options/sled_options'
8
+
9
+ include SledOptions
10
+
11
+ self.summary = '查找模拟器二进制缓存'
12
+
13
+ self.description = <<-DESC
14
+ #{self.summary},缓存目录: `#{Config.instance.cache_root + 'Frameworks'}`.
15
+ DESC
16
+
17
+ def initialize(argv)
18
+ super
19
+ end
20
+
21
+ def validate!
22
+ super
23
+ end
24
+
25
+ def run
26
+ Pod::Installer.sled_reuse_type = :simulator
27
+ super
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,68 @@
1
+ require 'cocoapods-sled/podfile/dsl_ext'
2
+ require 'cocoapods-sled/framework_cache'
3
+
4
+ module Pod
5
+ class Command
6
+ module Options
7
+ module SledOptions
8
+
9
+ module Options
10
+ def options
11
+ [
12
+ ['--no-binary-pods=name', '禁用指定的 Pod 二进制缓存,多个 Pod 名称用","分隔, 优先级高于 --all-binary'],
13
+ ['--all-binary', '强制使用二进制缓存,忽略 Podfile 中 `:binary` 设置'],
14
+ ['--header-search-path', '生成 Header Search Path,一般用于打包机'],
15
+ ['--project=name', '工程名称,用于生成framework缓存目录,区分多个工程的缓存'],
16
+ ['--no-dev-pod', '关闭 Development Pods 二进制缓存,默认是开启的'],
17
+ ['--force-sync-dev-pod', '强制缓存 Development Pods 编译结果,忽略本地修改检查,默认本地有修改时不缓存,一般用于打包机'],
18
+ ['--inhibit-all-warnings', '强制关闭警告,忽略 Podfile 中的配置,一般用于打包机'],
19
+ ['--cache-limit=num', '指定每个 Pod 缓存存储上限数量,小于 3 无效,一般用于打包机'],
20
+ ['--dep-check=[single|all]', '检查依赖库版本是否发生变更,single:只检查直接依赖,all:检查全部依赖,一般用于打包机'],
21
+ ['--check-xcode-version', '检查xcode版本,不同版本打包不复用,使用 xcodebuild -version 获取版本信息,一般用于打包机'],
22
+ ['--configuration=[Debug|Release|自定义]', '编译配置用于生产缓存路径(Debug、Release、自定义),不传则不区分共用,一般用于打包机']
23
+ ].concat(super)
24
+ end
25
+ end
26
+
27
+ def self.included(base)
28
+ base.extend(Options)
29
+ end
30
+
31
+ def initialize(argv)
32
+ Podfile::DSL.sled_disable_binary_pods = argv.option('no-binary-pods', '').split(',')
33
+ count = argv.option('cache-limit', '').to_i
34
+ if !count.nil? && count >= 3
35
+ FrameworkCache.sled_cache_limit = count
36
+ end
37
+
38
+ check_type = argv.option('dep-check', '').to_sym
39
+ if VALID_DEPENDENCY_CHECK_TYPE.include? check_type
40
+ Podfile::DSL.dependency_check_type = check_type
41
+ end
42
+
43
+ Podfile::DSL.sled_configuration = argv.option('configuration', DEFAULT_CONFIGURATION).to_s
44
+
45
+ Podfile::DSL.sled_project_name = argv.option('project', '')
46
+
47
+ Installer.sled_force_binary = argv.flag?('all-binary', false)
48
+ if argv.flag?('header-search-path', false)
49
+ Podfile::DSL.sled_enable_generate_header_search_paths = true
50
+ end
51
+ if argv.flag?('no-dev-pod', false)
52
+ Podfile::DSL.sled_disable_binary_cache_for_dev_pod = true
53
+ end
54
+ if argv.flag?('force-sync-dev-pod', false)
55
+ Installer.sled_force_rsync_local_pod = true
56
+ end
57
+ if argv.flag?('inhibit-all-warnings', false)
58
+ Podfile::DSL.sled_inhibit_all_warnings = true
59
+ end
60
+ if argv.flag?('check-xcode-version', false)
61
+ Podfile::DSL.sled_check_xcode_version = true
62
+ end
63
+ super
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,2 @@
1
+ require 'cocoapods-sled/command/install/device'
2
+ require 'cocoapods-sled/command/install/simulator'
@@ -0,0 +1,147 @@
1
+ require 'fileutils'
2
+ require 'tmpdir'
3
+
4
+ module Pod
5
+ # The class responsible for managing Pod downloads, transparently caching
6
+ # them in a cache directory.
7
+ #
8
+ class FrameworkCache
9
+
10
+ class_attr_accessor :sled_cache_limit
11
+ self.sled_cache_limit = 4
12
+
13
+ # @return [Pathname] The root directory where this cache store its
14
+ # downloads.
15
+ #
16
+ attr_reader :root
17
+
18
+ # Initialize a new instance
19
+ #
20
+ # @param [Pathname,String] root
21
+ # see {#root}
22
+ #
23
+ def initialize()
24
+ @root = Pathname(Config.instance.cache_root + 'Frameworks')
25
+ end
26
+
27
+ def path_for_framework(slug)
28
+ root + slug
29
+ end
30
+
31
+ def remove_size_exceeded_values(request)
32
+ pod_cache_dir = root + request.sled_cache_subpath
33
+ return unless pod_cache_dir.directory?
34
+
35
+ array = pod_cache_dir.children.select { |pn| pn.directory? }.sort { |a, b| a.mtime <=> b.mtime }
36
+ limit = FrameworkCache.sled_cache_limit
37
+ if array.count > limit # 数量支持配置
38
+ array.take(array.count - limit).each { |pn| `rm -dr #{pn.to_s}` } # 权限问题
39
+ end
40
+ end
41
+
42
+ # @param [Request] request
43
+ # the request to be downloaded.
44
+ #
45
+ # @return [Response] The download response for the given `request` that
46
+ # was found in the download cache.
47
+ #
48
+ def cached_pod(request)
49
+ cached_spec = cached_spec(request)
50
+ path = path_for_pod(request)
51
+
52
+ return unless cached_spec && path.directory?
53
+ spec = request.spec || cached_spec
54
+ Response.new(path, spec, request.params)
55
+ end
56
+
57
+ # Copies the `source` directory to `destination`, cleaning the directory
58
+ # of any files unused by `spec`.
59
+ #
60
+ # @param [Pathname] source
61
+ #
62
+ # @param [Pathname] destination
63
+ #
64
+ # @param [Specification] spec
65
+ #
66
+ # @return [Void]
67
+ #
68
+ def copy_and_clean(source, destination, spec)
69
+ specs_by_platform = group_subspecs_by_platform(spec)
70
+ destination.parent.mkpath
71
+ FileUtils.rm_rf(destination)
72
+ FileUtils.cp_r(source, destination)
73
+ Pod::Installer::PodSourcePreparer.new(spec, destination).prepare!
74
+ Sandbox::PodDirCleaner.new(destination, specs_by_platform).clean!
75
+ end
76
+
77
+ def group_subspecs_by_platform(spec)
78
+ specs_by_platform = {}
79
+ [spec, *spec.recursive_subspecs].each do |ss|
80
+ ss.available_platforms.each do |platform|
81
+ specs_by_platform[platform] ||= []
82
+ specs_by_platform[platform] << ss
83
+ end
84
+ end
85
+ specs_by_platform
86
+ end
87
+
88
+ # Writes the given `spec` to the given `path`.
89
+ #
90
+ # @param [Specification] spec
91
+ # the specification to be written.
92
+ #
93
+ # @param [Pathname] path
94
+ # the path the specification is to be written to.
95
+ #
96
+ # @return [Void]
97
+ #
98
+ def write_spec(spec, path)
99
+ path.dirname.mkpath
100
+ path.open('w') { |f| f.write spec.to_pretty_json }
101
+ end
102
+
103
+ # @return [Hash<String, Hash<Symbol, String>>]
104
+ # A hash whose keys are the pod name
105
+ # And values are a hash with the following keys:
106
+ # :spec_file : path to the spec file
107
+ # :name : name of the pod
108
+ # :version : pod version
109
+ # :release : boolean to tell if that's a release pod
110
+ # :slug : the slug path where the pod cache is located
111
+ #
112
+ def cache_descriptors_per_pod
113
+ specs_dir = root + 'Specs'
114
+ release_specs_dir = specs_dir + 'Release'
115
+ return {} unless specs_dir.exist?
116
+
117
+ spec_paths = specs_dir.find.select { |f| f.fnmatch('*.podspec.json') }
118
+ spec_paths.reduce({}) do |hash, spec_path|
119
+ spec = Specification.from_file(spec_path)
120
+ hash[spec.name] ||= []
121
+ is_release = spec_path.to_s.start_with?(release_specs_dir.to_s)
122
+ request = Downloader::Request.new(:spec => spec, :released => is_release)
123
+ hash[spec.name] << {
124
+ :spec_file => spec_path,
125
+ :name => spec.name,
126
+ :version => spec.version,
127
+ :release => is_release,
128
+ :slug => root + request.slug,
129
+ }
130
+ hash
131
+ end
132
+ end
133
+ end
134
+
135
+ module Downloader
136
+ class Request
137
+ def sled_cache_subpath(name: self.name)
138
+
139
+ if released_pod?
140
+ "Release/#{name}"
141
+ else
142
+ "External/#{name}"
143
+ end
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,7 @@
1
+ module Pod
2
+ module Sled
3
+ # The version of the CocoaPods-sled plug-in.
4
+ #
5
+ VERSION = '0.0.1'.freeze unless defined? Pod::Sled::VERSION
6
+ end
7
+ end
@@ -0,0 +1,49 @@
1
+ require_relative 'tool'
2
+ require_relative 'podfile/dsl_ext'
3
+
4
+ module Pod
5
+ class Installer
6
+
7
+ class_attr_accessor :sled_force_rsync_local_pod
8
+ self.sled_force_rsync_local_pod = false
9
+
10
+ # MARK: force_binary
11
+ class_attr_accessor :sled_force_binary
12
+ self.sled_force_binary = false
13
+
14
+ # MARK: sled_reuse_type
15
+ # @return [Array<Symbol>] known reuse options.
16
+ #
17
+ KNOWN_REUSE_OPTIONS = %i(device simulator).freeze
18
+
19
+ class_attr_accessor :sled_reuse_type
20
+ self.sled_reuse_type = nil
21
+
22
+ def self.sled_should_resure?
23
+ sled_reuse_type && KNOWN_REUSE_OPTIONS.include?(sled_reuse_type)
24
+ end
25
+
26
+ def self.sled_reuse_type_name
27
+ case sled_reuse_type
28
+ when :device then
29
+ "#{Podfile::DSL.sled_configuration}-iphoneos"
30
+ when :simulator then
31
+ "#{Podfile::DSL.sled_configuration}-iphonesimulator"
32
+ else
33
+ "Other"
34
+ end
35
+ end
36
+
37
+ def self.sled_reuse_type_desc
38
+ case sled_reuse_type
39
+ when :device then
40
+ "真机"
41
+ when :simulator then
42
+ "模拟器"
43
+ else
44
+ "Other"
45
+ end
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,257 @@
1
+ require_relative 'framework_cache'
2
+ require_relative 'tool'
3
+ require_relative 'sandbox/path_list_ext'
4
+ require_relative 'podfile/dsl_ext'
5
+ require_relative 'target/pod_target_ext'
6
+
7
+ module Pod
8
+ class Target
9
+
10
+ def sled_sepc_full_name
11
+ name = specs.sort_by(&:name)
12
+ .map { |spec| spec.name.sub("#{root_spec.name}/", "").gsub("/", "-") }
13
+ .join("-") # 区分不同subspec打包的framework
14
+ name = root_spec.name + "-" + name if !name.include?(root_spec.name)
15
+ # File name too long
16
+ if name.length > 50
17
+ name = Digest::MD5.hexdigest(name)
18
+ end
19
+ name
20
+ end
21
+
22
+ # 如果 Podfile 中重写了 build_as_static_framework? build_as_dynamic_framework?,但是没有修改 @build_type
23
+ # verify_no_static_framework_transitive_dependencies 执行时,需要编译的pod库都按照修改前的build_type检查
24
+ # 导致判断有问题报错:动态库不能依赖静态库
25
+ # The 'Pods-xxx' target has transitive dependencies that include statically linked binaries:
26
+ def sled_adjust_build_type
27
+ if build_as_static_framework?
28
+ @build_type = BuildType.static_framework
29
+ elsif build_as_dynamic_framework?
30
+ @build_type = BuildType.dynamic_framework
31
+ end
32
+ end
33
+
34
+ def sled_build_type_name
35
+ "#{build_type.linkage}_#{build_type.packaging}"
36
+ end
37
+
38
+ def sled_framework_cache_subpath(reuse_type_name)
39
+ "#{sled_build_type_name}/#{sled_sepc_full_name}/#{reuse_type_name}"
40
+ end
41
+ end
42
+ end
43
+
44
+ module Pod
45
+ class Installer
46
+ require 'cocoapods-sled/installer_options'
47
+
48
+ SLED_VALID_PLATFORMS = Platform.all.freeze.map { |v| v.name.to_s }
49
+
50
+ def f_cache
51
+ @f_cache ||= FrameworkCache.new
52
+ end
53
+
54
+ old_install_pod_sources = instance_method(:download_dependencies)
55
+ define_method(:download_dependencies) do
56
+ old_install_pod_sources.bind(self).()
57
+
58
+ # Installer.sled_reuse_type = :device
59
+ return unless Installer.sled_should_resure?
60
+
61
+ UI.section "查找#{Installer.sled_reuse_type_desc} Sled 缓存" do
62
+ sled_reuse_action
63
+ end
64
+ end
65
+
66
+ def sled_reuse_action
67
+ cache = []
68
+
69
+ sled_totalTargets = []
70
+ @sled_hits = []
71
+ @sled_miss = []
72
+ disable_binary_pod_targets = []
73
+
74
+ pod_targets.each do |target|
75
+ # 修正build_type
76
+ # target.sled_adjust_build_type
77
+
78
+ disable_binary_pod_targets << target.name if Podfile::DSL.sled_disable_binary_pods.include?(target.root_spec.name)
79
+ next if Podfile::DSL.sled_disable_binary_pods.include?(target.root_spec.name)
80
+
81
+ disable_binary_pod_targets << target.name if target.seld_ignore_binary?
82
+ next if target.seld_ignore_binary?
83
+
84
+ disable_binary_pod_targets << target.name unless Pod::Installer.sled_force_binary || target.sled_enable_binary?
85
+ next unless Pod::Installer.sled_force_binary || target.sled_enable_binary?
86
+
87
+ root_spec = target.root_spec
88
+
89
+
90
+ sled_totalTargets << target.name
91
+
92
+ if target.sled_local?
93
+ return if Podfile::DSL.sled_disable_binary_cache_for_dev_pod
94
+ sled_modify_pod_target(target)
95
+ else
96
+ sled_modify_pod_target(target)
97
+ end
98
+ end
99
+
100
+ UI.puts " -> pod targets数量: #{pod_targets.count}".yellow
101
+ UI.puts " -> binary disabled数量: #{disable_binary_pod_targets.count}".yellow
102
+ disable_binary_pod_targets_text = disable_binary_pod_targets.join(", ")
103
+ UI.puts " #{disable_binary_pod_targets_text}" unless disable_binary_pod_targets_text.empty?
104
+ UI.puts " -> 处理targets数量: #{sled_totalTargets.count}".yellow
105
+ UI.puts " -> 命中数量: #{@sled_hits.count}".yellow
106
+ UI.message " #{@sled_hits.join(", ")}"
107
+ UI.puts " -> 未命中数量: #{@sled_miss.count}".yellow
108
+ sled_miss_text = @sled_miss.join(", ")
109
+ UI.puts " #{sled_miss_text}" unless sled_miss_text.empty?
110
+ end
111
+
112
+ def xcode_version
113
+ @xcode_version ||= `xcodebuild -version | grep "Build version" | awk '{print $NF}' | head -1`.strip
114
+ end
115
+
116
+ def sled_modify_pod_target(target)
117
+ request = target.sled_download_request
118
+ return if request.nil?
119
+
120
+ root_spec = target.root_spec
121
+
122
+ slug = target.sled_slug_current
123
+ if Podfile::DSL.sled_check_xcode_version
124
+ slug = "#{slug}-#{xcode_version}"
125
+ end
126
+ unless Podfile::DSL.sled_project_name.empty?
127
+ slug = "#{slug}-#{Podfile::DSL.sled_project_name}"
128
+ end
129
+
130
+ path = f_cache.path_for_framework(slug)
131
+
132
+ pod_root = sandbox.pod_dir(root_spec.name)
133
+
134
+ framework_dir_path = path + target.sled_framework_cache_subpath(Installer.sled_reuse_type_name)
135
+ framework_file_path = framework_dir_path + target.product_name
136
+
137
+ if framework_file_path.directory?
138
+ path.utime(Time.now, Time.now)
139
+
140
+ @sled_hits << target.name
141
+
142
+ # 1.12.x 相同 pod_root 重用了 path_list,这里会导致同目录下的podspec只能找到一个二进制
143
+ target.file_accessors.map(&:path_list).each do |value|
144
+ value.add_cache_root(framework_dir_path)
145
+ end
146
+
147
+ framework_dir_relative_path = framework_dir_path.relative_path_from(pod_root)
148
+ framework_file_relative_path = framework_file_path.relative_path_from(pod_root)
149
+
150
+ target.specs.each do |spec|
151
+
152
+ sled_empty_source_files(spec)
153
+ sled_add_vendered_framework(spec, framework_file_relative_path.to_s)
154
+ sled_replace_resource_bundles(spec, framework_dir_relative_path.to_s)
155
+ sled_add_header_search_paths(spec, target, framework_file_path.to_s)
156
+ end
157
+ else
158
+ @sled_miss << target.name
159
+ sled_add_script_phases(target, path)
160
+ end
161
+
162
+ f_cache.remove_size_exceeded_values(request)
163
+ end
164
+
165
+ def sled_add_header_search_paths(spec, pod_target, framework_file_path)
166
+ return unless pod_target.sled_enable_generate_header_search_paths?
167
+
168
+ spec.attributes_hash["user_target_xcconfig"] ||= {}
169
+ spec.attributes_hash["user_target_xcconfig"]["HEADER_SEARCH_PATHS"] = "#{framework_file_path}/Headers/"
170
+ # "${PODS_ROOT}/#{target.copy_resources_script_path_for_spec(spec).relative_path_from(target.sandbox.root)}"
171
+ end
172
+
173
+ def sled_replace_resource_bundles(spec, framework_dir_path)
174
+ if spec.attributes_hash["resource_bundles"]
175
+ bundle_names = spec.attributes_hash["resource_bundles"].keys
176
+ spec.attributes_hash["resource_bundles"] = nil
177
+
178
+ spec.attributes_hash["resources"] = Array(spec.attributes_hash["resources"])
179
+ spec.attributes_hash["resources"] += bundle_names.map{ |name| "#{framework_dir_path}/#{name}.bundle" }
180
+ end
181
+ end
182
+
183
+ # TODO: 待完善 参考 add_vendered_framework
184
+ def sled_add_vendered_framework(spec, framework_file_path)
185
+
186
+ spec.attributes_hash["vendored_frameworks"] = Array(spec.attributes_hash["vendored_frameworks"])
187
+ spec.attributes_hash["vendored_frameworks"] += [framework_file_path]
188
+
189
+ # spec.attributes_hash["source_files"] = framework_file_path + '/Headers/*.h'
190
+ # spec.attributes_hash["public_header_files"] = framework_file_path + '/Headers/*.h'
191
+ spec.attributes_hash["subspecs"] = nil
192
+ end
193
+
194
+ # source_files 置空
195
+ def sled_empty_source_files(spec)
196
+ spec.attributes_hash["source_files"] = []
197
+ spec.attributes_hash["public_header_files"] = []
198
+ # VALID_PLATFORMS = Platform.all.freeze
199
+ SLED_VALID_PLATFORMS.each do |plat|
200
+ if spec.attributes_hash[plat] != nil
201
+ spec.attributes_hash[plat]["source_files"] = []
202
+ spec.attributes_hash[plat]["public_header_files"] = []
203
+ end
204
+ end
205
+ end
206
+
207
+ def sled_add_script_phases(pod_target, chche_dir)
208
+
209
+ rsync_func = ""
210
+
211
+ # Local Pod不强制同步时,检查本地代码变更
212
+ if pod_target.sled_local? && !Installer.sled_force_rsync_local_pod
213
+ pod_target.sled_local_pod_paths.each do |path|
214
+ rsync_func << <<-SH.strip_heredoc
215
+ status=`git -C #{path} status -s #{path}`
216
+
217
+ if [[ $status != "" ]]; then
218
+ echo "#{pod_target.name} 有变更,不同步编译结果"
219
+ echo $status
220
+ exit 0
221
+ fi
222
+
223
+ SH
224
+ end
225
+ end
226
+
227
+ rsync_func << "#{Pod::Generator::ScriptPhaseConstants::RSYNC_PROTECT_TMP_FILES}"
228
+ rsync_func << <<-SH.strip_heredoc
229
+
230
+ framework_cache_path="#{chche_dir}/#{pod_target.sled_framework_cache_subpath("${CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}")}"
231
+ common_cache_path="#{chche_dir}/#{pod_target.sled_framework_cache_subpath("#{DEFAULT_CONFIGURATION}${EFFECTIVE_PLATFORM_NAME}")}"
232
+
233
+ echo "mkdir -p ${framework_cache_path}" || true
234
+ mkdir -p ${framework_cache_path}
235
+
236
+ exec_rsync() {
237
+ echo "rsync -rLptgoDv --chmod=a=rwx "${RSYNC_PROTECT_TMP_FILES[@]}" ${CONFIGURATION_BUILD_DIR}/ ${framework_cache_path} &"
238
+
239
+ # TARGET_BUILD_DIR 在打包机上有问题,包含所有Framework,使用CONFIGURATION_BUILD_DIR
240
+ rsync -rLptgoDv --chmod=a=rwx "${RSYNC_PROTECT_TMP_FILES[@]}" "${CONFIGURATION_BUILD_DIR}/" "${framework_cache_path}" >/dev/null 2>>"#{chche_dir}/error.log"
241
+
242
+ ln -sfn "${framework_cache_path}" "${common_cache_path}"
243
+ }
244
+
245
+ (exec_rsync) &
246
+ SH
247
+
248
+ spec = pod_target.specs.first
249
+ value = Array(spec.attributes_hash['script_phases'] || spec.attributes_hash['script_phase'])
250
+ value << {
251
+ :name => "Rsync Framework And Bundle To Sled Cache",
252
+ :script => rsync_func
253
+ }
254
+ spec.attributes_hash["script_phases"] = value
255
+ end
256
+ end
257
+ end
@@ -0,0 +1,62 @@
1
+ require_relative '../tool'
2
+
3
+ VALID_DEPENDENCY_CHECK_TYPE = %i(default single all).freeze
4
+ DEFAULT_CONFIGURATION = "Sled-Common"
5
+
6
+ module Pod
7
+ class Podfile
8
+ module DSL
9
+
10
+ # def sled_enable_binary_cache!
11
+ # DSL.sled_enable_binary_cache = true
12
+ # end
13
+
14
+ def sled_disable_binary_cache_for_dev_pod!
15
+ DSL.sled_disable_binary_cache_for_dev_pod = true
16
+ end
17
+
18
+ def sled_enable_generate_header_search_paths!
19
+ DSL.sled_enable_generate_header_search_paths = true
20
+ end
21
+
22
+ def sled_disable_binary_pods(*names)
23
+ DSL.sled_disable_binary_pods ||= []
24
+ DSL.sled_disable_binary_pods.concat(names)
25
+ end
26
+
27
+ private
28
+ # 开启二进制缓存(默认开启,暂时不支持修改)
29
+ class_attr_accessor :sled_enable_binary_cache
30
+ self.sled_enable_binary_cache = true
31
+
32
+ # 禁用 Development pods 二进制缓存
33
+ class_attr_accessor :sled_disable_binary_cache_for_dev_pod
34
+ self.sled_disable_binary_cache_for_dev_pod = false
35
+
36
+ # 生成 HEADER_SEARCH_PATHS
37
+ class_attr_accessor :sled_enable_generate_header_search_paths
38
+ self.sled_enable_generate_header_search_paths = false
39
+
40
+ class_attr_accessor :sled_inhibit_all_warnings
41
+ self.sled_inhibit_all_warnings = false
42
+
43
+ class_attr_accessor :sled_disable_binary_pods
44
+ self.sled_disable_binary_pods = []
45
+
46
+ class_attr_accessor :dependency_check_type
47
+ self.dependency_check_type = :default
48
+
49
+ # 检查 xcode 版本,使用 xcodebuild -version 获取版本信息 Build version
50
+ class_attr_accessor :sled_check_xcode_version
51
+ self.sled_check_xcode_version = false
52
+
53
+ # 工程名称,用于生成缓存目录,区分多个工程的缓存
54
+ class_attr_accessor :sled_project_name
55
+ self.sled_project_name = ''
56
+
57
+ # 编译配置,用于生成缓存目录,默认不区分不同的编译配置(Debug | Release | 自定义)
58
+ class_attr_accessor :sled_configuration
59
+ self.sled_configuration = DEFAULT_CONFIGURATION
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,74 @@
1
+ module Pod
2
+ class Podfile
3
+ class SLEDPodOptionsItem
4
+
5
+ attr_reader :internal_hash
6
+ attr_reader :key
7
+ attr_reader :default
8
+
9
+ def initialize(key, default)
10
+ @internal_hash = {}
11
+ @key = key
12
+ @default = default
13
+ end
14
+
15
+ def value_for_pod(pod_name)
16
+ value = internal_hash[pod_name] || [default]
17
+ value.map do |v|
18
+ v.nil? ? default : v
19
+ end
20
+ end
21
+
22
+ # def sled_all_vlaue=(flag)
23
+ # internal_hash['all'] = flag
24
+ # end
25
+
26
+ def set_value_for_pod(pod_name, value)
27
+ internal_hash[pod_name] ||= []
28
+ internal_hash[pod_name] << value
29
+ end
30
+
31
+ def parse_options(name, requirements)
32
+ options = requirements.last
33
+ return requirements unless options.is_a?(Hash)
34
+
35
+ should_enable = options.delete(key)
36
+ pod_name = Specification.root_name(name)
37
+ set_value_for_pod(pod_name, should_enable)
38
+
39
+ requirements.pop if options.empty?
40
+ end
41
+ end
42
+
43
+ class TargetDefinition
44
+ def sled_option_binary
45
+ @sled_option_binary = SLEDPodOptionsItem.new(:binary, nil) unless @sled_option_binary
46
+ @sled_option_binary
47
+ end
48
+
49
+ def sled_option_header_search_paths
50
+ @sled_option_header_search_paths = SLEDPodOptionsItem.new(:hsp, nil) unless @sled_option_header_search_paths
51
+ @sled_option_header_search_paths
52
+ end
53
+
54
+ def sled_parse_sled_options(name, requirements)
55
+ sled_option_binary.parse_options(name, requirements)
56
+ sled_option_header_search_paths.parse_options(name, requirements)
57
+ end
58
+
59
+ def sled_inhibit_warnings_if_needed(name, requirements)
60
+ return requirements unless Podfile::DSL.sled_inhibit_all_warnings
61
+ options = requirements.last
62
+ return requirements unless options.is_a?(Hash)
63
+ options[:inhibit_warnings] = true
64
+ end
65
+
66
+ original_parse_inhibit_warnings = instance_method(:parse_inhibit_warnings)
67
+ define_method(:parse_inhibit_warnings) do |name, requirements|
68
+ sled_parse_sled_options(name, requirements)
69
+ sled_inhibit_warnings_if_needed(name, requirements)
70
+ original_parse_inhibit_warnings.bind(self).call(name, requirements)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,55 @@
1
+ require_relative '../tool'
2
+
3
+ module Pod
4
+ class Sandbox
5
+ class PathList
6
+ attr_accessor :sled_framework_cache_roots
7
+
8
+ old_read_file_system = instance_method(:read_file_system)
9
+ define_method(:read_file_system) do
10
+ old_read_file_system.bind(self).()
11
+
12
+ return if sled_framework_cache_roots.nil? || sled_framework_cache_roots.empty?
13
+ sled_framework_cache_roots.each do |root|
14
+ sled_read_framework_file_system(root)
15
+ end
16
+ end
17
+
18
+ def add_cache_root(root)
19
+ @sled_framework_cache_roots ||= []
20
+ @sled_framework_cache_roots << root unless @sled_framework_cache_roots.include?(root)
21
+ end
22
+
23
+ def sled_read_framework_file_system(path)
24
+ unless path.exist?
25
+ # raise Informative, "Attempt to read non existent folder `#{root}`."
26
+ Pod::UI.puts "⚠️⚠️⚠️ Attempt to read non existent folder `#{path}`."
27
+ return
28
+ end
29
+
30
+ prefix = path.relative_path_from(root)
31
+
32
+ dirs = []
33
+ files = []
34
+ root_length = path.cleanpath.to_s.length + File::SEPARATOR.length
35
+ escaped_root = escape_path_for_glob(path)
36
+ Dir.glob(escaped_root + '**/*', File::FNM_DOTMATCH).each do |f|
37
+ directory = File.directory?(f)
38
+ # Ignore `.` and `..` directories
39
+ next if directory && f =~ /\.\.?$/
40
+
41
+ f = f.slice(root_length, f.length - root_length)
42
+ next if f.nil?
43
+
44
+ (directory ? dirs : files) << (prefix + f).to_s
45
+ end
46
+
47
+ dirs.sort_by!(&:upcase)
48
+ files.sort_by!(&:upcase)
49
+
50
+ @dirs = @dirs + dirs
51
+ @files = @files + files
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,164 @@
1
+ require_relative '../podfile/target_definition_ext'
2
+ require 'digest'
3
+
4
+ module Pod
5
+ class PodTarget < Target
6
+
7
+ def sled_enable_generate_header_search_paths?
8
+ return @sled_enable_generate_header_search_paths if defined? @sled_enable_generate_header_search_paths
9
+ whitelists = target_definitions.map do |target_definition|
10
+ target_definition.sled_option_header_search_paths.value_for_pod(root_spec.name)
11
+ end.flatten.uniq.reject { |element| element == nil }
12
+
13
+ if whitelists.empty?
14
+ @sled_enable_generate_header_search_paths = Podfile::DSL.sled_enable_generate_header_search_paths
15
+ elsif whitelists.count == 1
16
+ @sled_enable_generate_header_search_paths = !!whitelists.first
17
+ else
18
+ value = whitelists.first
19
+ tmp_td = target_definitions
20
+ .detect { |obj| obj.sled_option_header_search_paths.value_for_pod(root_spec.name).first == value }
21
+ target_name = tmp_td == nil ? "unknown" : tmp_td.name
22
+ UI.warn "The pod `#{pod_name}` is linked to different targets " \
23
+ "(#{target_definitions.map { |td| "`#{td.name}`" }.to_sentence}), which contain different " \
24
+ 'settings to hsp. CocoaPods does not currently ' \
25
+ 'support different settings and will fall back to your preference ' \
26
+ "set in the `#{target_name}` target definition" \
27
+ " :hsp => #{value}."
28
+ @sled_enable_generate_header_search_paths = !!value
29
+ end
30
+ @sled_enable_generate_header_search_paths
31
+ end
32
+
33
+ def seld_ignore_binary?
34
+ sled_option_binary_value == :ignore
35
+ end
36
+
37
+ def sled_enable_binary?
38
+ sled_option_binary_value == true
39
+ end
40
+
41
+ def sled_option_binary_value
42
+ return @sled_option_binary_value if defined? @sled_option_binary_value
43
+ whitelists = target_definitions.map do |target_definition|
44
+ target_definition.sled_option_binary.value_for_pod(root_spec.name)
45
+ end.flatten.uniq.reject { |element| element == nil }
46
+
47
+ if whitelists.empty?
48
+ @sled_option_binary_value = Podfile::DSL.sled_enable_binary_cache
49
+ elsif whitelists.count == 1
50
+ @sled_option_binary_value = whitelists.first
51
+ else
52
+ value = whitelists.first
53
+ tmp_td = target_definitions
54
+ .detect { |obj| obj.sled_option_binary.value_for_pod(root_spec.name).first == value }
55
+ target_name = tmp_td == nil ? "unknown" : tmp_td.name
56
+ UI.warn "The pod `#{pod_name}` is linked to different targets " \
57
+ "(#{target_definitions.map { |td| "`#{td.name}`" }.to_sentence}), which contain different " \
58
+ "settings to binary. CocoaPods does not currently " \
59
+ 'support different settings and will fall back to your preference ' \
60
+ "set in the `#{target_name}` target definition" \
61
+ " :binary => #{value}."
62
+ @sled_option_binary_value = value
63
+ end
64
+ @sled_option_binary_value
65
+ end
66
+
67
+ def sled_predownloaded?
68
+ sandbox.predownloaded_pods.include?(root_spec.name)
69
+ end
70
+
71
+ def sled_local?
72
+ sandbox.local?(root_spec.name)
73
+ end
74
+
75
+ def sled_released?
76
+ !sled_local? && !sled_predownloaded? && sandbox.specification(root_spec.name) != root_spec
77
+ end
78
+
79
+ def sled_local_pod_paths
80
+ paths = []
81
+ paths =file_accessors.map(&:path_list).map(&:root).uniq if sled_local?
82
+ paths
83
+ end
84
+
85
+ def sled_slug_current
86
+ case Podfile::DSL.dependency_check_type
87
+ when :single
88
+ sled_plain_slug
89
+ when :all
90
+ sled_complex_slug
91
+ else
92
+ sled_slug
93
+ end
94
+ end
95
+
96
+ # 不检查依赖
97
+ def sled_slug
98
+ @sled_slug ||= sled_download_request.slug
99
+ @sled_slug
100
+ end
101
+
102
+ # 检查直接依赖
103
+ def sled_plain_slug
104
+ if dependent_targets.empty?
105
+ @sled_plain_slug ||= sled_slug
106
+ else
107
+ if @sled_plain_slug.nil?
108
+ tmp_slug = dependent_targets.map { |t| t.sled_slug }.join("-")
109
+ @sled_plain_slug = "#{sled_slug}-#{Digest::MD5.hexdigest(tmp_slug)}"
110
+ end
111
+ end
112
+ @sled_plain_slug
113
+ end
114
+
115
+ # 检查全部依赖
116
+ def sled_complex_slug
117
+ if dependent_targets.empty?
118
+ @sled_complex_slug ||= sled_slug
119
+ else
120
+ if @sled_complex_slug.nil?
121
+ tmp_slug = dependent_targets.map { |t| t.sled_complex_slug }.join("-")
122
+ @sled_complex_slug = "#{sled_slug}-#{Digest::MD5.hexdigest(tmp_slug)}"
123
+ end
124
+ end
125
+ @sled_complex_slug
126
+ end
127
+
128
+ def sled_download_request
129
+ if sled_local?
130
+ commit_id = file_accessors
131
+ .map(&:path_list)
132
+ .map(&:root).uniq
133
+ .map do |path|
134
+ `git -C #{path} log -1 --pretty=format:%H #{path} 2>/dev/null`
135
+ end
136
+ .join("")
137
+
138
+ if commit_id.empty?
139
+ request = nil
140
+ else
141
+ params = { :commit => commit_id }
142
+ request = Downloader::Request.new(
143
+ :name => root_spec.name,
144
+ :params => params,
145
+ )
146
+ end
147
+ elsif sandbox.checkout_sources && sandbox.checkout_sources.keys.include?(root_spec.name)
148
+ params = sandbox.checkout_sources[root_spec.name]
149
+
150
+ request = Downloader::Request.new(
151
+ :name => root_spec.name,
152
+ :params => params,
153
+ )
154
+ else
155
+ request = Downloader::Request.new(
156
+ :spec => root_spec,
157
+ :released => sled_released?,
158
+ )
159
+ end
160
+
161
+ request
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,12 @@
1
+ # attr_accessor for class variable.
2
+ # usage:
3
+ #
4
+ # ```
5
+ # class Pod
6
+ # class_attr_accessor :is_prebuild_stage
7
+ # end
8
+ # ```
9
+ #
10
+ def class_attr_accessor(symbol)
11
+ self.class.send(:attr_accessor, symbol)
12
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-sled/gem_version'
@@ -0,0 +1,2 @@
1
+ require 'cocoapods-sled/command'
2
+ require 'cocoapods-sled/integration'
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-sled
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - 赵守文
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: " Cocoapods-sled 是一款轻量级且易于使用的Cocoapods插件,旨在通过二进制化处理提升项目构建速度。它的核心优势在于:\n
42
+ \ \n 1. **编译结果缓存**:利用缓存机制,复用编译结果,避免不必要的重复编译,从而提高开发效率。\n 2. **二进制化处理**:自动将可复用的依赖项转换为二进制格式,提升构建速度。\n
43
+ \ 3. **低接入成本**:易于集成,开发者可以快速将其加入到现有的Xcode项目中,无需复杂的配置和基建即可开始优化构建流程。\n \n Cocoapods-sled
44
+ 致力于成为iOS项目构建优化的首选工具,帮助开发者以更低的成本实现更高效的开发流程。\n"
45
+ email:
46
+ - zsw19911017@163.com
47
+ executables: []
48
+ extensions: []
49
+ extra_rdoc_files: []
50
+ files:
51
+ - lib/cocoapods-sled.rb
52
+ - lib/cocoapods-sled/command.rb
53
+ - lib/cocoapods-sled/command/install/device.rb
54
+ - lib/cocoapods-sled/command/install/simulator.rb
55
+ - lib/cocoapods-sled/command/options/sled_options.rb
56
+ - lib/cocoapods-sled/framework_cache.rb
57
+ - lib/cocoapods-sled/gem_version.rb
58
+ - lib/cocoapods-sled/installer_options.rb
59
+ - lib/cocoapods-sled/integration.rb
60
+ - lib/cocoapods-sled/podfile/dsl_ext.rb
61
+ - lib/cocoapods-sled/podfile/target_definition_ext.rb
62
+ - lib/cocoapods-sled/sandbox/path_list_ext.rb
63
+ - lib/cocoapods-sled/target/pod_target_ext.rb
64
+ - lib/cocoapods-sled/tool.rb
65
+ - lib/cocoapods/sled.rb
66
+ - lib/cocoapods/sled/version.rb
67
+ - lib/cocoapods_plugin.rb
68
+ homepage: https://github.com/git179979506/cocoapods-sled
69
+ licenses:
70
+ - MIT
71
+ metadata:
72
+ homepage_uri: https://github.com/git179979506/cocoapods-sled
73
+ source_code_uri: https://github.com/git179979506/cocoapods-sled
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 2.4.0
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.0.3.1
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Cocoapods-sled:一个轻量级且高效的Cocoapods插件,实现二进制化功能。
93
+ test_files: []