Class: PodPostIntegrate

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-bb-PodAssistant/babybus/installer/post_integrate_hooks.rb

Constant Summary collapse

DEFAULT_SIMULATOR_UNSUPPORTED_BINARIES =

安装pod hook操作,处理最终生成的xcconfig 参数说明 lib 组件库 simulator_unsupported_binaries 过滤不支持模拟器二进制库,多个使用[],举例:['libRecorder.a','SingSound.framework']

[
    # ttsdk
    'RangersAppLog.framework', 'TTSDKFramework.framework', 'libRangersAppLog_CN_awesome_ios.a','libRangersAppLog_Core_awesome_ios.a','libRangersAppLog_Log_awesome_ios.a','libRangersAppLog_SG_awesome_ios.a','libRangersAppLog_VA_awesome_ios.a','libRangersAppLog_VOLC_awesome_ios.a',
    # mango
    'EasyReporter.framework', 'MGPlayerFoundation.framework', 'MgtvInteractiveMediaAds.framework', 'MGTVMediaSSPForAD.framework', 'MGTVSSPDownload.framework',
    # um
    'UMDevice.framework','UMRemoteConfig.framework','UMAPM.framework','UMCommon.framework',
    # baiduBCE
    'BaiduBCEBasic.framework','BaiduBCEBOS.framework','BaiduBCESTS.framework','BaiduBCEVOD.framework',
    # record
    'libRecorder.a',
    # singsound
    'SingSound.framework', 'libmp3lame.a', 'libssound-71-ios-3.0.3-20230926103957-SSL.a',
    # share
    'libWeiboSDK.a', 'QQSDK.framework',
    'cocos2dx.framework',
    'UnityFramework.framework',
    'MediaPipeUnity.framework',
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(lib, simulator_unsupported_binaries = []) ⇒ PodPostIntegrate

Returns a new instance of PodPostIntegrate.



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cocoapods-bb-PodAssistant/babybus/installer/post_integrate_hooks.rb', line 35

def initialize(lib, simulator_unsupported_binaries = [])
    @lib = lib

    binaries = if simulator_unsupported_binaries.is_a?(Array)
        simulator_unsupported_binaries
    elsif simulator_unsupported_binaries.is_a?(String)
        [simulator_unsupported_binaries]
    else
        []
    end

    # 外部未传或传入空数组/空字符串时,只使用默认列表;
    # 外部有传值时,在默认列表基础上追加业务自定义列表。
    binaries = binaries.reject { |binary| binary.to_s.strip.empty? }
    if binaries.empty?
        @simulator_unsupported_binaries = DEFAULT_SIMULATOR_UNSUPPORTED_BINARIES.dup
    else
        @simulator_unsupported_binaries = DEFAULT_SIMULATOR_UNSUPPORTED_BINARIES.dup + binaries
    end
    # 去重,避免默认配置和业务自定义配置重复。
    @simulator_unsupported_binaries.uniq!
end

Instance Method Details

#runObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/cocoapods-bb-PodAssistant/babybus/installer/post_integrate_hooks.rb', line 58

def run
    installer = @lib
    # 从 simulator_unsupported_binaries 中提取不支持 Simulator 的静态库名称
    # 例如:libRecorder.a -> Recorder;SingSound.framework -> SingSound
    simulator_unsupported_libraries = @simulator_unsupported_binaries
        .select { |binary| File.extname(binary) == '.a' }
        .map { |binary| File.basename(binary, '.a').sub(/^lib/, '') }
    simulator_unsupported_frameworks = @simulator_unsupported_binaries
        .select { |binary| File.extname(binary) == '.framework' }
        .map { |binary| File.basename(binary, '.framework') }
    puts "post_integrate===simulator_unsupported_libraries:#{simulator_unsupported_libraries}"
    puts "post_integrate===simulator_unsupported_frameworks:#{simulator_unsupported_frameworks}"
    Dir.glob(File.join(installer.sandbox.root.to_s, 'Target Support Files', 'Pods-*', 'Pods-*.xcconfig')).each do |xcconfig_path|
        lines = File.readlines(xcconfig_path)
        other_ldflags_line = lines.find do |line|
            line.start_with?('OTHER_LDFLAGS = ') ||
            line.start_with?('OTHER_LDFLAGS[sdk=iphoneos*] = ') ||
            line.start_with?('OTHER_LDFLAGS[sdk=iphonesimulator*] = ')
        end
        next unless other_ldflags_line
        original_flags = other_ldflags_line.sub('OTHER_LDFLAGS = ', '').strip
        simulator_flags = original_flags.dup
        simulator_unsupported_libraries.each do |library|
            simulator_flags.gsub!(/-l"?#{Regexp.escape(library)}"?\s*/, '')
        end
        simulator_unsupported_frameworks.each do |framework|
            escaped_framework = Regexp.escape(framework)
            # 绝对匹配 framework 名称:
            # -framework "SingSound" 只匹配 SingSound,不能误匹配 SingSoundSDK。
            # 同时兼容带引号和不带引号两种 OTHER_LDFLAGS 格式。
            simulator_flags.gsub!(
                /(?:^|\s)-framework\s+(?:"#{escaped_framework}"|#{escaped_framework})(?=\s|$)/,
                ''
            )
        end
        # 没有过滤掉任何linker flag 时,不改写xcconfig,避免pod install每次产生无意义文件变化
        # if simulator_flags == original_flags
        #     next
        # end
        device_setting = "OTHER_LDFLAGS[sdk=iphoneos*] = #{original_flags}\n"
        simulator_setting = "OTHER_LDFLAGS[sdk=iphonesimulator*] = #{simulator_flags}\n"
        lines.reject! do |line|
            line.start_with?('OTHER_LDFLAGS = ') ||
            line.start_with?('OTHER_LDFLAGS[sdk=iphoneos*] = ') ||
            line.start_with?('OTHER_LDFLAGS[sdk=iphonesimulator*] = ')
        end
        lines << device_setting
        lines << simulator_setting
        # Xcode去除EXCLUDED_ARCHS[sdk=iphonesimulator*] = arm64 支持Apple Silicon Simulator
        content = lines.join # content = File.read(xcconfig_path)
        updated = content.gsub(/^EXCLUDED_ARCHS\[sdk=iphonesimulator\*\]\s*=\s*(.*)$/) do
            archs = Regexp.last_match(1).split.reject { |arch| arch == 'arm64' }
            archs.empty? ? '' : "EXCLUDED_ARCHS[sdk=iphonesimulator*] = #{archs.join(' ')}"
        end
        File.write(xcconfig_path, updated)
    end
end