Class: Pod::Command::Bin::Auto

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

Class Method Summary collapse

Instance Method Summary collapse

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) ⇒ Auto

Returns a new instance of Auto.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/cocoapods-bb-bin/command/bin/auto.rb', line 32

def initialize(argv)
  @help = argv.flag?('help', false )
  if @help
  else
    @env = argv.option('env') || 'dev'
    CBin.config.set_configuration_env(@env)
  
    # podfile_path = link_podfile # 创建软链接 去除link操作 by hm 21/11/24
    @podspec = argv.shift_argument || find_podspec
    @specification = Specification.from_file(@podspec)
  
    @code_dependencies = argv.flag?('code-dependencies')
    @allow_prerelease = argv.flag?('allow-prerelease')
    @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', true )
    @pushsourcespec = argv.flag?('all-push', false )
    @clean = argv.flag?('clean', true)
    @zip = argv.flag?('zip', true)
    @all_make = argv.flag?('all-make', false )
    @verbose = argv.flag?('verbose',true)
  
    @config = argv.option('configuration', 'Debug')
    @additional_args = argv.remainder!
  end
  super
end

Class Method Details

.optionsObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/cocoapods-bb-bin/command/bin/auto.rb', line 15

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

Instance Method Details

#binary_podsepc_jsonObject



167
168
169
# File 'lib/cocoapods-bb-bin/command/bin/auto.rb', line 167

def binary_podsepc_json
  "#{@specification.name}.binary.podspec.json"
end

#binary_template_podsepcObject



171
172
173
# File 'lib/cocoapods-bb-bin/command/bin/auto.rb', line 171

def binary_template_podsepc
  "#{@specification.name}.binary-template.podspec"
end

#code_podsepc_extnameObject



163
164
165
# File 'lib/cocoapods-bb-bin/command/bin/auto.rb', line 163

def code_podsepc_extname
  '.podsepc'
end

#find_podspecObject

Dir.glob 可替代

Raises:

  • (Informative)


209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/cocoapods-bb-bin/command/bin/auto.rb', line 209

def find_podspec
  name = nil
  Pathname.pwd.children.each do |child|
    # puts child
    if File.file?(child)
      if child.extname == '.podspec' || child.basename.to_s.include?('.podspec.json')
        name = File.basename(child)
        unless name.include?("binary-template")
          return name
        end
      end
    end
  end
  raise Informative,  "podspec File no exist, please check" unless name
  return name
end

#runObject



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

def run
  # 配置二进制库环境,需要区分静态库还是动态库
  if @xcframework_output || @xcframework_dylib_output
    isGenDylib = @xcframework_dylib_output
    sources_manager = Pod::Config.instance.sources_manager
    sources_manager.initLibEnv(isGenDylib)
    source = sources_manager.binary_source
    UI.puts "push run source:#{source}"
  end

  @specification = Specification.from_file(@podspec)

  sources_sepc = run_archive

  fail_push_specs = []
  sources_sepc.uniq.each do |spec|
    begin
      fail_push_specs << spec unless CBin::Upload::Helper.new(spec,@code_dependencies,@sources,@pushsourcespec).upload(@xcframework_dylib_output)
    rescue  Object => exception
      UI.puts exception
      fail_push_specs << spec
    end
  end

  if fail_push_specs.any?
    fail_push_specs.uniq.each do |spec|
      UI.warn "#{spec.name} | #{spec.version}】组件spec push失败 ."
    end
  end

  success_specs = sources_sepc - fail_push_specs
  if success_specs.any?
    auto_success = ""
    success_specs.uniq.each do |spec|
      auto_success += "#{spec.name} | #{spec.version}\n"
      UI.warn "===【 #{spec.name} | #{spec.version} 】二进制组件制作完成 !!! "
    end
    puts auto_success
    ENV['auto_success'] = auto_success
  end
  #pod repo update
  UI.section("\nUpdating Spec Repositories\n".yellow) do
    Pod::Command::Bin::Repo::Update.new(CLAide::ARGV.new([])).run
  end

end

#run_archiveObject

制作二进制包



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

def run_archive
  argvs = [
      "--sources=#{sources_option(@code_dependencies, @sources)},https:\/\/cdn.cocoapods.org",
      @additional_args
  ]

  argvs << spec_file if spec_file
  argvs.delete(Array.new)

  unless @clean
    argvs += ['--no-clean']
  end
  if @code_dependencies
    argvs += ['--code-dependencies']
  end
  if @verbose
    argvs += ['--verbose']
  end
  if @allow_prerelease
    argvs += ['--allow-prerelease']
  end
  if @framework_output
    argvs += ['--framework-output']
  end
  if @xcframework_output
    argvs += ['--xcframework-output']
  end
  if @xcframework_dylib_output
    argvs += ['--xcframework-dylib-output']
  end
  if @support_maccatalyst
    argvs += ['--support_maccatalyst']
  end
  if @all_make
    argvs += ['--all-make']
  end
  if @env
    argvs += ["--env=#{@env}"]
  end
  argvs += ["--configuration=#{@config}"]
  # puts "===auto argvs: #{argvs}"
  archive = Pod::Command::Bin::Archive.new(CLAide::ARGV.new(argvs))
  archive.validate!
  sources_sepc = archive.run
  return sources_sepc
end

#spec_fileObject



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/cocoapods-bb-bin/command/bin/auto.rb', line 185

def spec_file
  @spec_file ||= begin
                   if @podspec
                     find_spec_file(@podspec) || @podspec
                   else
                     if code_spec_files.empty?
                       raise Informative, '当前目录下没有找到可用源码 podspec.'
                     end

                     spec_file = if @binary
                                   code_spec = Pod::Specification.from_file(code_spec_files.first)
                                   if template_spec_file
                                     template_spec = Pod::Specification.from_file(template_spec_file)
                                   end
                                   create_binary_spec_file(code_spec, template_spec)
                                 else
                                   code_spec_files.first
                                 end
                     spec_file
                   end
                 end
end

#template_spec_fileObject



175
176
177
178
179
180
181
182
183
# File 'lib/cocoapods-bb-bin/command/bin/auto.rb', line 175

def template_spec_file
  @template_spec_file ||= begin
                            if @template_podspec
                              find_spec_file(@template_podspec)
                            else
                              binary_template_spec_file
                            end
                          end
end

#validate!Object



61
62
63
64
# File 'lib/cocoapods-bb-bin/command/bin/auto.rb', line 61

def validate!
  help! "未找到 podspec文件" unless @podspec
  super
end