Class: PodPostInstaller

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

Instance Method Summary collapse

Constructor Details

#initialize(lib, deployment_target = nil, filter_targets = ["test"], is_matrix = true) ⇒ PodPostInstaller

Returns a new instance of PodPostInstaller.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cocoapods-bb-PodAssistant/babybus/installer/post_install_hooks.rb', line 10

def initialize(lib, deployment_target=nil, filter_targets=["test"], is_matrix=true)
    @lib = lib
    if deployment_target.nil?
        is_xcode16 = BB::PodUtils.above_xcode_16_version
        if (is_xcode16 == true) then
            @deployment_target = "13.0" # iOS18最低支持13系统
        else
            @deployment_target = isUnity3DApp ? "12.0" : "11.0" # Unity2022引擎最低支持iOS12.0、unity2d iOS11 、cocos iOS10、超A产品 iOS11 (968广告厂商升级最低支持iOS11)
        end
    else
        @deployment_target = deployment_target
    end
    if filter_targets.is_a? Array
        @filter_targets = filter_targets # 过滤target
    elsif filter_targets.is_a? String
        @filter_targets = [filter_targets] # 过滤target
    end
    @is_matrix = is_matrix
end

Instance Method Details

#runObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/cocoapods-bb-PodAssistant/babybus/installer/post_install_hooks.rb', line 38

def run
    env = BabybusInstallEnv.new()
    is_above_xcode15 = BB::PodUtils.compare_xcode_15_version # 高于15
    is_below_xcode15 = BB::PodUtils.below_xcode_15_version # 低于15
    # 是否Untify项目
    isUnityProject = isUnityApp
    # Untify项目需要移除cocos项目res/src目录
    if (isUnityProject) then
        env.createCocosResource
    end
    ios_deployment_target = @deployment_target
    puts "pod组件配置工程最低支持iOS系统 ===> #{ios_deployment_target.to_s.send(:red)}".green
    @lib.aggregate_targets.first.user_project.save # 解决Xcode13 pod update操作出现failed to save pods.xcodeproj问题 by hm 21/11/8
    project = Xcodeproj::Project.open(BB::PodUtils.getXcodeprojPath)
    project.targets.each do |target|
        target.build_configurations.each do |config|
            # if !target.name.include? 'test'
            if !filterTargetName(target.name) # 过滤target test 工程
                if (@is_matrix == true) && (config.name.include? 'Debug') # 只有debug环境才进行替换操作,其它环境交由打包机处理
                    puts "[#{target.name}/#{config.name}] 开发者debug环境环境替换[PlistMacro/cocos/unity]文件操作,其它环境交由打包机处理".red
                    env.copyPlistMacro # 开发自行打开不能提交到版本控制,避免test包出现配置不正确情况 by hm 22/5/17
                    if (isUnityProject) then
                        env.copyUnityFramework
                    else
                        env.copyCocosPackage
                    end
                end
                # xcode_version = `xcrun xcodebuild -version | grep Xcode | cut -d' ' -f2`.to_f   if xcode_version ≥ 15
                # iOS17适配添加ld64 https://developer.apple.com/documentation/xcode-release-notes/xcode-15-release-notes
                if (is_above_xcode15 == true) then
                    # c++ weak 标识 xcode15 -ld64 is deprecated, use -ld_classic instead
                    config.build_settings['OTHER_LDFLAGS'] = "$(inherited) -lxml2 -lz -ObjC -lstdc++ -Wl -ld_classic -weak_framework SwiftUI"
                else
                    config.build_settings['OTHER_LDFLAGS'] = "$(inherited) -lxml2 -lz -ObjC -lstdc++"
                end
                otherLink_setting_value = config.build_settings['OTHER_LDFLAGS']
                puts "#{target.name}-#{config.name} Build Setting 'OTHER_LDFLAGS' Value: #{otherLink_setting_value}"

                # 配置工程最低部署
                origin_value = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET']
                if origin_value.to_i != ios_deployment_target.to_i
                    config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = ios_deployment_target.to_s
                    new_value = config.build_settings['IPHONEOS_DEPLOYMENT_TARGET']
                    puts "#{target.name}-#{config.name} Build Setting 'IPHONEOS_DEPLOYMENT_TARGET' deployment target: #{origin_value} => #{new_value}"
                end
            end
        end
    end
    # projects.config
    @lib.pod_target_subprojects.each do |project|
        project.build_configurations.each do |config|
            config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = ios_deployment_target
            if (isUnityProject) then
                config.build_settings['ARCHS'] = 'arm64'
            else
                config.build_settings['ARCHS'] = '$(ARCHS_STANDARD)'
            end
        end
    end
    # project.targets.config
    @lib.pod_target_subprojects.flat_map { |p| p.targets }.each do |target|
        target.build_configurations.each do |config|
            # pod 1.13.0兼容故去除,避免
            # 适配xcode 15 动态库报错: Error 'DT_TOOLCHAIN_DIR cannot be used to evaluate LIBRARY_SEARCH_PATHS, use TOOLCHAIN_DIR instead'
            # if (is_above_xcode15 == true) then
            #     xcconfig_path = config.base_configuration_reference.real_path
            #     xcconfig = File.read(xcconfig_path)
            #     xcconfig_mod = xcconfig.gsub(/DT_TOOLCHAIN_DIR/, "TOOLCHAIN_DIR")
            #     File.open(xcconfig_path, "w") { |file| file << xcconfig_mod }
            # end
            
            config.build_settings['DEAD_CODE_STRIPPING'] = 'YES'
            config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = ios_deployment_target
            if (isUnityProject) then
                config.build_settings['ARCHS'] = 'arm64'
            else
                config.build_settings['ARCHS'] = '$(ARCHS_STANDARD)'
            end
            # fix xcode14手动签名问题 https://github.com/CocoaPods/CocoaPods/issues/11402
            # config.build_settings["DEVELOPMENT_TEAM"] = "#{teamid}"
            # Fix Xcode14 bundle need sign
            # https://github.com/CocoaPods/CocoaPods/issues/11402#issuecomment-1201464693
            if target.respond_to?(:product_type) and target.product_type == "com.apple.product-type.bundle"
                config.build_settings['CODE_SIGNING_ALLOWED'] = 'NO'
            end
            # 编译器优化
            config.build_settings['WARNING_CFLAGS'] = '-Wno-documentation -Wno-nullability-completeness -Wno-macro-redefined -Wno-property-attribute-mismatch -Wno-strict-prototypes -Wno-incompatible-pointer-types'
            config.build_settings['ASSETCATALOG_COMPILER_OPTIMIZATION'] = 'space'
            config.build_settings['ENABLE_BITCODE'] = 'NO'
            config.build_settings['DEAD_CODE_STRIPPING'] = 'YES'
            if config.name.include? 'Debug'
                config.build_settings['SWIFT_COMPILATION_MODE'] = 'Incremental'
                config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Onone'
                config.build_settings['GCC_OPTIMIZATION_LEVEL'] = '0'
            else
                config.build_settings['SWIFT_COMPILATION_MODE'] = 'wholemodule'
                config.build_settings['SWIFT_OPTIMIZATION_LEVEL'] = '-Osize'
                config.build_settings['GCC_OPTIMIZATION_LEVEL'] = 'z'
            end
            # C++支持@import (工程中带mm类需要进行控制)
            if (target.name.include? 'matrix-wechat') || (target.name.include? 'Sentry')
                # 三方库不支持modulemap
                config.build_settings['OTHER_CPLUSPLUSFLAGS'] = "$(inherited) $(OTHER_CFLAGS)"
            else
                config.build_settings['OTHER_CPLUSPLUSFLAGS'] = "$(inherited) $(OTHER_CFLAGS) -fmodules -fcxx-modules"
            end
        end
        # 修复警告 Run script build phase '[CP] Copy Pods Resources' will be run during every build because it does not specify any outputs
        fix_phases = target.shell_script_build_phases.find { |x| x.name == '[CP] Copy XCFrameworks' || 'Create Symlinks to Header Folders' }
        if fix_phases
            fix_phases.always_out_of_date = "1"
        end
        if (is_below_xcode15 == true) then
            project.save
        end
    end
end