Class: Pod::Command::JxedtCommand::Binary::Statistics

Inherits:
Pod::Command::JxedtCommand::Binary show all
Defined in:
lib/cocoapods-jxedt/command/binary/command/statistics.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Statistics

Returns a new instance of Statistics.



18
19
20
21
# File 'lib/cocoapods-jxedt/command/binary/command/statistics.rb', line 18

def initialize(argv)
    @check_failed = argv.flag?('failed')
    super
end

Class Method Details

.optionsObject



13
14
15
16
17
# File 'lib/cocoapods-jxedt/command/binary/command/statistics.rb', line 13

def self.options
    [
        ['--failed', '统计校验失败的二进制'],
    ]
end

Instance Method Details

#runObject



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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/cocoapods-jxedt/command/binary/command/statistics.rb', line 27

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_files = target_path.children().select { |path| path.extname == '.checksum' }
        checksum_file = checksum_files.first
        new_hash[:checksum] = checksum_file.basename.to_s.gsub('.checksum', '') unless checksum_file.nil?
        new_hash[:checksum_count] = checksum_files.count

        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] && hash[:checksum_count] == 1
        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}
                    checksum file count: #{hash[:checksum_count]}
            LOG
            Pod::UI.puts log.red
        end
    end
    Pod::UI.puts "checksum校验失败的组件: #{failed}".red if failed.size > 0
    Pod::UI.puts "建议使用命令清除prebuild缓存,再重新pod install或使用pod jxedt binary build。clean命令:`pod jxedt binary clean --name=#{failed.join(',')}`".red if failed.size > 0
end

#validate!Object



23
24
25
# File 'lib/cocoapods-jxedt/command/binary/command/statistics.rb', line 23

def validate!
    super
end