Class: PPL::Binary

Inherits:
Object
  • Object
show all
Defined in:
lib/pod-pipeline/util/binary.rb

Class Method Summary collapse

Class Method Details

.combine(output, inputs, include_list = [], exclude_list = []) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
# File 'lib/pod-pipeline/util/binary.rb', line 3

def self.combine(output, inputs, include_list=[], exclude_list=[])
    puts "\n目标文件:#{output}\n"

    #获取合并文件的路径序列
    input_file_queue=""
    inputs.each do |input|
        puts "\n合并路径:#{input}"

        Dir[input].each do |input_file|
            #若 input_file 为目录 则跳过
            next if Dir.exists? input_file
            #若 input_file 为非二进制文件 则跳过
            info_log = `lipo -info "#{input_file}" > /dev/null 2>&1
            echo result:$?`
            next unless info_log.include? 'result:0'
            #若 input_file 非被include标记的文件 则跳过
            unless include_list.empty?
                is_include = false
                include_list.each { |include|
                    input_file_basename = File.basename(input_file)
                    include_basename = File.basename(include)
                    if input_file_basename == include_basename || input_file_basename == "lib#{include_basename}.a"
                        is_include = true
                        break
                    end
                }
                next unless is_include
            end
            #若 input_file 为被exclude标记的文件 则跳过
            unless exclude_list.empty?
                is_exclude = false
                exclude_list.each { |exclude|
                    input_file_basename = File.basename(input_file)
                    exclude_basename = File.basename(exclude)
                    if input_file_basename == exclude_basename || input_file_basename == "lib#{exclude_basename}.a"
                        is_exclude = true
                        break
                    end
                }
                next if is_exclude
            end
            #若 input_file 为序列中已存在的文件 则跳过
            next if input_file_queue.include? input_file

            #合并
            puts "=> #{input_file}"
            input_file_queue += " \"#{input_file}\""
        end
    end

    #若合并文件序列不为空,执行合并
    unless input_file_queue.empty?
        if File.exists? output
            output_temp = output+'.temp'
            File.rename(output, output_temp)

            combine_log = 
            `libtool -static -o "#{output}" "#{output_temp}" #{input_file_queue} > /dev/null 2>&1
            echo result:$?`
            raise "\ncombine log:\n#{combine_log}" unless combine_log.include? 'result:0'
            
            File.delete(output_temp)
        else
            combine_log = 
            `libtool -static -o "#{output}" #{input_file_queue} > /dev/null 2>&1
            echo result:$?`
            raise "\ncombine log:\n#{combine_log}" unless combine_log.include? 'result:0'
        end
    end 
end

.thin(binary, archs) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/pod-pipeline/util/binary.rb', line 74

def self.thin(binary, archs)
    archs.each do |arch|
        thin_log = 
        `lipo "#{binary}" -thin #{arch} -output "#{binary}-#{arch}" > /dev/null 2>&1
        echo result:$?`
        unless thin_log.include? 'result:0'
            puts "lipo #{binary} -thin #{arch} 异常"
            return 
        end
    end
    File.delete(binary) if File.exist? binary

    binary_pieces = "#{binary}-*"
    combine(binary, [binary_pieces])
    
    Dir[binary_pieces].each do |binary_piece|
        File.delete(binary_piece)
    end
end