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

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Statistics

Returns a new instance of Statistics.



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

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

Class Method Details

.optionsObject



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

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

Instance Method Details

#runObject



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

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] }.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

#validate!Object



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

def validate!
    super
end