Class: Pod::Command::Bin::Archive

Inherits:
Pod::Command::Bin show all
Defined in:
lib/cocoapods-bb-bin/command/bin/archive.rb

Constant Summary collapse

@@missing_binary_specs =
[]

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pod::Command::Bin

#validate!

Methods included from CBin::SpecFilesHelper

#binary_spec, #binary_spec_files, #binary_template_spec, #binary_template_spec_file, #binary_template_spec_files, #clear_binary_spec_file_if_needed, #code_spec, #code_spec_files, #create_binary_spec_file, #find_spec_file, #spec_files

Methods included from CBin::SourcesHelper

#binary_source, #code_source, #sources_manager, #sources_option, #sources_optionV2, #valid_sources, #valid_sourcesV2

Constructor Details

#initialize(argv) ⇒ Archive

Returns a new instance of Archive.



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
# File 'lib/cocoapods-bb-bin/command/bin/archive.rb', line 45

def initialize(argv)
  @env = argv.option('env') || 'dev'
  CBin.config.set_configuration_env(@env)
  UI.puts "====== cocoapods-bb-bin #{CBin::VERSION} 版本 #{@env} 环境 ========".yellow

  @code_dependencies = argv.flag?('code-dependencies')
  @framework_output = argv.flag?('framework-output', false )
  @xcframework_output = argv.flag?('xcframework-output', false )
  @xcframework_dylib_output = argv.flag?('xcframework-dylib-output', false )
  @support_maccatalyst = argv.flag?('support_maccatalyst', false )
  @clean = argv.flag?('no-clean', false)
  @zip = argv.flag?('zip', true)
  @all_make = argv.flag?('all-make', false )
  @sources = argv.option('sources') || []
  @platform = Platform.new(:ios)

  @config = argv.option('configuration', 'Release')

  @framework_path
  super

  @additional_args = argv.remainder!
  @build_finshed = false
  @spec_sources = @sources
  if @xcframework_output || @xcframework_dylib_output
    # 生存xcframework优先使用源码仓库\二进制仓库
    @spec_sources = "#{sources_optionV2(@code_dependencies, nil)},https:\/\/cdn.cocoapods.org"
  end
end

Class Method Details

.missing_binary_specs(missing_binary_specs) ⇒ Object

解析器传过来的



165
166
167
# File 'lib/cocoapods-bb-bin/command/bin/archive.rb', line 165

def Archive.missing_binary_specs(missing_binary_specs)
  @@missing_binary_specs = missing_binary_specs unless @build_finshed
end

.optionsObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cocoapods-bb-bin/command/bin/archive.rb', line 25

def self.options
  [
      ['--all-make', '对该组件的依赖库,全部制作为二进制组件'],
      ['--code-dependencies', '使用源码依赖'],
      ['--no-clean', '保留构建中间产物'],
      ['--sources', '私有源地址,多个用分号区分'],
      ['--framework-output', '输出framework文件'],
      ['--xcframework-output', '输出静态xcframework文件'],
      ['--xcframework-dylib-output', '输出动态xcframework文件'],
      ['--support_maccatalyst', '输出xcframework文件是否支持Mac Catalyst'],
      ['--no-zip', '不压缩静态库 为 zip'],
      ['--configuration', 'Build the specified configuration (e.g. Debug). Defaults to Release'],
      ['--env', "该组件上传的环境 %w[dev debug_iphoneos release_iphoneos]"]
  ].concat(Pod::Command::Gen.options).concat(super).uniq
end

Instance Method Details

#build_dependenciesObject



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
155
156
157
158
159
160
161
162
# File 'lib/cocoapods-bb-bin/command/bin/archive.rb', line 109

def build_dependencies
  @build_finshed = true
  #如果没要求,就清空依赖库数据
  sources_sepc = []
  @@missing_binary_specs.uniq.each do |spec|
    next if spec.name.include?('/')
    next if spec.name == @spec.name
    #过滤白名单
    next if CBin::Config::Builder.instance.white_pod_list.include?(spec.name)
    #过滤 git
    if spec.source[:git] && spec.source[:git]
      spec_git = spec.source[:git]
      spec_git_res = false
      CBin::Config::Builder.instance.ignore_git_list.each do |ignore_git|
        spec_git_res = spec_git.include?(ignore_git)
        break if spec_git_res
      end
      next if spec_git_res
    end
    UI.warn "#{spec.name}.podspec 带有 vendored_frameworks 字段,请检查是否有效!!!" if spec.attributes_hash['vendored_frameworks']
    next if spec.attributes_hash['vendored_frameworks'] && @spec.name != spec.name #过滤带有vendored_frameworks的
    next if spec.attributes_hash['ios.vendored_frameworks'] && @spec.name != spec.name #过滤带有vendored_frameworks的
    #获取没有制作二进制版本的spec集合
    sources_sepc << spec
  end

  fail_build_specs = []
  sources_sepc.uniq.each do |spec|
    begin
      builder = CBin::Build::Helper.new(spec,
                                        @platform,
                                        @framework_output,
                                        @xcframework_output,
                                        @xcframework_dylib_output,
                                        @support_maccatalyst,
                                        @sources,
                                        @zip,
                                        @spec,
                                        false ,
                                        @config)
      builder.build
    rescue Object => exception
      UI.puts exception
      fail_build_specs << spec
    end
  end

  if fail_build_specs.any?
    fail_build_specs.uniq.each do |spec|
      UI.warn "#{spec.name} | #{spec.version}】组件二进制版本编译失败 ."
    end
  end
  sources_sepc - fail_build_specs
end

#build_root_specObject



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/cocoapods-bb-bin/command/bin/archive.rb', line 93

def build_root_spec
  builder = CBin::Build::Helper.new(@spec,
                                    @platform,
                                    @framework_output,
                                    @xcframework_output,
                                    @xcframework_dylib_output,
                                    @support_maccatalyst,
                                    @spec_sources,
                                    @zip,
                                    @spec,
                                    CBin::Config::Builder.instance.white_pod_list.include?(@spec.name),
                                    @config)
  builder.build
  builder.clean_workspace if @clean && !@all_make
end

#runObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/cocoapods-bb-bin/command/bin/archive.rb', line 75

def run
  # 清除之前的缓存
  CBin::Config::Builder.instance.clean

  @spec = Specification.from_file(spec_file)
  generate_project

  swift_pods_buildsetting

  build_root_spec
  # 生成podspec
  sources_sepc = Array.new
  sources_sepc << @spec
  sources_sepc.concat(build_dependencies) if @all_make

  return sources_sepc
end