cocoapods-bb-PodAssistant 0.3.18.0 → 0.3.18.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 +4 -4
- data/lib/cocoapods-bb-PodAssistant/babybus/installer/post_install_hooks.rb +419 -185
- data/lib/cocoapods-bb-PodAssistant/babybus/installer/post_integrate_hooks.rb +9 -0
- data/lib/cocoapods-bb-PodAssistant/gem_version.rb +1 -1
- data/lib/cocoapods-bb-PodAssistant/helpers/build_environment.rb +69 -0
- data/lib/cocoapods-bb-PodAssistant/helpers/molinillo_performance_patch.rb +89 -0
- data/lib/cocoapods-bb-PodAssistant/helpers/pod_performance_profiler.rb +372 -0
- data/lib/cocoapods-bb-PodAssistant/security/security_hardening.rb +31 -77
- data/lib/cocoapods_plugin.rb +10 -0
- metadata +4 -1
|
@@ -7,61 +7,140 @@ require 'cocoapods-bb-PodAssistant/babybus/business/babybus_install_environment'
|
|
|
7
7
|
require 'cocoapods-bb-PodAssistant/helpers/pod_utils'
|
|
8
8
|
require 'fileutils'
|
|
9
9
|
require 'cocoapods-bb-PodAssistant/security/security_hardening'
|
|
10
|
+
require 'cocoapods-bb-PodAssistant/helpers/build_environment'
|
|
10
11
|
|
|
11
12
|
class PodPostInstaller
|
|
12
|
-
#
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
|
|
13
|
+
# 性能优先组件
|
|
14
|
+
PERFORMANCE_PRIORITY_TARGETS = %w[
|
|
15
|
+
cocos2dx
|
|
16
|
+
UnityFramework
|
|
17
|
+
BBUnityFramework
|
|
18
|
+
].freeze
|
|
19
|
+
# # 安装 Pod Hook
|
|
20
|
+
# # 参数说明
|
|
21
|
+
# # lib 组件库
|
|
22
|
+
# # deployment_target 工程最低支持系统版本,nil 时自动判断
|
|
23
|
+
# # excluded_targets 过滤工程target,多个使用[]
|
|
24
|
+
# # is_matrix 是否矩阵产品,默认true,debug场景会进行配置替换操作
|
|
25
|
+
# # is_replaceMinVersionForMultiTarget 多target产品,是否需要替换最低版本支持,默认false
|
|
26
|
+
# # omvll_whitelist 加固白名单,只有添加白名单组件才会进行加固
|
|
27
|
+
# def initialize(lib, deployment_target=nil, excluded_targets=["test"], is_matrix=true, is_replaceMinVersionForMultiTarget=false, omvll_whitelist=[])
|
|
28
|
+
# # 旧接口废弃
|
|
29
|
+
# @lib = lib
|
|
30
|
+
# @deployment_target = deployment_target || default_deployment_target
|
|
31
|
+
# @excluded_targets = Array(excluded_targets || [])
|
|
32
|
+
# @is_matrix = is_matrix
|
|
33
|
+
# @is_replaceMinVersionForMultiTarget = is_replaceMinVersionForMultiTarget
|
|
34
|
+
# @omvll_whitelist = Array(omvll_whitelist || [])
|
|
35
|
+
# end
|
|
36
|
+
|
|
37
|
+
# # (新初始化接口) 安装 Pod Hook
|
|
38
|
+
# # 参数说明
|
|
39
|
+
# # lib 组件库
|
|
40
|
+
# # deployment_target 工程最低支持系统版本,nil 时自动判断
|
|
41
|
+
# # excluded_targets 过滤工程target,多个使用[]
|
|
42
|
+
# # omvll_whitelist 加固白名单,只有添加白名单组件才会进行加固
|
|
43
|
+
# def initialize(lib, deployment_target, excluded_targets: [], omvll_whitelist: [])
|
|
44
|
+
# @lib = lib
|
|
45
|
+
# @deployment_target = deployment_target || default_deployment_target
|
|
46
|
+
# @excluded_targets = Array(excluded_targets || [])
|
|
47
|
+
# @omvll_whitelist = Array(omvll_whitelist || [])
|
|
48
|
+
# # 构建策略由环境变量统一管理
|
|
49
|
+
# @is_matrix = BB::BuildEnvironment.matrix?
|
|
50
|
+
# @is_replaceMinVersionForMultiTarget = BB::BuildEnvironment.replace_min_version_for_multi_target?
|
|
51
|
+
# @unity_simulator_supported = BB::BuildEnvironment.unity_simulator_supported?
|
|
52
|
+
# @enable_security_hardening = BB::BuildEnvironment.security_hardening_enabled?
|
|
53
|
+
# @enable_omvll = BB::BuildEnvironment.hardening_omvll_enabled?
|
|
54
|
+
# BB::BuildEnvironment.print_configuration
|
|
55
|
+
# end
|
|
56
|
+
|
|
57
|
+
# 安装 Pod Hook,兼容新旧初始化接口
|
|
58
|
+
#
|
|
59
|
+
# @param lib CocoaPods Installer
|
|
60
|
+
# @param deployment_target 工程最低支持系统版本,nil 时自动判断
|
|
61
|
+
# @param legacy_args 兼容旧版位置参数,依次为:
|
|
62
|
+
# excluded_targets
|
|
63
|
+
# is_matrix
|
|
64
|
+
# is_replaceMinVersionForMultiTarget
|
|
65
|
+
# omvll_whitelist
|
|
66
|
+
# @param excluded_targets 排除的Target名称,多个使用[]
|
|
67
|
+
# @param omvll_whitelist O-MVLL加固白名单,请使用target名称,多个使用[]
|
|
68
|
+
def initialize(lib, deployment_target = nil, *legacy_args, excluded_targets: nil, omvll_whitelist: nil)
|
|
69
|
+
# 兼容旧版本位置参数
|
|
70
|
+
if legacy_args.length > 4
|
|
71
|
+
raise ArgumentError, 'Too many legacy arguments'
|
|
72
|
+
end
|
|
21
73
|
@lib = lib
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
else
|
|
33
|
-
@deployment_target = deployment_target
|
|
74
|
+
# 最低系统版本
|
|
75
|
+
@deployment_target = deployment_target || default_deployment_target
|
|
76
|
+
# 解析旧版位置参数
|
|
77
|
+
legacy_excluded_targets,
|
|
78
|
+
legacy_is_matrix,
|
|
79
|
+
legacy_replace_min_version,
|
|
80
|
+
legacy_omvll_whitelist = legacy_args
|
|
81
|
+
# 校验新旧参数是否冲突
|
|
82
|
+
if legacy_args.length >= 1 && !excluded_targets.nil?
|
|
83
|
+
raise ArgumentError, '[PodPostInstaller] Duplicate excluded_targets arguments'
|
|
34
84
|
end
|
|
35
|
-
if
|
|
36
|
-
|
|
37
|
-
elsif filter_targets.is_a? String
|
|
38
|
-
@filter_targets = [filter_targets] # 过滤target
|
|
85
|
+
if legacy_args.length >= 4 && !omvll_whitelist.nil?
|
|
86
|
+
raise ArgumentError,'[PodPostInstaller] Duplicate omvll_whitelist arguments'
|
|
39
87
|
end
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
88
|
+
# 旧版 API 使用提醒
|
|
89
|
+
unless legacy_args.empty?
|
|
90
|
+
puts '[PodPostInstaller] Legacy API is deprecated, please use keyword arguments => PodPostInstaller.new(lib, $deploymentTarget, excluded_targets: [], omvll_whitelist: [])'.yellow
|
|
91
|
+
end
|
|
92
|
+
# Target 过滤配置
|
|
93
|
+
@excluded_targets = Array(
|
|
94
|
+
excluded_targets || legacy_excluded_targets || ['test']
|
|
95
|
+
)
|
|
96
|
+
# O-MVLL 白名单
|
|
97
|
+
@omvll_whitelist = Array(
|
|
98
|
+
omvll_whitelist || legacy_omvll_whitelist || []
|
|
99
|
+
)
|
|
100
|
+
# 是否矩阵产品
|
|
101
|
+
@is_matrix = if legacy_is_matrix.nil?
|
|
102
|
+
BB::BuildEnvironment.matrix?
|
|
46
103
|
else
|
|
47
|
-
|
|
104
|
+
legacy_is_matrix
|
|
48
105
|
end
|
|
49
|
-
#
|
|
50
|
-
@
|
|
51
|
-
|
|
52
|
-
puts "当前工程开启Xcode编译加固功能".yellow
|
|
106
|
+
# 是否统一替换多 Target 最低系统版本
|
|
107
|
+
@is_replaceMinVersionForMultiTarget = if legacy_replace_min_version.nil?
|
|
108
|
+
BB::BuildEnvironment.replace_min_version_for_multi_target?
|
|
53
109
|
else
|
|
54
|
-
|
|
110
|
+
legacy_replace_min_version
|
|
55
111
|
end
|
|
56
|
-
#
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
112
|
+
# 构建策略由环境变量统一管理
|
|
113
|
+
@unity_simulator_supported = BB::BuildEnvironment.unity_simulator_supported?
|
|
114
|
+
@enable_security_hardening = BB::BuildEnvironment.security_hardening_enabled?
|
|
115
|
+
@enable_omvll = BB::BuildEnvironment.hardening_omvll_enabled?
|
|
116
|
+
print_configuration
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
private def print_configuration
|
|
120
|
+
puts '[PodPostInstaller] ================================='
|
|
121
|
+
puts "Deployment Target : #{@deployment_target}"
|
|
122
|
+
puts "Excluded Targets : #{@excluded_targets.inspect}"
|
|
123
|
+
puts "Matrix Product : #{@is_matrix}"
|
|
124
|
+
puts "Replace Min Version : #{@is_replaceMinVersionForMultiTarget}"
|
|
125
|
+
puts "Unity Simulator : #{@unity_simulator_supported}"
|
|
126
|
+
puts "Security Hardening : #{@enable_security_hardening}"
|
|
127
|
+
puts "O-MVLL Enabled : #{@enable_omvll}"
|
|
128
|
+
puts "O-MVLL Whitelist : #{@omvll_whitelist.inspect}"
|
|
129
|
+
puts '[PodPostInstaller] ================================='
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
private def default_deployment_target
|
|
133
|
+
if BB::PodUtils.above_xcode_27_version
|
|
134
|
+
'15.0' # iOS27最低支持15系统
|
|
135
|
+
elsif BB::PodUtils.above_xcode_16_version
|
|
136
|
+
'13.0' # iOS18最低支持13系统
|
|
137
|
+
else
|
|
138
|
+
isUnity3DApp ? '12.0' : '11.0' # Unity2022引擎最低支持iOS12.0、unity2d iOS11 、cocos iOS10、超A产品 iOS11 (968广告厂商升级最低支持iOS11)
|
|
61
139
|
end
|
|
62
140
|
end
|
|
141
|
+
|
|
63
142
|
private def filterTargetName(target_name)
|
|
64
|
-
for name in @
|
|
143
|
+
for name in @excluded_targets
|
|
65
144
|
if target_name.include?(name)
|
|
66
145
|
return true
|
|
67
146
|
end
|
|
@@ -121,10 +200,19 @@ install_framework()
|
|
|
121
200
|
return 1
|
|
122
201
|
fi
|
|
123
202
|
SH
|
|
124
|
-
flag = content.include?(old_code)
|
|
125
|
-
next unless content.include?(old_code)
|
|
203
|
+
# flag = content.include?(old_code)
|
|
204
|
+
# next unless content.include?(old_code)
|
|
205
|
+
if content.include?(new_code)
|
|
206
|
+
puts "[Skipped] Framework script already patched: #{script_path}"
|
|
207
|
+
next
|
|
208
|
+
end
|
|
209
|
+
unless content.include?(old_code)
|
|
210
|
+
puts "[Warning] Framework script template not matched: #{script_path}"
|
|
211
|
+
next
|
|
212
|
+
end
|
|
126
213
|
updated = content.sub(old_code, new_code)
|
|
127
214
|
File.write(script_path, updated) if updated != content
|
|
215
|
+
puts "[Updated] Framework script: #{script_path}"
|
|
128
216
|
end
|
|
129
217
|
end
|
|
130
218
|
|
|
@@ -190,31 +278,42 @@ install_framework()
|
|
|
190
278
|
end
|
|
191
279
|
|
|
192
280
|
private def generate_other_ldflags()
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
281
|
+
new_flags = [
|
|
282
|
+
'$(inherited)',
|
|
283
|
+
'-ObjC',
|
|
284
|
+
'-lxml2',
|
|
285
|
+
'-lz',
|
|
286
|
+
'-lc++',
|
|
287
|
+
'-weak_framework',
|
|
288
|
+
'SwiftUI'
|
|
289
|
+
]
|
|
290
|
+
if BB::PodUtils.above_xcode_26_version
|
|
198
291
|
# -Wl、-Xlinker使用一样
|
|
199
292
|
# 从 Xcode 15.3 起,Apple 已正式废弃 ld-classic,而 Xcode 26 beta 默认强制使用新版链接器(ld64 764.0+)。
|
|
200
293
|
# xcode26 废弃ld_classic
|
|
201
294
|
# https://developer.apple.com/forums/thread/788064 -Xlinker -dead_strip -Xlinker -allow_dead_duplicates
|
|
202
|
-
new_flags << '-Xlinker' << '-dead_strip'
|
|
203
|
-
|
|
295
|
+
new_flags << '-Xlinker' << '-dead_strip'
|
|
296
|
+
new_flags << '-Xlinker' << '-allow_dead_duplicates'
|
|
297
|
+
elsif BB::PodUtils.compare_xcode_15_version # iOS17适配添加ld64 https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes
|
|
204
298
|
# c++ weak 标识 xcode15 -ld64 is deprecated, use -ld_classic instead
|
|
205
|
-
new_flags << '-Wl,-v'
|
|
299
|
+
new_flags << '-Wl,-v'
|
|
300
|
+
new_flags << '-Wl,-no_deduplicate'
|
|
301
|
+
new_flags << '-Wl,-ld_classic'
|
|
206
302
|
else
|
|
207
303
|
new_flags << '-Wl,-ld64'
|
|
208
304
|
end
|
|
209
305
|
# 去重并规范化输出
|
|
210
306
|
# new_flags.uniq.join(' ') #xcode26就是有多个Xlinker,故不能去重
|
|
307
|
+
new_flags
|
|
211
308
|
end
|
|
212
309
|
|
|
213
310
|
private def fix_above_xcode27_excluded_archs(config)
|
|
214
311
|
key = 'EXCLUDED_ARCHS[sdk=iphonesimulator*]'
|
|
215
312
|
excluded_archs = config.build_settings[key]
|
|
216
313
|
return if excluded_archs.nil?
|
|
217
|
-
archs = excluded_archs
|
|
314
|
+
archs = Array(excluded_archs)
|
|
315
|
+
.flat_map { |value| value.to_s.split }
|
|
316
|
+
.reject { |arch| arch == 'arm64' }
|
|
218
317
|
if archs.empty?
|
|
219
318
|
config.build_settings.delete(key)
|
|
220
319
|
else
|
|
@@ -223,178 +322,313 @@ install_framework()
|
|
|
223
322
|
end
|
|
224
323
|
|
|
225
324
|
private def config_unity_simulator_supported(config)
|
|
226
|
-
|
|
227
|
-
definitions =
|
|
228
|
-
|
|
229
|
-
|
|
325
|
+
key = 'GCC_PREPROCESSOR_DEFINITIONS'
|
|
326
|
+
definitions = Array(
|
|
327
|
+
config.build_settings[key] || ['$(inherited)']
|
|
328
|
+
).dup
|
|
329
|
+
definitions.reject! do |definition|
|
|
330
|
+
definition.to_s.match?(
|
|
331
|
+
/\ABB_UNITY_SIMULATOR_SUPPORTED(?:=|$)/
|
|
332
|
+
)
|
|
333
|
+
end
|
|
334
|
+
unity_flag = 'BB_UNITY_SIMULATOR_SUPPORTED=1'
|
|
335
|
+
if @unity_simulator_supported
|
|
336
|
+
definitions << unity_flag unless definitions.include?(unity_flag)
|
|
337
|
+
end
|
|
338
|
+
config.build_settings[key] = definitions
|
|
230
339
|
end
|
|
231
340
|
|
|
232
|
-
def
|
|
341
|
+
private def capture_user_project_snapshots
|
|
342
|
+
user_projects.to_h do |project|
|
|
343
|
+
[project.path.to_s, Marshal.load(Marshal.dump(project.to_hash))]
|
|
344
|
+
end
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
private def save_user_projects(snapshots)
|
|
348
|
+
user_projects.each do |project|
|
|
349
|
+
before = snapshots.fetch(project.path.to_s)
|
|
350
|
+
after = project.to_hash
|
|
351
|
+
# Compare structural values, not Marshal bytes (hash order and object sharing may differ).
|
|
352
|
+
if before == after
|
|
353
|
+
puts "[PodPostInstaller] Skipped unchanged project: #{project.path}"
|
|
354
|
+
next
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
# Compare with the persisted project as well, using Xcodeproj's normalized representation.
|
|
358
|
+
persisted = Xcodeproj::Project.open(project.path).to_hash
|
|
359
|
+
if persisted == after
|
|
360
|
+
puts "[PodPostInstaller] Skipped already persisted project: #{project.path}"
|
|
361
|
+
next
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
# Log actual changed build settings to identify non-idempotent configuration.
|
|
365
|
+
before_objects = before.fetch('objects', {})
|
|
366
|
+
after.fetch('objects', {}).each do |uuid, object|
|
|
367
|
+
next unless object['isa'] == 'XCBuildConfiguration'
|
|
368
|
+
old_settings = before_objects.fetch(uuid, {}).fetch('buildSettings', {})
|
|
369
|
+
new_settings = object.fetch('buildSettings', {})
|
|
370
|
+
(old_settings.keys | new_settings.keys).sort.each do |key|
|
|
371
|
+
next if old_settings[key] == new_settings[key]
|
|
372
|
+
# puts "[PodPostInstaller] Changed #{object['name']} (#{uuid}): #{key}: #{old_settings[key].inspect} => #{new_settings[key].inspect}"
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
project.save
|
|
376
|
+
puts "[PodPostInstaller] Saved changed project: #{project.path}"
|
|
377
|
+
end
|
|
378
|
+
end
|
|
379
|
+
|
|
380
|
+
# 获取业务工程
|
|
381
|
+
private def user_projects
|
|
382
|
+
@lib.aggregate_targets
|
|
383
|
+
.map(&:user_project)
|
|
384
|
+
.compact
|
|
385
|
+
.uniq
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
# 获取 CocoaPods 工程,兼容单工程和多工程模式
|
|
389
|
+
private def pod_projects
|
|
390
|
+
(
|
|
391
|
+
[@lib.pods_project] +
|
|
392
|
+
Array(@lib.pod_target_subprojects)
|
|
393
|
+
).compact.uniq
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
# 获取全部工程
|
|
397
|
+
private def all_projects
|
|
398
|
+
(user_projects + pod_projects).uniq
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
# 矩阵产品 Debug 环境资源配置
|
|
402
|
+
private def matrix_debug_configure()
|
|
233
403
|
env = BabybusInstallEnv.new()
|
|
234
|
-
is_above_xcode27 = BB::PodUtils.above_xcode_27_version # 高于27
|
|
235
|
-
is_above_xcode26 = BB::PodUtils.above_xcode_26_version # 高于26
|
|
236
|
-
# is_above_xcode15 = BB::PodUtils.compare_xcode_15_version # 高于15
|
|
237
|
-
# is_below_xcode15 = BB::PodUtils.below_xcode_15_version # 低于15
|
|
238
|
-
# 修正Pods-XXX-frameworks.sh脚本framework拷贝文件报错问题,xcframework缺少模拟器架构导致编译报错
|
|
239
|
-
fix_pods_frameworks()
|
|
240
404
|
# 是否Untify项目
|
|
241
405
|
isUnityProject = isUnityApp
|
|
242
406
|
# Untify项目需要移除cocos项目res/src目录
|
|
243
407
|
if (isUnityProject) then
|
|
244
408
|
env.createCocosResource
|
|
245
409
|
end
|
|
410
|
+
env.copyPlistMacro # 开发自行打开不能提交到版本控制,避免test包出现配置不正确情况 by hm 22/5/17
|
|
411
|
+
env.copyUnityFramework if isUnityProject
|
|
412
|
+
env.copyCocosPackage
|
|
413
|
+
end
|
|
414
|
+
|
|
415
|
+
private def configure_build_phases(target)
|
|
416
|
+
return unless target.respond_to?(:shell_script_build_phases)
|
|
417
|
+
target.shell_script_build_phases.each do |phase|
|
|
418
|
+
next unless [
|
|
419
|
+
'[CP] Copy XCFrameworks',
|
|
420
|
+
'Create Symlinks to Header Folders'
|
|
421
|
+
].include?(phase.name)
|
|
422
|
+
phase.always_out_of_date = '1'
|
|
423
|
+
end
|
|
424
|
+
end
|
|
425
|
+
|
|
426
|
+
private def configure_pod_deployment_target(config)
|
|
427
|
+
key = 'IPHONEOS_DEPLOYMENT_TARGET'
|
|
428
|
+
current = config.build_settings[key].to_s
|
|
429
|
+
required = @deployment_target.to_s
|
|
430
|
+
if current.empty?
|
|
431
|
+
config.build_settings[key] = required
|
|
432
|
+
return
|
|
433
|
+
end
|
|
434
|
+
# 只提高,不降低
|
|
435
|
+
return unless current.match?(/\A\d+(?:\.\d+)*\z/)
|
|
436
|
+
current_version = Gem::Version.new(current)
|
|
437
|
+
required_version = Gem::Version.new(required)
|
|
438
|
+
if current_version < required_version
|
|
439
|
+
config.build_settings[key] = required
|
|
440
|
+
end
|
|
441
|
+
end
|
|
442
|
+
|
|
443
|
+
private def configure_swift_compilation_conditions(config, enabled)
|
|
444
|
+
key = 'SWIFT_ACTIVE_COMPILATION_CONDITIONS'
|
|
445
|
+
conditions = Array(
|
|
446
|
+
config.build_settings[key] || '$(inherited)'
|
|
447
|
+
).flat_map { |value| value.to_s.split }
|
|
448
|
+
conditions.delete('USING_XCODE_26')
|
|
449
|
+
conditions << 'USING_XCODE_26' if enabled
|
|
450
|
+
config.build_settings[key] = conditions.uniq.join(' ')
|
|
451
|
+
end
|
|
452
|
+
|
|
453
|
+
private def configure_compiler_optimization(config, is_debug, performance_priority: false)
|
|
454
|
+
settings = config.build_settings
|
|
455
|
+
# 禁用 Bitcode
|
|
456
|
+
settings['ENABLE_BITCODE'] = 'NO'
|
|
457
|
+
if is_debug
|
|
458
|
+
# Debug:调试效率优先
|
|
459
|
+
settings['SWIFT_COMPILATION_MODE'] = 'incremental'
|
|
460
|
+
settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone'
|
|
461
|
+
settings['GCC_OPTIMIZATION_LEVEL'] = '0'
|
|
462
|
+
else
|
|
463
|
+
# Release:全模块编译
|
|
464
|
+
settings['SWIFT_COMPILATION_MODE'] = 'wholemodule'
|
|
465
|
+
if performance_priority
|
|
466
|
+
# 运行性能优先
|
|
467
|
+
settings['SWIFT_OPTIMIZATION_LEVEL'] = '-O'
|
|
468
|
+
settings['GCC_OPTIMIZATION_LEVEL'] = '2'
|
|
469
|
+
else
|
|
470
|
+
# 产物体积优先
|
|
471
|
+
settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Osize'
|
|
472
|
+
settings['GCC_OPTIMIZATION_LEVEL'] = 'z'
|
|
473
|
+
end
|
|
474
|
+
end
|
|
475
|
+
end
|
|
476
|
+
|
|
477
|
+
private def fix_configure_projects()
|
|
246
478
|
ios_deployment_target = @deployment_target
|
|
247
479
|
puts "pod组件配置工程最低支持iOS系统 ===> #{ios_deployment_target.to_s.send(:red)}".yellow
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
480
|
+
is_above_xcode27 = BB::PodUtils.above_xcode_27_version # 高于27
|
|
481
|
+
is_above_xcode26 = BB::PodUtils.above_xcode_26_version # 高于26
|
|
482
|
+
# is_above_xcode15 = BB::PodUtils.compare_xcode_15_version # 高于15
|
|
483
|
+
# is_below_xcode15 = BB::PodUtils.below_xcode_15_version # 低于15
|
|
484
|
+
projects = all_projects
|
|
485
|
+
app_projects = user_projects
|
|
486
|
+
base_ldflags = generate_other_ldflags
|
|
487
|
+
matrix_resources_configured = false
|
|
488
|
+
|
|
489
|
+
performance_priority_targets = (PERFORMANCE_PRIORITY_TARGETS).uniq
|
|
490
|
+
projects.flat_map(&:targets).uniq.each do |target|
|
|
491
|
+
# 是否属于业务工程
|
|
492
|
+
is_user_target = app_projects.include?(target.project)
|
|
493
|
+
# 是否为主 App 类型
|
|
494
|
+
isMainApp = is_user_target &&
|
|
495
|
+
target.respond_to?(:product_type) &&
|
|
496
|
+
target.product_type == 'com.apple.product-type.application'
|
|
497
|
+
# 是否属于 Pods 工程
|
|
498
|
+
isPodTarget = !is_user_target
|
|
499
|
+
# 过滤业务工程 Target
|
|
500
|
+
next if is_user_target && filterTargetName(target.name)
|
|
501
|
+
# 是否为资源 Bundle
|
|
502
|
+
isBundle = target.respond_to?(:product_type) && target.product_type == 'com.apple.product-type.bundle'
|
|
503
|
+
# 修复警告 Run script build phase '[CP] Copy Pods Resources' will be run during every build because it does not specify any outputs
|
|
504
|
+
configure_build_phases(target)
|
|
505
|
+
# 静态库/动态库修改sdk最低版本
|
|
506
|
+
unless target.is_a?(Xcodeproj::Project::Object::PBXNativeTarget)
|
|
507
|
+
target.build_configurations.each do |config|
|
|
508
|
+
configure_pod_deployment_target(config)
|
|
509
|
+
end
|
|
510
|
+
# puts "[PodPostInstaller] Configured deployment target only: #{target.name} (#{target.class.name.split('::').last})".yellow
|
|
511
|
+
next
|
|
512
|
+
end
|
|
513
|
+
performance_priority = performance_priority_targets.include?(target.name)
|
|
254
514
|
target.build_configurations.each do |config|
|
|
255
|
-
|
|
256
|
-
if
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
end
|
|
263
|
-
env.copyCocosPackage
|
|
515
|
+
isDebug = config.name.match?(/debug/i)
|
|
516
|
+
if isMainApp
|
|
517
|
+
# 主 App 配置
|
|
518
|
+
if @is_matrix == true && isDebug && !matrix_resources_configured # 只有debug环境才进行替换操作,其它环境交由打包机处理
|
|
519
|
+
puts "[#{target.name}/#{config.name}] 开发者debug环境环境替换[PlistMacro/cocos/unity]文件操作,其它环境交由打包机处理".yellow
|
|
520
|
+
matrix_debug_configure
|
|
521
|
+
matrix_resources_configured = true
|
|
264
522
|
end
|
|
265
523
|
# xcode_version = `xcrun xcodebuild -version | grep Xcode | cut -d' ' -f2`.to_f if xcode_version ≥ 15
|
|
266
524
|
new_ldflags = base_ldflags.dup
|
|
267
|
-
key = 'OTHER_LDFLAGS'
|
|
268
|
-
# origin_flags = Array(config.build_settings[key]).join(' ').strip
|
|
269
|
-
origin_flags = Array(config.build_settings[key]).dup
|
|
270
|
-
# 确保 inherited 在
|
|
271
|
-
origin_flags.unshift('$(inherited)') unless origin_flags.include?('$(inherited)')
|
|
272
525
|
linkmap_flag = '-Wl,-map,$(CONFIGURATION_BUILD_DIR)/$(PRODUCT_NAME)-LinkMap-$(CURRENT_VARIANT)-$(CURRENT_ARCH).txt'
|
|
273
|
-
# if
|
|
526
|
+
# if isDebug
|
|
274
527
|
# new_ldflags << linkmap_flag unless new_ldflags.include?(linkmap_flag)
|
|
275
528
|
# else
|
|
276
529
|
# new_ldflags.delete(linkmap_flag)
|
|
277
530
|
# end
|
|
278
531
|
new_ldflags.delete(linkmap_flag) # 提升效率
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
# puts "origin_flags:#{origin_flags}"
|
|
282
|
-
# puts "new_ldflags:#{new_ldflags}"
|
|
283
|
-
# puts "=====#{target.name}-#{config.name} end====="
|
|
532
|
+
key = 'OTHER_LDFLAGS'
|
|
533
|
+
origin_flags = Array(config.build_settings[key])
|
|
284
534
|
if origin_flags != new_ldflags
|
|
285
535
|
config.build_settings[key] = new_ldflags
|
|
286
|
-
should_save = true
|
|
287
536
|
puts "[Updated] #{target.name} #{config.name}: OTHER_LDFLAGS changed Value: #{new_ldflags}".yellow
|
|
288
537
|
else
|
|
289
538
|
puts "[Skipped] #{target.name} #{config.name}: already up-to-date"
|
|
290
539
|
end
|
|
291
|
-
|
|
292
540
|
# 配置工程最低部署:
|
|
293
541
|
# 1. 多 Target 产品显式开启替换时继续保持原有行为;
|
|
294
542
|
# 2. Xcode 27+ 强制将工程最低支持版本统一为 ios_deployment_target。
|
|
295
543
|
if @is_replaceMinVersionForMultiTarget || is_above_xcode27
|
|
296
|
-
|
|
297
|
-
if origin_value.to_s != ios_deployment_target.to_s
|
|
298
|
-
should_save = true
|
|
299
|
-
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = ios_deployment_target.to_s
|
|
300
|
-
new_value = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET']
|
|
301
|
-
puts "#{target.name}-#{config.name} Build Setting 'IPHONEOS_DEPLOYMENT_TARGET' deployment target: #{origin_value} => #{new_value}"
|
|
302
|
-
end
|
|
544
|
+
configure_pod_deployment_target(config)
|
|
303
545
|
end
|
|
304
|
-
|
|
305
|
-
#
|
|
306
|
-
|
|
307
|
-
|
|
546
|
+
elsif isPodTarget
|
|
547
|
+
# Pods 配置
|
|
548
|
+
# pod 1.13.0兼容故去除,避免
|
|
549
|
+
# 适配xcode 15 动态库报错: Error 'DT_TOOLCHAIN_DIR cannot be used to evaluate LIBRARY_SEARCH_PATHS, use TOOLCHAIN_DIR instead'
|
|
550
|
+
# if (is_above_xcode15 == true) then
|
|
551
|
+
# xcconfig_path = config.base_configuration_reference.real_path
|
|
552
|
+
# xcconfig = File.read(xcconfig_path)
|
|
553
|
+
# xcconfig_mod = xcconfig.gsub(/DT_TOOLCHAIN_DIR/, "TOOLCHAIN_DIR")
|
|
554
|
+
# File.open(xcconfig_path, "w") { |file| file << xcconfig_mod }
|
|
555
|
+
# end
|
|
556
|
+
# Only enable BUILD_LIBRARY_FOR_DISTRIBUTION for binary static libraries
|
|
557
|
+
# if (target.name.include? 'BBNativeContainer') || (target.name.include? 'BBSchemeDispatcher') || (target.name.include? 'BBComponentServicesKit') || (target.name.include? 'BBSecurityProtectionKit')
|
|
558
|
+
# config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
|
|
559
|
+
# end
|
|
560
|
+
configure_pod_deployment_target(config)
|
|
561
|
+
config.build_settings['ARCHS'] = "$(ARCHS_STANDARD)"
|
|
562
|
+
# Release+模拟器,cpu架构使用arm64、x86_64,sdk不包含x86_64导致编译失败
|
|
563
|
+
# 指令验证pod工程cpu架构,ARCHS_STANDARD = arm64 x86_64
|
|
564
|
+
# xcodebuild -project Pods/BBUnityFramework.xcodeproj -configuration Release -sdk iphonesimulator -showBuildSettings | grep -E 'ARCHS =|ARCHS_STANDARD =|ONLY_ACTIVE_ARCH =|EXCLUDED_ARCHS ='
|
|
565
|
+
if !isDebug && ['BBUnityFramework', 'cocos2dx'].include?(target.name)
|
|
566
|
+
config.build_settings['ARCHS[sdk=iphonesimulator*]'] = 'arm64'
|
|
308
567
|
end
|
|
568
|
+
# fix xcode14手动签名问题 https://github.com/CocoaPods/CocoaPods/issues/11402
|
|
569
|
+
# config.build_settings["DEVELOPMENT_TEAM"] = "#{teamid}"
|
|
570
|
+
# Fix Xcode14 bundle need sign
|
|
571
|
+
# https://github.com/CocoaPods/CocoaPods/issues/11402#issuecomment-1201464693
|
|
572
|
+
if isBundle
|
|
573
|
+
config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
|
|
574
|
+
end
|
|
575
|
+
# C++支持@import (工程中带mm类需要进行控制)
|
|
576
|
+
if (target.name.include? 'matrix-wechat') || (target.name.include? 'Sentry')
|
|
577
|
+
# 三方库不支持modulemap
|
|
578
|
+
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = "$(inherited) $(OTHER_CFLAGS)"
|
|
579
|
+
else
|
|
580
|
+
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = "$(inherited) $(OTHER_CFLAGS) -fmodules -fcxx-modules"
|
|
581
|
+
end
|
|
582
|
+
# Xcode26写入自定义宏
|
|
583
|
+
configure_swift_compilation_conditions(config, is_above_xcode26)
|
|
584
|
+
# Unity 支持模拟器时,为 BBGameModule 注入编译宏,供 Objective-C/C/C++ 代码判断
|
|
585
|
+
if target.name == 'BBGameModule'
|
|
586
|
+
config_unity_simulator_supported(config)
|
|
587
|
+
end
|
|
588
|
+
# 编译优化配置
|
|
589
|
+
config.build_settings['WARNING_CFLAGS'] = '-Wno-documentation -Wno-nullability-completeness -Wno-macro-redefined -Wno-property-attribute-mismatch -Wno-strict-prototypes -Wno-incompatible-pointer-types'
|
|
590
|
+
# 资源体积优化
|
|
591
|
+
config.build_settings['ASSETCATALOG_COMPILER_OPTIMIZATION'] = 'space'
|
|
309
592
|
end
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
end
|
|
318
|
-
end
|
|
319
|
-
# 组件配置
|
|
320
|
-
@lib.pod_target_subprojects.flat_map { |p| p.targets }.each do |target|
|
|
321
|
-
target.build_configurations.each do |config|
|
|
322
|
-
# Release+模拟器,cpu架构使用arm64、x86_64,sdk不包含x86_64导致编译失败
|
|
323
|
-
# 指令验证pod工程cpu架构,ARCHS_STANDARD = arm64 x86_64
|
|
324
|
-
# xcodebuild -project Pods/BBUnityFramework.xcodeproj -configuration Release -sdk iphonesimulator -showBuildSettings | grep -E 'ARCHS =|ARCHS_STANDARD =|ONLY_ACTIVE_ARCH =|EXCLUDED_ARCHS ='
|
|
325
|
-
if config.name.include?('Release') && ['BBUnityFramework', 'cocos2dx'].include?(target.name)
|
|
326
|
-
config.build_settings['ARCHS[sdk=iphonesimulator*]'] = 'arm64'
|
|
327
|
-
end
|
|
328
|
-
# pod 1.13.0兼容故去除,避免
|
|
329
|
-
# 适配xcode 15 动态库报错: Error 'DT_TOOLCHAIN_DIR cannot be used to evaluate LIBRARY_SEARCH_PATHS, use TOOLCHAIN_DIR instead'
|
|
330
|
-
# if (is_above_xcode15 == true) then
|
|
331
|
-
# xcconfig_path = config.base_configuration_reference.real_path
|
|
332
|
-
# xcconfig = File.read(xcconfig_path)
|
|
333
|
-
# xcconfig_mod = xcconfig.gsub(/DT_TOOLCHAIN_DIR/, "TOOLCHAIN_DIR")
|
|
334
|
-
# File.open(xcconfig_path, "w") { |file| file << xcconfig_mod }
|
|
335
|
-
# end
|
|
336
|
-
# Only enable BUILD_LIBRARY_FOR_DISTRIBUTION for binary static libraries
|
|
337
|
-
# if (target.name.include? 'BBNativeContainer') || (target.name.include? 'BBSchemeDispatcher') || (target.name.include? 'BBComponentServicesKit') || (target.name.include? 'BBSecurityProtectionKit')
|
|
338
|
-
# config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
|
|
339
|
-
# end
|
|
340
|
-
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = ios_deployment_target
|
|
341
|
-
config.build_settings['ARCHS'] = "$(ARCHS_STANDARD)"
|
|
342
|
-
# fix xcode14手动签名问题 https://github.com/CocoaPods/CocoaPods/issues/11402
|
|
343
|
-
# config.build_settings["DEVELOPMENT_TEAM"] = "#{teamid}"
|
|
344
|
-
# Fix Xcode14 bundle need sign
|
|
345
|
-
# https://github.com/CocoaPods/CocoaPods/issues/11402#issuecomment-1201464693
|
|
346
|
-
if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle"
|
|
347
|
-
config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
|
|
348
|
-
end
|
|
349
|
-
# 编译器优化
|
|
350
|
-
config.build_settings['WARNING_CFLAGS'] = '-Wno-documentation -Wno-nullability-completeness -Wno-macro-redefined -Wno-property-attribute-mismatch -Wno-strict-prototypes -Wno-incompatible-pointer-types'
|
|
351
|
-
config.build_settings['ASSETCATALOG_COMPILER_OPTIMIZATION'] = 'space'
|
|
352
|
-
config.build_settings['ENABLE_BITCODE'] = 'NO'
|
|
353
|
-
config.build_settings['DEAD_CODE_STRIPPING'] = 'YES'
|
|
354
|
-
if config.name.include? 'Debug'
|
|
355
|
-
config.build_settings['SWIFT_COMPILATION_MODE'] = 'Incremental'
|
|
356
|
-
config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone'
|
|
357
|
-
config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0'
|
|
358
|
-
else
|
|
359
|
-
config.build_settings['SWIFT_COMPILATION_MODE'] = 'wholemodule'
|
|
360
|
-
config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Osize'
|
|
361
|
-
config.build_settings['GCC_OPTIMIZATION_LEVEL'] = 'z'
|
|
362
|
-
end
|
|
363
|
-
# C++支持@import (工程中带mm类需要进行控制)
|
|
364
|
-
if (target.name.include? 'matrix-wechat') || (target.name.include? 'Sentry')
|
|
365
|
-
# 三方库不支持modulemap
|
|
366
|
-
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = "$(inherited) $(OTHER_CFLAGS)"
|
|
367
|
-
else
|
|
368
|
-
config.build_settings['OTHER_CPLUSPLUSFLAGS'] = "$(inherited) $(OTHER_CFLAGS) -fmodules -fcxx-modules"
|
|
369
|
-
end
|
|
370
|
-
# Xcode26写入自定义宏
|
|
371
|
-
if (is_above_xcode26 == true) then
|
|
372
|
-
config.build_settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS'] = "$(inherited) USING_XCODE_26"
|
|
373
|
-
else
|
|
374
|
-
config.build_settings['SWIFT_ACTIVE_COMPILATION_CONDITIONS'] = "$(inherited)"
|
|
375
|
-
end
|
|
376
|
-
|
|
377
|
-
# Unity 支持模拟器时,为 BBGameModule 注入编译宏,供 Objective-C/C/C++ 代码判断
|
|
378
|
-
if (target.name == 'BBGameModule') && (@unity_simulator_supported) then
|
|
379
|
-
config_unity_simulator_supported(config)
|
|
593
|
+
# 公共编译优化配置
|
|
594
|
+
unless isBundle
|
|
595
|
+
configure_compiler_optimization(
|
|
596
|
+
config,
|
|
597
|
+
isDebug,
|
|
598
|
+
performance_priority: performance_priority
|
|
599
|
+
)
|
|
380
600
|
end
|
|
381
|
-
|
|
382
601
|
# Xcode27去除EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64
|
|
383
|
-
if
|
|
602
|
+
if is_above_xcode27
|
|
384
603
|
fix_above_xcode27_excluded_archs(config)
|
|
385
604
|
end
|
|
386
|
-
|
|
387
|
-
end
|
|
388
|
-
# 修复警告 Run script build phase '[CP] Copy Pods Resources' will be run during every build because it does not specify any outputs
|
|
389
|
-
fix_phases = target.shell_script_build_phases.find { |x| x.name == '[CP] Copy XCFrameworks' || 'Create Symlinks to Header Folders' }
|
|
390
|
-
if fix_phases
|
|
391
|
-
fix_phases.always_out_of_date = "1"
|
|
392
605
|
end
|
|
393
606
|
end
|
|
394
|
-
|
|
607
|
+
end
|
|
608
|
+
|
|
609
|
+
def run
|
|
610
|
+
# 记录业务工程修改前的状态
|
|
611
|
+
snapshots = capture_user_project_snapshots
|
|
612
|
+
# 修正Pods-XXX-frameworks.sh脚本framework拷贝文件报错问题,xcframework缺少模拟器架构导致编译报错
|
|
613
|
+
fix_pods_frameworks
|
|
614
|
+
# 修复工程配置
|
|
615
|
+
fix_configure_projects
|
|
395
616
|
# 修正Xcode16不能po问题
|
|
396
617
|
# fix_above_xcode16_no_po() # xcode27不需要
|
|
397
|
-
# Xcode
|
|
398
|
-
apply_security_hardening(@lib, @enable_omvll, @omvll_whitelist)
|
|
618
|
+
# Xcode 原生安全加固、O-MVLL 加固
|
|
619
|
+
apply_security_hardening(@lib, @enable_omvll, @omvll_whitelist, @enable_security_hardening, save_projects: false)
|
|
620
|
+
# 仅保存发生变化的业务工程
|
|
621
|
+
save_user_projects(snapshots)
|
|
399
622
|
end
|
|
400
623
|
end
|
|
624
|
+
|
|
625
|
+
# 安装 Pod Hook
|
|
626
|
+
#
|
|
627
|
+
# @param installer CocoaPods Installer
|
|
628
|
+
# @param deployment_target 工程最低支持系统版本,nil 时自动判断
|
|
629
|
+
# @param excluded_targets 排除的Target名称,多个使用[]
|
|
630
|
+
# @param omvll_whitelist O-MVLL加固白名单,请使用target名称,多个使用[]
|
|
631
|
+
def apply_pod_post_install(installer, deployment_target, excluded_targets: [], omvll_whitelist: [])
|
|
632
|
+
installer = PodPostInstaller.new(installer ,deployment_target, excluded_targets:excluded_targets, omvll_whitelist:omvll_whitelist)
|
|
633
|
+
installer.run
|
|
634
|
+
end
|