Class: CBin::BuildAll::PodspecUtil

Inherits:
Object
  • Object
show all
Includes:
Pod
Defined in:
lib/cocoapods-meitu-bin/helpers/buildAll/podspec_util.rb

Instance Method Summary collapse

Methods included from Pod

match_version?

Constructor Details

#initialize(pod_target, version, build_as_framework = false, configuration = 'Debug', options = {}) ⇒ PodspecUtil

Returns a new instance of PodspecUtil.



7
8
9
10
11
12
13
# File 'lib/cocoapods-meitu-bin/helpers/buildAll/podspec_util.rb', line 7

def initialize(pod_target, version, build_as_framework = false, configuration = 'Debug', options = {})
  @pod_target = pod_target
  @version = version
  @build_as_framework = build_as_framework
  @configuration = configuration
  @subspec_root_payload_white_list = Array(options[:subspec_root_payload_white_list]).compact
end

Instance Method Details

#create_binary_podspecObject

创建二进制podspec



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cocoapods-meitu-bin/helpers/buildAll/podspec_util.rb', line 16

def create_binary_podspec
  UI.info "创建二进制podspec:`#{@pod_target}`".yellow
  spec = @pod_target.root_spec.to_hash
  root_dir = @pod_target.framework_name
  # 处理版本号
  spec['version'] = version
  # 处理source
  spec['source'] = source
  # 处理头文件
  spec['source_files'] = "#{root_dir}/Headers/*.h"
  spec['public_header_files'] = "#{root_dir}/Headers/*.h"
  spec['private_header_files'] = "#{root_dir}/PrivateHeaders/*.h"
  # 处理vendored_libraries和vendored_frameworks
  spec['vendored_libraries'] = "#{root_dir}/libs/*.a"
  #兼容.xcframework
  spec['vendored_frameworks'] = %W[#{root_dir} #{root_dir}/fwks/*.{framework,xcframework}]
  # 处理资源
  resources = %W[#{root_dir}/*.{#{special_resource_exts.join(',')}} #{root_dir}/resources/*]
  spec['resources'] = resources
  # 删除无用的字段
  delete_unused(spec)
  # 处理subspecs
  handle_subspecs(spec)
  # 生成二进制podspec
  bin_spec = Pod::Specification.from_hash(spec)
  bin_spec.description = <<-EOF
   「converted automatically by plugin cocoapods-meitu-bin @美图 - zys」
    #{bin_spec.description}
  EOF
  bin_spec
  # puts bin_spec.to_json
end

#push_binary_podspec(binary_podsepc_json) ⇒ Object

上传二进制podspec



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
# File 'lib/cocoapods-meitu-bin/helpers/buildAll/podspec_util.rb', line 63

def push_binary_podspec(binary_podsepc_json)
  UI.info "推送podspec:`#{@pod_target}`".yellow
  return unless File.exist?(binary_podsepc_json)
  repo_name = Pod::Config.instance.sources_manager.binary_source.name
  # repo_name = 'example-private-spec-bin'
  argvs = %W[#{repo_name} #{binary_podsepc_json} --skip-import-validation --use-libraries --allow-warnings --verbose]
  
  start_time = Time.now
  timeout = ENV['PODSPEC_PUSH_TIMEOUT'] ? ENV['PODSPEC_PUSH_TIMEOUT'].to_i : 15 # Default 15 seconds timeout
  last_error = nil

  while (Time.now - start_time) < timeout
    begin
      push = Pod::Command::Repo::Push.new(CLAide::ARGV.new(argvs))
      push.validate!
      push.run
      return true
    rescue Pod::StandardError => e
      last_error = e
      remaining_time = timeout - (Time.now - start_time)
      if remaining_time > 0
        UI.info "推送podspec:`#{@pod_target}`失败,将在#{remaining_time.round(1)}秒后重试,错误:#{e.to_s}".yellow
        sleep(1) # Wait 1 second before retrying
      end
    end
  end

  UI.info "推送podspec:`#{@pod_target}`失败,已超过#{timeout}秒重试时间,跳过此次处理,错误:#{last_error.to_s}".red
  return false
end

#write_binary_podspec(spec) ⇒ Object

podspec写入文件



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cocoapods-meitu-bin/helpers/buildAll/podspec_util.rb', line 50

def write_binary_podspec(spec)
  UI.info "写入podspec:`#{@pod_target}`".yellow
  podspec_dir = PodUpdateConfig.shell_project ? "#{Pathname.pwd}/all_build/Build/Products/podspec" : "#{Pathname.pwd}/build_pods/#{@pod_target}/Products/podspec"
  FileUtils.mkdir_p(podspec_dir) unless File.exist?(podspec_dir)
  file = "#{podspec_dir}/#{@pod_target.pod_name}.podspec.json"
  FileUtils.rm_rf(file) if File.exist?(file)
  File.open(file, "w+") do |f|
    f.write(spec.to_pretty_json)
  end
  file
end