Class: CBin::Config::Builder

Inherits:
Object
  • Object
show all
Includes:
Pod
Defined in:
lib/cocoapods-imy-bin/config/config_builder.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Pod

match_version?

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



13
14
15
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 13

def initialize
  load_build_config
end

Class Method Details

.instanceObject



9
10
11
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 9

def self.instance
  @instance ||= new
end

Instance Method Details

#binary_json_dirObject



100
101
102
103
104
105
106
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 100

def binary_json_dir
  @binary_json_dir ||= begin
                 dir = File.join(root_dir,binary_json_dir_name)
                 Dir.mkdir(dir) unless File.exist?dir
                 Pathname.new(dir)
               end
end

#binary_json_dir_nameObject



96
97
98
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 96

def binary_json_dir_name
  "bin-json"
end

#framework_file(spec) ⇒ Object



56
57
58
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 56

def framework_file(spec)
  File.join(zip_dir_name, framework_name(spec))
end

#framework_name(spec) ⇒ Object



52
53
54
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 52

def framework_name(spec)
  "#{spec.name}.framework"
end

#gen_dirObject

制作二进制打包 工程目录



44
45
46
47
48
49
50
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 44

def gen_dir
  @gen_dir ||= begin
                 dir = File.join(root_dir,gen_name)
                 Dir.mkdir(dir) unless File.exist?dir
                 Pathname.new(dir)
               end
end

#gen_nameObject

制作二进制打包 工程目录



39
40
41
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 39

def gen_name
  'bin-archive'
end

#ignore_git_listObject

忽略制作二进制组件的 git



169
170
171
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 169

def ignore_git_list
  @ignore_git_list
end

#ignore_http_listObject



173
174
175
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 173

def ignore_http_list
  @ignore_http_list
end

#library_file(spec) ⇒ Object



67
68
69
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 67

def library_file(spec)
  File.join(zip_dir_name, library_name(spec))
end

#library_name(spec) ⇒ Object



60
61
62
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 60

def library_name(spec)
  library_name_version(spec.name, spec.version)
end

#library_name_version(name, version) ⇒ Object



64
65
66
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 64

def library_name_version(name,version)
  "bin_#{name}_#{version}"
end

#load_build_configObject

加载配置项



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 18

def load_build_config
  @white_pod_list = []
  @ignore_git_list = []
  project_root = Pod::Config.instance.project_root
  path = File.join(project_root.to_s, 'BinArchive.json')

  if File.exist?(path)
    config = JSON.parse(File.read(path))
    @white_pod_list = config['archive-white-pod-list']
    UI.warn "====== archive-white-pod-list = #{@white_pod_list}" if @white_pod_list
    @ignore_git_list = config['ignore-git-list']
    UI.warn "====== ignore_git_list = #{@ignore_git_list}" if @ignore_git_list
    @ignore_http_list = config['ignore-http-list']

    @xcode_build_name = config['xcode_build_path']
    @root_dir = config['root_dir'] unless config['root_dir'].nil?
  end

end

#local_psec_dirObject



88
89
90
91
92
93
94
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 88

def local_psec_dir
  @local_psec_dir ||= begin
                         dir = File.join(root_dir,local_spec_dir_name)
                         Dir.mkdir(dir) unless File.exist?dir
                         Pathname.new(dir)
                       end
end

#local_spec_dir_nameObject

本地



84
85
86
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 84

def local_spec_dir_name
  "bin-spec"
end

#root_dirObject

处理编译产物后存储根目录,会存放spec、 json、zip的父目录,默认是工程的同级目录下,“#basename-build-temp”



153
154
155
156
157
158
159
160
161
162
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 153

def root_dir
  @root_dir ||= begin
                   basename = File.basename(Pod::Config.instance.installation_root)
                   parent_dir = File.dirname(Pod::Config.instance.installation_root)
                   root_name = File.join(parent_dir,"#{basename}-build-temp")
                   Dir.mkdir(root_name) unless File.exist?root_name
                   Pathname.new(root_name)
                 end

end

#target_nameObject

编译target名,如 seeyou



111
112
113
114
115
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 111

def target_name
  @target_name ||= begin
                     Pod::Config.instance.podfile.root_target_definitions.first.children.first.to_s.split('-').last
                   end
end

#white_pod_listObject

制作二进制 白名单



165
166
167
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 165

def white_pod_list
  @white_pod_list
end

#xcode_build_dirObject

完整的xcodebuild 输出路径



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 138

def xcode_build_dir
  @xcode_build_dir ||= begin
                          temp_xcode_build_name = xcode_build_name
                          if File.exist?(temp_xcode_build_name)
                              Pathname.new(temp_xcode_build_name)
                          else
                              dir = File.join(root_dir,xcode_build_name)
                              Pathname.new(dir)
                          end
                       end
end

#xcode_build_nameObject

编译缓存文件目录,如Xcodebuild的编译缓存目录如果有配置, 配置完整路径,会使用



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 119

def xcode_build_name
  @xcode_build_name ||= begin
                            project_root = Pod::Config.instance.project_root
                            path = File.join(project_root.to_s, 'BinArchive.json')

                            if File.exist?(path)
                              config = JSON.parse(File.read(path))
                              @xcode_build_name = config['xcode_build_path']
                            end
                            #默认值,在美柚上使用默认
                            if @xcode_build_name.nil? || Dir.exist?(@xcode_build_name)
                              @xcode_build_name = "xcode-build/Build/Intermediates.noindex/ArchiveIntermediates/#{target_name}/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/"
                            end
                            @xcode_build_name
                        end
end

#zip_dirObject



75
76
77
78
79
80
81
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 75

def zip_dir
  @zip_dir ||= begin
                 dir = File.join(root_dir,zip_dir_name)
                 Dir.mkdir(dir) unless File.exist?dir
                 Pathname.new(dir)
               end
end

#zip_dir_nameObject



71
72
73
# File 'lib/cocoapods-imy-bin/config/config_builder.rb', line 71

def zip_dir_name
  "bin-zip"
end