Class: CBin::XCFramework::XCBuilder

Inherits:
Object
  • Object
show all
Includes:
Pod, Pod::Config::Mixin
Defined in:
lib/cocoapods-bb-bin/helpers/xcframework_builder.rb

Instance Method Summary collapse

Methods included from Pod

match_version?

Constructor Details

#initialize(spec, spec_sources, support_maccatalyst = false, isGenDylib = false) ⇒ XCBuilder

Returns a new instance of XCBuilder.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/cocoapods-bb-bin/helpers/xcframework_builder.rb', line 17

def initialize(spec,spec_sources, support_maccatalyst=false,isGenDylib=false)
    @spec = spec
    @spec_sources = spec_sources.split(',') unless spec_sources.nil?
    @name = "#{@spec.name}.podspec"
    @source = nil
    @subspecs = nil
    @configuration = 'Release'
    @use_modular_headers = true
    @force = true
    @use_static_library = true
    @enable_bitcode = false
    @symbols = true
    @support_maccatalyst = support_maccatalyst # 默认不再支持MacCatalyst方式支持iOS应用在mac平台运行库生成
    @support_dynamic = isGenDylib
    
    target_dir = "#{Dir.pwd}/#{@spec.name}-#{@spec.version}"
    UI.puts "build initialize...#{spec} spec_sources:#{spec_sources} target_dir:#{target_dir} 是否支持Mac Catalyst:#{support_maccatalyst} 是否生成动态库:#{isGenDylib}"
end

Instance Method Details

#buildObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cocoapods-bb-bin/helpers/xcframework_builder.rb', line 36

def build
    UI.section("Building xcframework #{@spec} 是否生成动态库:#{@support_dynamic}") do
        config.static_library_enable = @use_static_library # 一定要配置 true,否则调用xcframework生成命令无效
        # 废弃,run_xcframework替代实现
        # frameworker = Frameworker.new(@name, @source, @spec_sources, @subspecs, @configuration, @force, @use_modular_headers, @enable_bitcode, @symbols, @support_maccatalyst, @support_dynamic)
        # frameworker.run
        # 生成二进制产物 by hm 26/2/4
        run_xcframework
        # 拷贝
        cp_to_source_dir
    end
end

#run_xcframeworkObject



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
# File 'lib/cocoapods-bb-bin/helpers/xcframework_builder.rb', line 49

def run_xcframework
    spec_sources_str = if @spec_sources.is_a?(Array)
                         @spec_sources.join(',')
                       else
                         @spec_sources.to_s
                       end
    argvs = [
        "#{@name}",  # name
        "#{@source}", # spec
        "--spec-sources=#{spec_sources_str}",
        "--subspecs=#{@subspecs}",
        "--configuration=#{@configuration}",
        "--use-modular-headers=#{@use_modular_headers}",
        "--archive-export", # 默认archive导出dylib
        # "--no-archive-export",
    ]
    if @force
        argvs += ['--force']
    end
    if @enable_bitcode
        argvs += ['--enable-bitcode']
    end
    if @symbols
        argvs += ['--symbols']
    end
    if @support_maccatalyst
        argvs += ['--support-maccatalyst']
    end
    if @support_dynamic
        argvs += ['--support-dynamic']
    end
    puts "make xcframework argvs: #{argvs}".yellow
    archive = Pod::Command::Bin::XCFramework.new(CLAide::ARGV.new(argvs))
    archive.validate!
    sources_sepc = archive.run
    return sources_sepc
end