Class: PodsOrz::BinaryBuilder
- Inherits:
-
Object
- Object
- PodsOrz::BinaryBuilder
- Defined in:
- lib/podsorz/core/Binary/binary_builder.rb
Instance Attribute Summary collapse
-
#http_host ⇒ Object
Returns the value of attribute http_host.
-
#kx_binary_path ⇒ Object
Returns the value of attribute kx_binary_path.
-
#main_path ⇒ Object
Returns the value of attribute main_path.
-
#pod_repo ⇒ Object
Returns the value of attribute pod_repo.
-
#podfile_io ⇒ Object
Returns the value of attribute podfile_io.
-
#remote_binary_directory ⇒ Object
Returns the value of attribute remote_binary_directory.
Instance Method Summary collapse
- #build_static_library(pod) ⇒ Object
- #check_directory ⇒ Object
-
#copy_podspec(pod) ⇒ Object
copy.
- #delete_build_files(pod) ⇒ Object
-
#detect_kx_binary ⇒ Object
detect.
- #detect_pod_directory(pod) ⇒ Object
- #detect_version_directory(pod, pod_version) ⇒ Object
-
#initialize(main_path, podfile_io) ⇒ BinaryBuilder
constructor
A new instance of BinaryBuilder.
- #mv_embedded_framework(pod) ⇒ Object
- #override_podspec(pod) ⇒ Object
- #start_package_pod(pod) ⇒ Object
- #zip_framework(pod) ⇒ Object
Constructor Details
#initialize(main_path, podfile_io) ⇒ BinaryBuilder
Returns a new instance of BinaryBuilder.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 11 def initialize(main_path, podfile_io) @main_path = main_path @kx_binary_path = File.("../kx_binary", main_path) @podfile_io = podfile_io @pod_repo = PodsOrz::PodsRepo.new(main_path) @http_host = "http://192.168.6.127:8899" @remote_binary_directory = "binary_pod" end |
Instance Attribute Details
#http_host ⇒ Object
Returns the value of attribute http_host.
9 10 11 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 9 def http_host @http_host end |
#kx_binary_path ⇒ Object
Returns the value of attribute kx_binary_path.
9 10 11 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 9 def kx_binary_path @kx_binary_path end |
#main_path ⇒ Object
Returns the value of attribute main_path.
9 10 11 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 9 def main_path @main_path end |
#pod_repo ⇒ Object
Returns the value of attribute pod_repo.
9 10 11 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 9 def pod_repo @pod_repo end |
#podfile_io ⇒ Object
Returns the value of attribute podfile_io.
9 10 11 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 9 def podfile_io @podfile_io end |
#remote_binary_directory ⇒ Object
Returns the value of attribute remote_binary_directory.
9 10 11 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 9 def remote_binary_directory @remote_binary_directory end |
Instance Method Details
#build_static_library(pod) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 135 def build_static_library(pod) is_build_success = true command = Thread.new do pod_version = @podfile_io.get_podfile_pod_version(pod) dest_dir = detect_version_directory(pod, pod_version) dest_file_path = File.("#{pod}.podspec", dest_dir) cmd_list = [] cmd_list << "cd #{dest_dir}" cmd_list << "pod package #{pod}.podspec --exclude-deps --no-mangle --force --embedded [email protected]:ios_pods/Specs.git" Open3.popen3(cmd_list.join(";")) do |stdin , stdout , stderr, wait_thr| while line = stdout.gets puts line end end end command.join is_build_success end |
#check_directory ⇒ Object
91 92 93 94 95 96 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 91 def check_directory() is_directory = File.directory?(@main_path) Logger.error("Detect failure, it is not a directory path: #{@main_path}") unless is_directory is_directory end |
#copy_podspec(pod) ⇒ Object
copy
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 119 def copy_podspec(pod) command = Thread.new do pod_version = @podfile_io.get_podfile_pod_version(pod) source_podspec_dir = @pod_repo.directory_pod_version(pod, pod_version) source_file_path = File.("#{pod}.podspec", source_podspec_dir) dest_dir = detect_version_directory(pod, pod_version) dest_file_path = File.("#{pod}.podspec", dest_dir) `cp -f #{source_file_path} #{dest_file_path}` Logger.highlight("Copy file Success.\n Source file path:#{source_file_path} \n dest_file_path:#{dest_file_path}") end command.join end |
#delete_build_files(pod) ⇒ Object
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 292 def delete_build_files(pod) command = Thread.new do pod_version = @podfile_io.get_podfile_pod_version(pod) origin_spec_dir = detect_version_directory(pod, pod_version) package_dir_name = "#{pod}-#{pod_version}" cmd_list = [] cmd_list << "cd #{origin_spec_dir}" cmd_list << "rm -f -r #{package_dir_name}" IO.popen(cmd_list.join(";")) do |io| io.close end end command.join end |
#detect_kx_binary ⇒ Object
detect
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 78 def detect_kx_binary() result = check_directory() if result binary_result = File.directory?(@kx_binary_path) unless binary_result Logger.warning("kx_binary directory not exist, generate default 'kx_binary' directory") FileUtils.mkdir_p(@kx_binary_path, :mode => 0777) end end end |
#detect_pod_directory(pod) ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 98 def detect_pod_directory(pod) pod_path = File.("#{pod}", @kx_binary_path) pod_result = File.directory?(pod_path) unless pod_result Logger.warning("#{pod_path} directory not exist, generate default '#{pod_path}' directory") FileUtils.mkdir_p(pod_path, :mode => 0777) end end |
#detect_version_directory(pod, pod_version) ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 107 def detect_version_directory(pod, pod_version) pod_version_path = File.("#{pod}/#{pod_version}", @kx_binary_path) pod_version_result = File.directory?(pod_version_path) unless pod_version_result Logger.warning("#{pod_version_path} directory not exist, generate default '#{pod_version_path}' directory") FileUtils.mkdir_p(pod_version_path, :mode => 0777) end pod_version_path end |
#mv_embedded_framework(pod) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 187 def (pod) is_mv_success = true command = Thread.new do pod_version = @podfile_io.get_podfile_pod_version(pod) origin_spec_dir = detect_version_directory(pod, pod_version) package_dir = File.("#{pod}-#{pod_version}", origin_spec_dir) = File.("ios/#{pod}.embeddedframework", package_dir) cmd_list = [] cmd_list << "cd #{}" cmd_list << "mv -f #{pod}.framework.zip #{origin_spec_dir}" IO.popen(cmd_list.join(";")) do |io| io_lines = io.readlines io_lines.each do |line| puts line is_mv_success = false if line.include? "mv:" end io.close end end command.join is_mv_success end |
#override_podspec(pod) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 215 def override_podspec(pod) is_override_success = true command = Thread.new do pod_version = @podfile_io.get_podfile_pod_version(pod) origin_spec_dir = detect_version_directory(pod, pod_version) origin_spec_file_path = File.("#{pod}.podspec", origin_spec_dir) origin_podspec_model = PodsOrz::PodspecModel.new(origin_spec_file_path) package_dir = File.("#{pod}-#{pod_version}", origin_spec_dir) static_pod_spec_path = File.("#{pod}.podspec", package_dir) static_podspec_totoal_sentences = [] File.open(static_pod_spec_path, "r") {|io| static_podspec_totoal_sentences = io.readlines } File.open(static_pod_spec_path, "w+") {|io| static_podspec_totoal_sentences.each do |sentence| sentence_content = sentence.strip.chomp.to_s is_sentence_content_empty = sentence_content.empty? is_sentence_content_size_zero = sentence_content.size.zero? unless is_sentence_content_empty || is_sentence_content_size_zero unless sentence_content.start_with?("#") mt = /.*s.source = /.match(sentence) unless mt.nil? sentence = mt[0] + "{:http => \'#{@http_host}/#{remote_binary_directory}/#{pod}/#{pod_version}/#{pod}.framework.zip\'}" end mt = /.*s.ios.vendored_framework = /.match(sentence) #behind vendored_framework add extra lines unless mt.nil? sentence = mt[0] + "\'#{pod}.framework\'" + "\n" #add Resource if origin_podspec_model.have_resources sentence += " " + "s.resources = \'#{pod}.framework/Versions/A/Resources/*.{png,bundle,xib}\'" + "\n\n" end #add dependency origin_podspec_model.dependency_list.each do |d| sentence += " " + "s.dependency " + "#{d}" + "\n" end sentence += "\n" end end end io.write(sentence.chomp + "\n") end } cmd_list = [] cmd_list << "cd #{package_dir}" cmd_list << "mv -f #{pod}.podspec #{origin_spec_dir}" IO.popen(cmd_list.join(";")) do |io| io_lines = io.readlines io_lines.each do |line| puts line is_override_success = false if line.include? "mv:" end io.close end end command.join is_override_success end |
#start_package_pod(pod) ⇒ Object
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 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 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 22 def start_package_pod(pod) is_package_success = true #1.创建kx_binary detect_kx_binary() #2.创建Pod文件夹 detect_pod_directory(pod) #3.创建version文件夹 pod_version = @podfile_io.get_podfile_pod_version(pod) detect_version_directory(pod, pod_version) #4.copy kuxiu_specs中对应的podspec copy_podspec(pod) #5.build static library is_build_success = build_static_library(pod) unless is_build_success Logger.error("【#{pod}】build version:#{pod_version} static library failure!") is_package_success = false return is_package_success end #6.zip framework is_zip_success = zip_framework(pod) unless is_zip_success Logger.error("【#{pod}】zip framework failure!") is_package_success = false return is_package_success end #7.mv framework is_mv_success = (pod) unless is_mv_success Logger.error("【#{pod} mv #{pod}.framework.zip failure!") is_package_success = false return is_package_success end #8.override .podspec is_override_success = override_podspec(pod) unless is_override_success Logger.error("【#{pod} mv #{pod}.podspec failure!") is_package_success = false return is_package_success end #9.delete build files delete_build_files(pod) is_package_success end |
#zip_framework(pod) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/podsorz/core/Binary/binary_builder.rb', line 158 def zip_framework(pod) is_zip_success = true command = Thread.new do pod_version = @podfile_io.get_podfile_pod_version(pod) origin_spec_dir = detect_version_directory(pod, pod_version) package_dir = File.("#{pod}-#{pod_version}", origin_spec_dir) = File.("ios/#{pod}.embeddedframework", package_dir) cmd_list = [] cmd_list << "cd #{}" cmd_list << "zip -q -r -y -o #{pod}.framework.zip #{pod}.framework" IO.popen(cmd_list.join(";")) do |io| io_lines = io.readlines io_lines.each do |line| puts line is_zip_success = false if line.include? "zip error" end io.close end end command.join is_zip_success end |