cocoapods-binary-matchup 0.0.17 → 0.0.19

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5b2d7e5383e4069928a8652aef16cd19446482e0149cb36dc4b880f68ffdd11d
4
- data.tar.gz: b76423c11f50d5cba8f78c31c3707707aaf55511ef848225dfff0549ddb7c1c0
3
+ metadata.gz: 07e6a14cf198cebbb76b6976937d49e9c898cc26587581455ead527556e3fa42
4
+ data.tar.gz: 52cde4cb69e7bf2ddccc15f96c16d79a702a9b5f294895161be96a562f255c07
5
5
  SHA512:
6
- metadata.gz: a2f3f6d35e6aa9a410038014c97a5c4fddbac788da44ce2b2fce2fb72d55c04cf910794d5ee7718274f5d6d80ba47095abf870096c22fcda52707be5058d044e
7
- data.tar.gz: fa74552e79a659791add383487f55fad19c492588fc5943f108cfff70fee9a98b1624e209c7bdb2c915b3dc800b8ec16773498a8fabf693f4cf5bef2673ecf13
6
+ metadata.gz: b393ac322ea327f09e914533d846693cc133653e1f0c8267131af131dbeeb52e53c6b8f1ae3ae128eb43ca463d9cde767edf453ca26faea5b785e5cb5ef61d19
7
+ data.tar.gz: 107faf52b261ee0ba0e73d4db661ed4a3d8677f395724b7af37675cc176ade72ff5736492608a61ee79bbfa58b97034082de0425dcdf04dd550adb7b6ab54368
@@ -172,8 +172,7 @@ Pod::HooksManager.register('cocoapods-binary-matchup', :pre_install) do |install
172
172
  Pod::Podfile::DSL.enable_prebuild_patch false
173
173
  Pod::Config.force_disable_write_lockfile false
174
174
  Pod::Installer.disable_install_complete_message false
175
-
176
-
175
+
177
176
  # -- step 2: pod install ---
178
177
  # install
179
178
  Pod::UI.puts "\n"
@@ -183,3 +182,211 @@ Pod::HooksManager.register('cocoapods-binary-matchup', :pre_install) do |install
183
182
  # go on the normal install step ...
184
183
  end
185
184
 
185
+ Pod::HooksManager.register('cocoapods-binary-matchup', :post_install) do |installer_context|
186
+ require_relative 'Integration'
187
+
188
+ # 检查是否是预构建阶段,如果是则跳过
189
+ require_relative 'helper/feature_switches'
190
+ if Pod.is_prebuild_stage
191
+ next
192
+ end
193
+
194
+ Pod::UI.puts "📱 Post-install: Adding prebuilt framework resources to Pods-OMI-resources.sh"
195
+
196
+ # 从ObjectSpace中获取installer实例(类似pre_install hook的做法)
197
+ installer = nil
198
+ include ObjectSpace
199
+ ObjectSpace.each_object(Pod::Installer) { |inst| installer = inst }
200
+
201
+ if installer.nil?
202
+ Pod::UI.puts "⚠️ Could not find installer instance, skipping framework resources processing"
203
+ next
204
+ end
205
+
206
+ # 处理每个aggregate target的资源脚本
207
+ installer.aggregate_targets.each do |aggregate_target|
208
+ if !aggregate_target.static_framework?
209
+ Pod::UI.puts " ⚠️ Skipping static framework: #{aggregate_target.name}"
210
+ next
211
+ end
212
+
213
+ # 手动构建资源脚本路径(CocoaPods没有直接的script_path API)
214
+ target_support_dir = installer.sandbox.target_support_files_dir(aggregate_target.name)
215
+ script_path = target_support_dir + "#{aggregate_target.name}-resources.sh"
216
+
217
+ Pod::UI.puts " 🔍 Checking script path: #{script_path}"
218
+ next unless script_path.exist?
219
+
220
+ Pod::UI.puts " 🔧 Processing #{script_path.basename}"
221
+
222
+ # 收集预编译framework的资源
223
+ framework_resources = collect_prebuilt_framework_resources(installer, aggregate_target)
224
+
225
+ if framework_resources.any?
226
+ # 修改资源脚本
227
+ modify_resources_script(script_path, framework_resources)
228
+ Pod::UI.puts " ✅ Added #{framework_resources.count} framework resources to #{script_path.basename}"
229
+ else
230
+ Pod::UI.puts " ℹ️ No framework resources found for #{aggregate_target.name}"
231
+ end
232
+ end
233
+
234
+ Pod::UI.puts "✅ Framework resources processing completed"
235
+ end
236
+
237
+ # 收集预编译framework中的资源
238
+ def collect_prebuilt_framework_resources(installer, aggregate_target)
239
+ framework_resources = []
240
+
241
+ # 获取预编译的pod列表 - 强制刷新以确保获取最新状态
242
+ prebuilt_pod_names = installer.refresh_prebuild_pod_names!
243
+
244
+ aggregate_target.pod_targets.each do |pod_target|
245
+ next unless prebuilt_pod_names.include?(pod_target.pod_name)
246
+
247
+ Pod::UI.puts " 📱 Scanning prebuilt pod: #{pod_target.pod_name}"
248
+
249
+ # 获取pod目录
250
+ pod_dir = installer.sandbox.pod_dir(pod_target.pod_name)
251
+ next unless pod_dir.exist?
252
+
253
+ # 查找framework目录
254
+ framework_dirs = pod_dir.children.select { |child|
255
+ child.directory? && child.extname == '.framework'
256
+ }
257
+
258
+ framework_dirs.each do |framework_dir|
259
+ framework_name = framework_dir.basename.to_s
260
+ Pod::UI.puts " 🔍 Scanning framework: #{framework_name}"
261
+
262
+ # 扫描framework中的资源
263
+ resources = scan_framework_resources(framework_dir, pod_target.pod_name)
264
+ framework_resources.concat(resources)
265
+ end
266
+ end
267
+
268
+ framework_resources.uniq
269
+ end
270
+
271
+ # 扫描framework中的资源文件
272
+ def scan_framework_resources(framework_dir, pod_name)
273
+ resources = []
274
+ framework_name = framework_dir.basename.to_s
275
+
276
+ Pod::UI.puts " 🎯 Framework path: #{framework_dir}"
277
+ Pod::UI.puts " 🎯 Pod name: #{pod_name}, Framework name: #{framework_name}"
278
+
279
+ # 资源文件类型
280
+ resource_patterns = [
281
+ '*.png', '*.jpg', '*.jpeg', '*.gif', '*.webp', # 图片
282
+ '*.storyboard', '*.xib', # 界面文件
283
+ '*.storyboardc', # 编译后的storyboard
284
+ '*.nib', # 编译后的xib
285
+ '*.bundle', # 资源包
286
+ '*.ttf', '*.otf', # 字体
287
+ '*.mp3', '*.wav', '*.m4a', '*.mp4', '*.mov' # 媒体
288
+ ]
289
+
290
+ # 扫描framework根目录
291
+ resource_patterns.each do |pattern|
292
+ Dir.glob(framework_dir + pattern).each do |resource_path|
293
+ resource_file = Pathname(resource_path)
294
+ # 其他资源使用BUILT_PRODUCTS_DIR/framework路径
295
+ # 例如:${PODS_ROOT}/CocoaDebug/CocoaDebug.framework/App.storyboardc
296
+ resource_entry = "${PODS_ROOT}/#{pod_name}/#{framework_name}/#{resource_file.basename}"
297
+ resources << resource_entry
298
+ Pod::UI.puts " 📄 Found: #{resource_file.basename} -> #{resource_entry}"
299
+ end
300
+ end
301
+
302
+ # 扫描framework/Resources目录
303
+ resources_dir = framework_dir + 'Resources'
304
+ if resources_dir.exist?
305
+ Pod::UI.puts " 📁 Scanning Resources subdirectory"
306
+ resource_patterns.each do |pattern|
307
+ Dir.glob(resources_dir + pattern).each do |resource_path|
308
+ resource_file = Pathname(resource_path)
309
+
310
+ # Resources目录中的资源也使用BUILT_PRODUCTS_DIR路径
311
+ resource_entry = "${PODS_ROOT}/#{pod_name}/#{framework_name}/#{resource_file.basename}"
312
+ resources << resource_entry
313
+
314
+ Pod::UI.puts " 📄 Found in Resources/: #{resource_file.basename} -> #{resource_entry}"
315
+ end
316
+ end
317
+ end
318
+
319
+ Pod::UI.puts " 📊 Total resources found: #{resources.count}"
320
+ resources
321
+ end
322
+
323
+ # 修改resources脚本,添加framework资源
324
+ def modify_resources_script(script_path, framework_resources)
325
+ return if framework_resources.empty?
326
+
327
+ original_content = script_path.read
328
+
329
+ # 检查是否已经添加过framework资源(避免重复)
330
+ if original_content.include?('# Prebuilt Framework Resources')
331
+ Pod::UI.puts " ℹ️ Framework resources already added, skipping"
332
+ return
333
+ end
334
+
335
+ Pod::UI.puts " 📝 Adding #{framework_resources.count} framework resources to script"
336
+ framework_resources.each_with_index do |resource, index|
337
+ Pod::UI.puts " #{index + 1}. #{resource}"
338
+ end
339
+
340
+ # 构建要添加的资源安装代码
341
+ framework_resources_block = build_framework_resources_block(framework_resources)
342
+
343
+ # 在Debug配置块中插入framework资源(而不是脚本末尾)
344
+ debug_pattern = /if \[\[ "\$CONFIGURATION" == "Debug" \]\]; then/
345
+ if original_content.match(debug_pattern)
346
+ # 找到Debug配置块,在其中插入framework资源
347
+ modified_content = original_content.sub(debug_pattern) do |match|
348
+ "#{match}\n#{framework_resources_block}"
349
+ end
350
+ else
351
+ # 如果没有找到Debug配置块,创建一个新的
352
+ framework_resources_with_condition = <<~SCRIPT
353
+ if [[ "$CONFIGURATION" == "Debug" ]]; then
354
+ #{framework_resources_block}
355
+ fi
356
+ SCRIPT
357
+
358
+ # 在脚本末尾(exit 0之前)插入
359
+ if original_content.include?('exit 0')
360
+ modified_content = original_content.sub(/exit 0/, "#{framework_resources_with_condition}\nexit 0")
361
+ else
362
+ modified_content = original_content + "\n#{framework_resources_with_condition}"
363
+ end
364
+ end
365
+
366
+ # 写回修改后的内容
367
+ script_path.write(modified_content)
368
+
369
+ Pod::UI.puts " ✅ Script modified successfully"
370
+
371
+ # 显示修改后脚本的相关部分以便验证
372
+ debug_lines = modified_content.lines.select.with_index do |line, index|
373
+ line.include?('CONFIGURATION') || line.include?('Prebuilt Framework') ||
374
+ (index > 0 && modified_content.lines[index-1].include?('CONFIGURATION'))
375
+ end
376
+ Pod::UI.puts " 📄 Debug configuration block preview:"
377
+ debug_lines.first(5).each { |line| Pod::UI.puts " #{line.chomp}" }
378
+ end
379
+
380
+ # 构建framework资源安装代码块
381
+ def build_framework_resources_block(framework_resources)
382
+ block = " # Prebuilt Framework Resources\n"
383
+ block += " echo \"Installing prebuilt framework resources...\"\n"
384
+
385
+ framework_resources.each do |resource|
386
+ block += " install_resource \"#{resource}\"\n"
387
+ end
388
+
389
+ block += " echo \"Prebuilt framework resources installation completed\"\n"
390
+
391
+ return block
392
+ end
@@ -1,3 +1,3 @@
1
1
  module CocoapodsBinary
2
- VERSION = "0.0.17"
2
+ VERSION = "0.0.19"
3
3
  end
@@ -123,10 +123,99 @@ def build_for_iosish_platform(sandbox,
123
123
 
124
124
  # output
125
125
  output_path.mkpath unless output_path.exist?
126
+
127
+ if target.static_framework?
128
+ # 🔑 添加资源处理 - 修复静态库资源丢失问题
129
+ copy_resources_to_framework(sandbox, target, device_framework_path)
130
+ end
131
+
126
132
  FileUtils.mv device_framework_path, output_path, :force => true
127
133
 
128
134
  end
129
135
 
136
+ # 新增函数:拷贝资源文件到 framework
137
+ def copy_resources_to_framework(sandbox, target, framework_path)
138
+ Pod::UI.puts "📋 Processing resources for #{target.name}..."
139
+
140
+ pod_dir = Pathname.new(sandbox.pod_dir(target.pod_name))
141
+ framework_dir = Pathname.new(framework_path)
142
+
143
+ # 直接递归扫描 pod 目录下的所有资源文件,拷贝到 framework 根目录
144
+ scan_and_copy_resources_flat(pod_dir, framework_dir)
145
+
146
+ Pod::UI.puts "✅ Resource processing completed for #{target.name}"
147
+ end
148
+
149
+ # 递归扫描资源文件并平铺拷贝到目标目录
150
+ def scan_and_copy_resources_flat(source_dir, target_dir)
151
+ # 确保参数是Pathname类型
152
+ source_dir = Pathname.new(source_dir) unless source_dir.is_a?(Pathname)
153
+ target_dir = Pathname.new(target_dir) unless target_dir.is_a?(Pathname)
154
+
155
+ Pod::UI.puts "📁 Recursively scanning directory: #{source_dir}"
156
+
157
+ # 资源文件扩展名
158
+ resource_extensions = [
159
+ '.png', '.jpg', '.jpeg', '.gif', '.webp', '.svg', # 图片
160
+ '.storyboard', '.xib', '.storyboardc', '.nib', # 界面文件
161
+ '.ttf', '.otf', '.woff', '.woff2', # 字体
162
+ '.mp3', '.wav', '.m4a', '.mp4', '.mov', '.avi', # 媒体
163
+ '.json', '.plist', '.strings', '.xcassets', # 配置文件
164
+ 'metallib' # metal or opengl文件
165
+ ]
166
+
167
+ # 特殊处理的目录类型(这些需要完整保留)
168
+ special_directory_extensions = ['.bundle', '.xcassets', '.lproj']
169
+
170
+ # 递归查找并拷贝资源文件,传递原始根目录用于路径计算
171
+ find_and_copy_resources_recursively(source_dir, target_dir, source_dir, resource_extensions, special_directory_extensions)
172
+ end
173
+
174
+ # 递归查找资源文件并拷贝
175
+ def find_and_copy_resources_recursively(current_dir, target_dir, source_root_dir, resource_extensions, special_extensions)
176
+ # 确保所有参数都是Pathname类型
177
+ current_dir = Pathname.new(current_dir) unless current_dir.is_a?(Pathname)
178
+ target_dir = Pathname.new(target_dir) unless target_dir.is_a?(Pathname)
179
+ source_root_dir = Pathname.new(source_root_dir) unless source_root_dir.is_a?(Pathname)
180
+
181
+ return unless current_dir.exist? && current_dir.directory?
182
+
183
+ current_dir.children.each do |child|
184
+ # 跳过隐藏文件和系统目录
185
+ next if child.basename.to_s.start_with?('.')
186
+ next if ['.git', '.svn', 'node_modules', '.DS_Store'].include?(child.basename.to_s)
187
+
188
+ if child.directory?
189
+ # 检查是否是特殊资源目录(需要完整保留的)
190
+ if special_extensions.include?(child.extname)
191
+ Pod::UI.puts " 📦 Copying special directory: #{child.basename}"
192
+ target_path = target_dir + child.basename
193
+ FileUtils.cp_r(child.to_s, target_path.to_s, :remove_destination => true)
194
+ else
195
+ # 递归处理普通目录
196
+ find_and_copy_resources_recursively(child, target_dir, source_root_dir, resource_extensions, special_extensions)
197
+ end
198
+ else
199
+ # 检查是否是资源文件
200
+ if resource_extensions.include?(child.extname.downcase)
201
+ Pod::UI.puts " 📄 Copying resource file: #{child.basename}"
202
+ target_path = target_dir + child.basename
203
+
204
+ # 处理文件名冲突(如果有重名文件,添加路径前缀)
205
+ if target_path.exist?
206
+ # 计算相对于根目录的路径作为前缀
207
+ relative_dir = child.dirname.relative_path_from(source_root_dir)
208
+ safe_name = "#{relative_dir.to_s.gsub('/', '_')}_#{child.basename}"
209
+ target_path = target_dir + safe_name
210
+ Pod::UI.puts " ⚠️ File name conflict, renamed to: #{safe_name}"
211
+ end
212
+
213
+ FileUtils.cp(child.to_s, target_path.to_s)
214
+ end
215
+ end
216
+ end
217
+ end
218
+
130
219
  def xcodebuild(sandbox, target, sdk='macosx', deployment_target=nil, other_options=[])
131
220
  args = %W(-project #{sandbox.project_path.realdirpath} -scheme #{target} -configuration #{CONFIGURATION} -sdk #{sdk} )
132
221
  platform = PLATFORMS[sdk]
@@ -156,8 +245,6 @@ def xcodebuild(sandbox, target, sdk='macosx', deployment_target=nil, other_optio
156
245
  [is_succeed, log]
157
246
  end
158
247
 
159
-
160
-
161
248
  module Pod
162
249
  class Prebuild
163
250
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-binary-matchup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.17
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - leavez