cocoapods-bb-PodAssistant 0.3.17.8 → 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.
@@ -116,3 +116,12 @@ class PodPostIntegrate
116
116
  end
117
117
  end
118
118
  end
119
+
120
+ # 安装 Pod Hook,处理最终生成的xcconfig
121
+ #
122
+ # @param installer [Pod::Installer] CocoaPods Installer
123
+ # @param simulator_unsupported_binaries [Array<String>] 不支持模拟器的二进制库列表,将从模拟器链接参数中移除,举例:['libRecorder.a','SingSound.framework']
124
+ def apply_pod_post_integrate(installer, simulator_unsupported_binaries: [])
125
+ installer = PodPostIntegrate.new(installer ,simulator_unsupported_binaries)
126
+ installer.run
127
+ end
@@ -1,3 +1,3 @@
1
1
  module CocoapodsBbPodassistant
2
- VERSION = "0.3.17.8"
2
+ VERSION = "0.3.18.1"
3
3
  end
@@ -0,0 +1,69 @@
1
+ # 统一环境变量管理
2
+
3
+ module BB
4
+ module BuildEnvironment
5
+ TRUE_VALUES = %w[true 1 yes on].freeze
6
+ FALSE_VALUES = %w[false 0 no off].freeze
7
+
8
+ module_function
9
+
10
+ # 读取布尔类型环境变量
11
+ def bool(key, default: false)
12
+ value = ENV[key]
13
+
14
+ return default if value.nil? || value.strip.empty?
15
+
16
+ normalized = value.strip.downcase
17
+
18
+ return true if TRUE_VALUES.include?(normalized)
19
+ return false if FALSE_VALUES.include?(normalized)
20
+
21
+ raise ArgumentError,
22
+ "[BuildEnvironment] Invalid boolean: #{key}=#{value.inspect}"
23
+ end
24
+
25
+ # 是否矩阵产品
26
+ def matrix?
27
+ bool('BB_MATRIX_PRODUCTC')
28
+ end
29
+ # 是否统一替换多 Target 最低系统版本
30
+ def replace_min_version_for_multi_target?
31
+ bool(
32
+ 'BB_REPLACE_MIN_VERSION_FOR_MULTI_TARGET',
33
+ default: true
34
+ )
35
+ end
36
+
37
+ # Unity是否支持Simulator
38
+ def unity_simulator_supported?
39
+ bool('UNITY_SIMULATOR_SUPPORTED')
40
+ end
41
+
42
+ # 原生安全加固
43
+ def security_hardening_enabled?
44
+ bool('BB_ENABLE_SECURITY_HARDENING', default: true)
45
+ end
46
+
47
+ # O-MVLL 加固
48
+ def hardening_omvll_enabled?
49
+ bool('BB_ENABLE_OMVLL', default: true)
50
+ end
51
+
52
+ # 360 加固
53
+ def hardening_360_enabled?
54
+ bool('BB_ENABLE_360_HARDENING')
55
+ end
56
+
57
+ # 打印当前构建策略
58
+ def print_configuration
59
+ puts '[BuildEnvironment] =========================='
60
+ puts "是否矩阵产品 : #{matrix?}"
61
+ puts "是否统一多 Target 最低系统版本 : #{replace_min_version_for_multi_target?}"
62
+ puts "Unity 是否支持模拟器 : #{unity_simulator_supported?}"
63
+ puts "是否开启原生安全编译配置 : #{security_hardening_enabled?}"
64
+ puts "是否开启 O-MVLL 加固 : #{hardening_omvll_enabled?}"
65
+ puts "是否开启 360 加固 : #{hardening_360_enabled?}"
66
+ puts '[BuildEnvironment] =========================='
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,89 @@
1
+ require 'molinillo'
2
+
3
+ module BB
4
+ module MolinilloPerformancePatch
5
+
6
+ # gem list molinillo 查看版本
7
+ SUPPORTED_VERSIONS = %w[
8
+ 0.8.0
9
+ ].freeze
10
+
11
+ module VertexOptimization
12
+
13
+ def path_to?(other)
14
+ result = optimized_path_to?(other)
15
+
16
+ if ENV['BB_MOLINILLO_VERIFY'] == '1'
17
+ original = super(other)
18
+
19
+ unless result == original
20
+ raise "[MolinilloOptimization] Path result mismatch"
21
+ end
22
+ end
23
+
24
+ result
25
+ end
26
+
27
+ private
28
+
29
+ def optimized_path_to?(other)
30
+ return true if equal?(other)
31
+
32
+ visited = {}.compare_by_identity
33
+ visited[self] = true
34
+
35
+ pending = [self]
36
+
37
+ until pending.empty?
38
+ vertex = pending.pop
39
+
40
+ vertex.successors.each do |successor|
41
+ return true if successor.equal?(other)
42
+
43
+ next if visited.key?(successor)
44
+
45
+ visited[successor] = true
46
+ pending << successor
47
+ end
48
+ end
49
+
50
+ false
51
+ end
52
+ end
53
+
54
+ class << self
55
+
56
+ def enabled?
57
+ ENV.fetch('BB_MOLINILLO_OPTIMIZATION', '1') == '1'
58
+ # ENV['BB_MOLINILLO_OPTIMIZATION'] == '1'
59
+ end
60
+
61
+ def install!
62
+ return unless enabled?
63
+ return if @installed
64
+
65
+ version = Gem.loaded_specs['molinillo']&.version&.to_s
66
+
67
+ unless SUPPORTED_VERSIONS.include?(version)
68
+ puts "[MolinilloOptimization] Unsupported version: #{version}"
69
+ return
70
+ end
71
+
72
+ klass = Molinillo::DependencyGraph::Vertex
73
+
74
+ unless klass.method_defined?(:path_to?)
75
+ puts '[MolinilloOptimization] path_to? unavailable'
76
+ return
77
+ end
78
+
79
+ klass.prepend(VertexOptimization)
80
+
81
+ @installed = true
82
+
83
+ puts "[MolinilloOptimization] Enabled for Molinillo #{version}"
84
+ end
85
+ end
86
+ end
87
+ end
88
+
89
+ BB::MolinilloPerformancePatch.install!
@@ -0,0 +1,372 @@
1
+ require 'cocoapods'
2
+
3
+ # BB_POD_PROFILE=1 BB_POD_PROFILE_DEEP=1 podin
4
+ module BB
5
+ module PodPerformanceProfiler
6
+
7
+ ALLOCATION_PROFILE_TARGETS = %w[
8
+ Molinillo::DependencyGraph::Vertex#path_to?
9
+ Molinillo::Resolver::Resolution#resolve
10
+ Pod::Installer::Analyzer#generate_version_locking_dependencies
11
+ Pod::Installer::Analyzer#analyze
12
+ Pod::Installer#generate_pods_project
13
+ ].map(&:freeze).freeze
14
+
15
+ @statistics = Hash.new do |hash, key|
16
+ hash[key] = {
17
+ count: 0,
18
+ total: 0.0,
19
+ max: 0.0,
20
+ allocated: 0,
21
+ max_allocated: 0
22
+ }
23
+ end
24
+
25
+ class << self
26
+ def enabled?
27
+ ENV['BB_POD_PROFILE'] == '1'
28
+ end
29
+
30
+ def allocation_profile_enabled?
31
+ ENV['BB_POD_PROFILE_ALLOC'] == '1'
32
+ end
33
+
34
+ def allocation_profile_target?(name)
35
+ allocation_profile_enabled? && ALLOCATION_PROFILE_TARGETS.include?(name)
36
+ end
37
+
38
+ def now
39
+ Process.clock_gettime(Process::CLOCK_MONOTONIC)
40
+ end
41
+
42
+ def measure(name)
43
+ return yield unless Process.pid == @owner_pid
44
+
45
+ track_allocation = allocation_profile_target?(name)
46
+
47
+ allocated_before = if track_allocation
48
+ GC.stat(:total_allocated_objects)
49
+ end
50
+
51
+ start_time = now
52
+
53
+ begin
54
+ yield
55
+ ensure
56
+ elapsed = now - start_time
57
+
58
+ allocated = if track_allocation
59
+ GC.stat(:total_allocated_objects) - allocated_before
60
+ else
61
+ 0
62
+ end
63
+
64
+ item = @statistics[name]
65
+
66
+ item[:count] += 1
67
+ item[:total] += elapsed
68
+ item[:max] = [item[:max], elapsed].max
69
+
70
+ if track_allocation
71
+ item[:allocated] += allocated
72
+
73
+ item[:min_allocated] = [
74
+ item[:min_allocated] || allocated,
75
+ allocated
76
+ ].min
77
+
78
+ item[:max_allocated] = [
79
+ item[:max_allocated],
80
+ allocated
81
+ ].max
82
+ end
83
+
84
+ if elapsed >= 0.5
85
+ puts format(
86
+ '[PodProfile] %-55s %8.3fs',
87
+ name,
88
+ elapsed
89
+ )
90
+ end
91
+ end
92
+ end
93
+
94
+ def instrument(klass, *method_names)
95
+ method_names.each do |method_name|
96
+ visibility =
97
+ if klass.private_method_defined?(method_name)
98
+ :private
99
+ elsif klass.protected_method_defined?(method_name)
100
+ :protected
101
+ elsif klass.method_defined?(method_name)
102
+ :public
103
+ end
104
+
105
+ unless visibility
106
+ puts "[PodProfile] Method unavailable: #{klass}##{method_name}"
107
+ next
108
+ end
109
+
110
+ name = "#{klass.name || klass.to_s}##{method_name}"
111
+ if method_name == :path_to?
112
+ original_method = klass.instance_method(method_name)
113
+
114
+ puts "[PodProfile] Method: #{name}"
115
+ puts "[PodProfile] Owner: #{original_method.owner}"
116
+ puts "[PodProfile] Source: #{original_method.source_location.inspect}"
117
+ end
118
+
119
+ wrapper = Module.new do
120
+ define_method(method_name) do |*args, **kwargs, &block|
121
+ BB::PodPerformanceProfiler.measure(name) do
122
+ super(*args, **kwargs, &block)
123
+ end
124
+ end
125
+
126
+ send(visibility, method_name)
127
+ end
128
+
129
+ klass.prepend(wrapper)
130
+ end
131
+ end
132
+
133
+ def install!
134
+ return unless enabled?
135
+ return if @installed
136
+
137
+ @installed = true
138
+ @owner_pid = Process.pid
139
+ GC::Profiler.enable
140
+ @gc_stat_before = GC.stat
141
+
142
+ puts '[PodProfile] Performance profiler enabled'
143
+
144
+ instrument(
145
+ Pod::Installer,
146
+ # :prepare,
147
+ :resolve_dependencies,
148
+ # :analyze,
149
+ # :download_dependencies,
150
+ # :validate_targets,
151
+ :generate_pods_project,
152
+ # :integrate,
153
+ # :perform_post_install_actions,
154
+ # :run_podfile_post_install_hooks,
155
+ # :run_podfile_post_integrate_hooks,
156
+ # :write_lockfiles
157
+ )
158
+
159
+ instrument(
160
+ Pod::Installer::Analyzer,
161
+ :analyze,
162
+ # :inspect_targets_to_integrate,
163
+ # :fetch_external_sources,
164
+ # :resolve_dependencies,
165
+ # :generate_targets,
166
+ # :generate_pod_targets,
167
+ # :generate_aggregate_targets,
168
+ # :generate_podfile_state,
169
+ # :generate_sandbox_state,
170
+ # :validate_podfile,
171
+ # :validate_lockfile_version,
172
+ :generate_version_locking_dependencies,
173
+ # :dependencies_to_fetch,
174
+ # :specifications_for_target,
175
+ # :compute_pod_target_dependencies,
176
+ # :compute_aggregate_target_dependencies,
177
+ # :compute_specs_by_target,
178
+ # :filter_pod_targets,
179
+ # :validate_platforms,
180
+ # :sources
181
+ )
182
+
183
+ instrument(
184
+ Pod::Resolver,
185
+ :resolve,
186
+ :search_for,
187
+ :dependencies_for,
188
+ :specifications_for_dependency,
189
+ :sort_dependencies,
190
+ :requirement_satisfied_by?,
191
+ :dependencies_equal?,
192
+ :allow_missing?,
193
+ :valid_possibility_version_for_root_name?,
194
+ :specification_satisfies_requirement?,
195
+ :find_cached_set,
196
+ :aggregate_for_dependency,
197
+ :resolver_specs_by_target
198
+ )
199
+
200
+ require 'molinillo'
201
+
202
+ if defined?(Molinillo::Resolver)
203
+ instrument(
204
+ Molinillo::Resolver,
205
+ :resolve
206
+ )
207
+ end
208
+
209
+ if defined?(Molinillo::Resolver::Resolution)
210
+ instrument(
211
+ Molinillo::Resolver::Resolution,
212
+ :resolve,
213
+ :process_topmost_state,
214
+ :attempt_to_activate,
215
+ :attempt_to_filter_existing_spec,
216
+ :activate_new_spec,
217
+ :require_nested_dependencies_for,
218
+ :push_state_for_requirements,
219
+ :possibilities_for_requirement,
220
+ :group_possibilities,
221
+ :unwind_for_conflict,
222
+ :build_details_for_unwind,
223
+ :filter_possibilities_after_unwind,
224
+ :sort_dependencies,
225
+ :create_conflict
226
+ )
227
+ end
228
+
229
+ if defined?(Molinillo::DependencyGraph)
230
+ instrument(
231
+ Molinillo::DependencyGraph,
232
+ :add_child_vertex,
233
+ :add_vertex,
234
+ :add_edge,
235
+ :add_edge_no_circular,
236
+ :vertex_named,
237
+ :path,
238
+ :detach_vertex_named,
239
+ :set_payload,
240
+ :tag,
241
+ :rewind_to
242
+ )
243
+ end
244
+
245
+ if defined?(Molinillo::DependencyGraph::Vertex)
246
+ instrument(
247
+ Molinillo::DependencyGraph::Vertex,
248
+ :path_to?,
249
+ # :recursive_successors,
250
+ # :recursive_predecessors,
251
+ # :successors,
252
+ # :predecessors,
253
+ # :ancestor?,
254
+ # :descendent?
255
+ )
256
+ # 深度监控
257
+ if ENV['BB_POD_PROFILE_DEEP'] == '1'
258
+ instrument(
259
+ Molinillo::DependencyGraph::Vertex,
260
+ :hash,
261
+ :eql?,
262
+ :==
263
+ )
264
+ end
265
+ end
266
+
267
+ if defined?(Molinillo::DependencyGraph::Log)
268
+ instrument(
269
+ Molinillo::DependencyGraph::Log,
270
+ :add_vertex,
271
+ :add_edge_no_circular,
272
+ :push_action,
273
+ :rewind_to
274
+ )
275
+ end
276
+
277
+ if defined?(Pod::Installer::Analyzer::LockingDependencyAnalyzer)
278
+ instrument(
279
+ Pod::Installer::Analyzer::LockingDependencyAnalyzer,
280
+ :generate_version_locking_dependencies,
281
+ :add_to_dependency_graph,
282
+ :add_dependency,
283
+ :dependencies_from_lockfile
284
+ )
285
+
286
+ # 监控类方法
287
+ instrument(
288
+ Pod::Installer::Analyzer::LockingDependencyAnalyzer.singleton_class,
289
+ :generate_version_locking_dependencies
290
+ )
291
+ end
292
+
293
+ at_exit do
294
+ if Process.pid == @owner_pid
295
+ print_summary
296
+ end
297
+ end
298
+ end
299
+
300
+ def print_summary
301
+ return unless enabled?
302
+
303
+ puts
304
+ puts '[PodProfile] ================= Performance Summary ================='
305
+
306
+ @statistics
307
+ .sort_by { |_, value| -value[:total] }
308
+ .each do |name, value|
309
+ puts format(
310
+ '%-65s count=%-6d total=%8.3fs max=%8.3fs',
311
+ name,
312
+ value[:count],
313
+ value[:total],
314
+ value[:max]
315
+ )
316
+ end
317
+
318
+ puts '[PodProfile] ======================================================='
319
+
320
+ gc_stat_after = GC.stat
321
+ puts
322
+ puts '[PodProfile] ================= GC Summary ================='
323
+
324
+ puts format(
325
+ 'GC Total Time: %.3fs',
326
+ GC::Profiler.total_time
327
+ )
328
+
329
+ [
330
+ :count,
331
+ :minor_gc_count,
332
+ :major_gc_count,
333
+ :total_allocated_objects,
334
+ :total_freed_objects
335
+ ].each do |key|
336
+ before = @gc_stat_before.fetch(key, 0)
337
+ after = gc_stat_after.fetch(key, 0)
338
+
339
+ puts "#{key}: #{after - before}"
340
+ end
341
+
342
+ puts '[PodProfile] =============================================='
343
+
344
+ if allocation_profile_enabled?
345
+ puts
346
+ puts '[PodProfile] ================= Allocation Summary ================='
347
+
348
+ @statistics
349
+ .select { |_, value| value[:allocated] > 0 }
350
+ .sort_by { |_, value| -value[:allocated] }
351
+ .each do |name, value|
352
+
353
+ average = value[:allocated] / value[:count]
354
+
355
+ puts format(
356
+ '%-65s count=%-6d allocated=%-12d avg=%-10d max=%d',
357
+ name,
358
+ value[:count],
359
+ value[:allocated],
360
+ average,
361
+ value[:max_allocated]
362
+ )
363
+ end
364
+
365
+ puts '[PodProfile] ======================================================='
366
+ end
367
+ end
368
+ end
369
+ end
370
+ end
371
+
372
+ BB::PodPerformanceProfiler.install!