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
100
101
102
103
104
105
106
# 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)
        # 目录下文件为空不处理
        next if Dir["#{file_path}/*"].empty?

        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]
        
        # lockfile中没有则跳过
        next unless lockfile.internal_data["SPEC CHECKSUMS"].include?(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 = "            \#{index}). \#{name}:\n                    multiple configuration: \#{hash[:multiple_configuration]}\n                    checksum\#{\"\uFF08git commitid\uFF09\" if is_git_commitid}: \#{hash[:checksum]}\n            LOG\n            Pod::UI.puts log\n        else\n            index += 1\n            log = <<~LOG\n            \#{index}). \#{name}:\n                    multiple configuration: \#{hash[:multiple_configuration]}\n                    checksum: \#{hash[:checksum]}\n                    checksum in lockfile\#{\"\uFF08git commitid\uFF09\" if is_git_commitid}: \#{checksum}\n                    checksum file count: \#{hash[:checksum_count]}\n            LOG\n            Pod::UI.puts log.red\n        end\n    end\n    Pod::UI.puts \"checksum\u6821\u9A8C\u5931\u8D25\u7684\u7EC4\u4EF6: \#{failed}\".red if failed.size > 0\n    Pod::UI.puts \"\u5EFA\u8BAE\u4F7F\u7528\u547D\u4EE4\u6E05\u9664prebuild\u7F13\u5B58\uFF0C\u518D\u91CD\u65B0pod install\u6216\u4F7F\u7528pod jxedt binary build\u3002clean\u547D\u4EE4\uFF1A`pod jxedt binary clean --name=\#{failed.join(',')}`\".red if failed.size > 0\nend\n"

#validate!Object



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

def validate!
    super
end