module Pod class Command class JxedtCommand < Command class Statistics < JxedtCommand self.summary = '统计二进制使用情况' self.description = <<-DESC 统计二进制使用详情 DESC self.command = 'statistics' self.arguments = [ ] def self.options [ ['--failed', '统计校验失败的二进制'], ] end def initialize(argv) @check_failed = argv.flag?('failed') super end def validate! super end def run podfile = Pod::Config.instance.podfile lockfile = Pod::Config.instance.lockfile help! '请检查命令执行路径,需要在Podfile文件所在目录执行' if podfile.nil? || lockfile.nil? require 'cocoapods-jxedt/binary/config' require 'cocoapods-jxedt/binary/helper/podfile_options' pods_root = Pathname.new(File.dirname(podfile.defined_in_file)) + "Pods" binary_dir = pods_root + Jxedt.config.binary_dir used_binary = [] Dir.glob("#{pods_root}/*/_Prebuild") do |file_path| next unless File.directory?(file_path) dir_name = File.dirname(file_path) name = File.basename(dir_name).to_s target_path = binary_dir + name next unless target_path.exist? # 路径不存在,跳过 new_hash = {} # name new_hash[:name] = name # multiple_configuration configuration_enable = target_path.children().select { |path| "#{path.basename}" == 'Debug' || "#{path.basename}" == 'Release' }.count == 2 new_hash[:multiple_configuration] = configuration_enable # checksum validation checksum_file = target_path.children().select { |path| path.extname == '.checksum' }.first new_hash[:checksum] = checksum_file.basename.to_s.gsub('.checksum', '') unless checksum_file.nil? used_binary << new_hash end # print index, failed = 0, [] used_binary.sort_by {|hash| hash[:name].capitalize }.each do |hash| name = hash[:name] checksum = lockfile.spec_checksums_hash_key(name) validation_passed = checksum && checksum == hash[:checksum] failed << name unless validation_passed # 校验和是否用的 git commitid checkout_options = lockfile.internal_data["CHECKOUT OPTIONS"] || {} is_git_commitid = checkout_options[name] && checkout_options[name][:commit] if validation_passed next if @check_failed index += 1 log = <<~LOG #{index}). #{name}: multiple configuration: #{hash[:multiple_configuration]} checksum#{"(git commitid)" if is_git_commitid}: #{hash[:checksum]} LOG Pod::UI.puts log else index += 1 log = <<~LOG #{index}). #{name}: multiple configuration: #{hash[:multiple_configuration]} checksum: #{hash[:checksum]} checksum in lockfile#{"(git commitid)" if is_git_commitid}: #{checksum} LOG Pod::UI.puts log.red end end Pod::UI.puts "checksum校验失败的组件: #{failed}".red if failed.size > 0 end end end end end