Class: Build::RepoModuleBinary

Inherits:
RepoModule show all
Defined in:
lib/core_blur/repo_module_binary.rb

Instance Attribute Summary collapse

Attributes inherited from RepoModule

#build_item, #framework_name, #pod_name, #pod_version, #pod_version_final, #podspec_content, #podspec_json_path, #project_id, #snapshot, #third

Attributes inherited from Repo

#branch, #gitlab_helper, #http_url, #last_commit, #page_url, #path, #pusher, #repo_path, #size, #size_format, #ssh_url, #user_email, #user_name

Instance Method Summary collapse

Methods inherited from RepoModule

#analyzer, #build_binary, #get_commit_msg, #git_clone, #git_commit, #initialize, #update_binary, #validate

Methods inherited from Repo

#clear, #discard_pull, #git_add_stag, #git_checkout, #git_clone, #git_commit, #git_fetch, #git_pull, #git_push, #git_push_f, #git_push_tags, #git_reset_hard, #git_status, #git_tag_delete_local, #git_tag_delete_origin, #git_tag_local, #git_tag_origin, #initialize, #push_code

Constructor Details

This class inherits a constructor from Build::RepoModule

Instance Attribute Details

#framework_binary_pathObject

Returns the value of attribute framework_binary_path.



7
8
9
# File 'lib/core_blur/repo_module_binary.rb', line 7

def framework_binary_path
  @framework_binary_path
end

Instance Method Details

#copy_framework(repo_xcode_package, repo_module_source) ⇒ Object



8
9
10
11
12
13
14
15
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
# File 'lib/core_blur/repo_module_binary.rb', line 8

def copy_framework(repo_xcode_package, repo_module_source)
  build_real_device = build_item.real_device
  build_simulator = build_item.simulator
  if not build_real_device and not build_simulator
    return
  end
  @framework_name = repo_module_source.framework_name
  origin_framework_real_device = "#{repo_xcode_package.real_device_archive_path}/Products/Library/Frameworks/#{framework_name}.framework"
  origin_framework_simulator = "#{repo_xcode_package.simulator_archive_path}/Products/Library/Frameworks/#{framework_name}.framework"
  if build_real_device and not File.exist?(origin_framework_real_device)
    error = "真机架构framework不存在"
    pusher.push("❌ 打包失败", error)
    Process.exit(-1)
  end
  if build_simulator and not File.exist?(origin_framework_simulator)
    error = "模拟器架构framework不存在"
    pusher.push("❌ 打包失败", error)
    Process.exit(-1)
  end
  @framework_binary_path = "#{self.path}/#{framework_name}.xcframework"
  command = "xcodebuild -create-xcframework"
  if build_real_device
    command += " -framework \"#{origin_framework_real_device}\""
  end
  if build_simulator
    command += " -framework \"#{origin_framework_simulator}\""
  end
  command += " -output \"#{framework_binary_path}\""
  puts "\n⏩ 合并并拷贝framework(#{File.basename(self.path)}): #{command}"
  res = system command
  unless res == true
    error = "合并framework失败"
    pusher.push("❌ 打包失败", error)
    Process.exit(-1)
  end
end

#copy_podspec(repo_xcode_package, repo_module_source) ⇒ Object



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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/core_blur/repo_module_binary.rb', line 77

def copy_podspec(repo_xcode_package, repo_module_source)
  build_real_device = build_item.real_device
  build_simulator = build_item.simulator
  if not build_real_device and not build_simulator
    return
  end
  puts "\n⏩ 拷贝podspec文件到framework中(#{File.basename(self.path)}):"
  @podspec_json_path = "#{self.path}/#{self.pod_name}.podspec.json"
  source_files_dir = build_real_device ? "*arm64*" : "*simulator*"
  @podspec_content = repo_module_source.podspec_content
  podspec_content.delete("license")
  podspec_content.delete("module_map")
  podspec_content.delete("public_header_files")
  podspec_content.delete("private_header_files")
  podspec_content.delete("exclude_files")
  podspec_content.delete("prefix_header_file")
  if pod_name == "libwebp" or pod_name == "libcmark"
    podspec_content.delete("prepare_command")
  end
  podspec_content["source"] = {} #二进制后, 只从tag读取,去除其他的标志信息
  podspec_content["source"]["git"] = self.ssh_url
  podspec_content["source"]["tag"] = self.pod_version_final
  podspec_content["source_files"] = "**/*/#{source_files_dir}/*.framework/Headers/*.h"
  podspec_content["version"] = self.pod_version_final
  podspec_content["vendored_frameworks"] = "*.xcframework"
  resources = podspec_content["resources"] ? podspec_content["resources"] : podspec_content["resource"]
  podspec_content["resources"] = []
  if resources
    podspec_content.delete("resource")
    resources_array = resources.class == Array ? resources : [resources]
    resources_array.each { |resource|
      resource_path = "#{repo_module_source.path}/#{resource}"
      Dir[resource_path].select{|real_path|
        resource_name = File.basename(real_path)
        podspec_content["resources"] << "**/*/#{source_files_dir}/*.framework/#{resource_name}"
      }
    }
  end
  resource_bundles = podspec_content["resource_bundles"] ? podspec_content["resource_bundles"] : podspec_content["resource_bundle"]
  if resource_bundles
    podspec_content.delete("resource_bundles")
    podspec_content.delete("resource_bundle")
    resource_bundles_array = resource_bundles.class == Array ? resource_bundles : [resource_bundles]
    resource_bundles_array.each { |resource_bundle|
      if resource_bundle.class == Hash
        resource_bundle.each_key {|key|
          podspec_content["resources"] << "**/*/#{source_files_dir}/*.framework/#{key}.bundle"
        }
      end
    }
  end
  podspec_content["resources"] << "**/*/#{source_files_dir}/*.framework/*.podspec.json"
  podspec_content["address"] = self.http_url
  podspec_content["frameworkSize"] = self.size_format
  podspec_content["archive"] = repo_xcode_package.debug_mode ? "Debug" : "Release"
  if podspec_content.has_key?("swift_version")
    podspec_content["pod_target_xcconfig"] = {"BUILD_LIBRARY_FOR_DISTRIBUTION": true}
  end
  subspecs = podspec_content["subspecs"]
  if subspecs.respond_to?(:each)
    subspecs.each do |subspec|
      subspec.delete("resources")
      subspec.delete("resource_bundles")
      subspec.delete("exclude_files")
      subspec.delete("public_header_files")
      subspec.delete("project_header_files")
      if subspec["ios"] and subspec["ios"].class == Hash
        sun = subspec["ios"]
        sun.delete("resources")
        sun.delete("resource_bundles")
        sun.delete("exclude_files")
        sun.delete("public_header_files")
        sun.delete("project_header_files")
        sun.delete("source_files")
      end
      subspec["source_files"] = "placeholder.m"
    end
  end
  new_file = File.new(podspec_json_path, "w+")
  if new_file
    new_file.syswrite(JSON.pretty_generate(podspec_content))
  end
  framework_real_device_path = "#{framework_binary_path}/ios-arm64/#{framework_name}.framework"
  if File.directory?(framework_real_device_path)
    FileUtils.cp(podspec_json_path, framework_real_device_path)
  end
  framework_simulator_path = "#{framework_binary_path}/ios-x86_64-simulator/#{framework_name}.framework"
  if File.directory?(framework_simulator_path)
    FileUtils.cp(podspec_json_path, framework_simulator_path)
  end
  puts "拷贝完成"
end

#copy_resources(repo_xcode_package, repo_module_source) ⇒ Object



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
# File 'lib/core_blur/repo_module_binary.rb', line 44

def copy_resources(repo_xcode_package, repo_module_source)
  puts "\n⏩ 拷贝资源文件到framework中(#{File.basename(self.path)}):"
  bundle_path_array = repo_xcode_package.resource_bundles_paths
  resource_paths = repo_xcode_package.resource_paths
  if bundle_path_array.length == 0
    puts "源码podspec里未指定resource_bundles"
  end
  if resource_paths.length == 0
    puts "源码podspec里未指定resource"
  end
  result_array = bundle_path_array + resource_paths
  puts "读取到的资源文件路径如下"
  puts result_array
  if result_array.length == 0
    puts "为空不拷贝"
    return
  end
  framework_path_array = Array.new
  framework = "#{repo_module_source.framework_name}.framework"
  FileHelper.recursion_find(self.path, framework, framework_path_array)
  puts "以上资源文件需要分别拷贝到如下路径中"
  puts framework_path_array
  framework_path_array.each { |framework_path|
    result_array.each { |bundle_path|
      bundle_name = File.basename(bundle_path)
      des_bundle_path = "#{framework_path}/#{bundle_name}"
      unless File.exist?(des_bundle_path)
        FileUtils.cp_r(bundle_path, framework_path)
      end
    }
  }
  puts "拷贝资源文件完成"
end

#git_tagObject



169
170
171
172
173
# File 'lib/core_blur/repo_module_binary.rb', line 169

def git_tag
  if build_item.real_device or build_item.simulator
    super
  end
end