Class: Jxedt::Prebuild
- Inherits:
-
Object
- Object
- Jxedt::Prebuild
- Defined in:
- lib/cocoapods-jxedt/binary/prebuild.rb
Instance Method Summary collapse
- #all_supports_targets ⇒ Object
- #build ⇒ Object
- #build_dir ⇒ Object
- #build_targets(names: nil, binary_output: nil) ⇒ Object
- #clear_output_path ⇒ Object
-
#initialize(source_installer) ⇒ Prebuild
constructor
A new instance of Prebuild.
- #make_options ⇒ Object
- #make_prebuild(targets, binary_output = nil) ⇒ Object
- #output_path ⇒ Object
- #targets_to_prebuild ⇒ Object
Constructor Details
#initialize(source_installer) ⇒ Prebuild
Returns a new instance of Prebuild.
77 78 79 |
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 77 def initialize(source_installer) @source_installer = source_installer end |
Instance Method Details
#all_supports_targets ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 97 def all_supports_targets targets = @source_installer.pod_targets.select { |target| # 排除不需要编译 next unless target.should_build? # 排除target name和pod name不一致的(有两种情况) # 1. 同一个pod,在两个target下使用了不同的subspec # 2. 同一个pod,在两个不同ios版本的target种引用 next unless target.name == target.pod_name true } # 排除本地pod targets.reject! { |target| @source_installer.sandbox.local?(target.pod_name) } unless Jxedt.config.dev_pods_enabled? # 配置中排除的pods targets.reject! { |target| Jxedt.config.excluded_pods.include?(target.pod_name) } # target中可能存在需要编译的resource文件 Jxedt.config.disable_resource_compilable_pods? && targets.reject! { |target| # 因为编译library静态库会把需要编译的文件拷贝到宿主工程编译,后面我们要把静态库组装成framework,所以需要过滤掉 resource_extension_compilable = false target.resource_paths.each {|name, resources| resources.each {|resource_file| resource_extname = Pathname.new(resource_file).basename.extname resource_extension_compilable = target.class.resource_extension_compilable?(resource_extname) break if resource_extension_compilable } break if resource_extension_compilable } resource_extension_compilable } targets end |
#build ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 128 def build check_sandbox = Jxedt::Sandbox.from_sandbox(@source_installer.sandbox) existed_target_names = check_sandbox.target_paths.map { |pair| pair.basename.to_s } targets = targets_to_prebuild.reject { |target| existed_target_names.include?(target.name.to_s) } Pod::UI.puts "Prebuild total count: #{targets.size}" Pod::UI.puts "Prebuild targets: #{ targets.map(&:name)}" return [] if targets.empty? require_relative 'pod-room/xcodebuild_command' clear_output_path case targets[0].platform.name when :ios, :tvos, :watchos Jxedt.config.support_configurations.each do |configuration| Pod::UI.puts "Prebuild configuration: #{configuration}" = [:configuration] = configuration [:targets] = targets [:output_path] = output_path + configuration Jxedt::XcodebuildCommand.new().run end when :osx Jxedt.config.support_configurations.each do |configuration| Pod::UI.puts "Prebuild configuration: #{configuration}" = xcodebuild( sandbox: [:sandbox], targets: targets, configuration: configuration, sdk: "macosx", args: [:args] ) end else raise "Unsupported platform for '#{targets[0].name}': '#{targets[0].platform.name}'" end make_prebuild(targets) clear_output_path targets.map(&:pod_name).to_a end |
#build_dir ⇒ Object
273 274 275 276 |
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 273 def build_dir sandbox = @source_installer.sandbox sandbox.root.parent + "build" end |
#build_targets(names: nil, binary_output: nil) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 172 def build_targets(names: nil, binary_output: nil) targets = all_supports_targets targets.select! { |target| names.include?(target.pod_name) } if names && names.is_a?(Array) && names.size > 0 Pod::UI.puts "Prebuild total count: #{targets.size}" Pod::UI.puts "Prebuild targets: #{ targets.map(&:name)}" return [] if targets.empty? require_relative 'pod-room/xcodebuild_command' clear_output_path case targets[0].platform.name when :ios, :tvos, :watchos Jxedt.config.support_configurations.each do |configuration| Pod::UI.puts "Prebuild configuration: #{configuration}" = [:configuration] = configuration [:targets] = targets [:output_path] = output_path + configuration Jxedt::XcodebuildCommand.new().run end when :osx Jxedt.config.support_configurations.each do |configuration| Pod::UI.puts "Prebuild configuration: #{configuration}" = xcodebuild( sandbox: [:sandbox], targets: targets, configuration: configuration, sdk: "macosx", clean_build: Jxedt.config.clean_build?, args: [:args] ) end else raise "Unsupported platform for '#{targets[0].name}': '#{targets[0].platform.name}'" end binary_output = Pathname.new(binary_output) make_prebuild(targets, binary_output) clear_output_path targets.map(&:pod_name).to_a end |
#clear_output_path ⇒ Object
283 284 285 286 |
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 283 def clear_output_path path = output_path path.rmtree if path.exist? end |
#make_options ⇒ Object
258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 258 def = {} [:sandbox] = @source_installer.sandbox [:build_dir] = build_dir [:output_path] = output_path [:clean_build] = Jxedt.config.clean_build? [:bitcode_enabled] = Jxedt.config.bitcode_enabled? [:device_build_enabled] = Jxedt.config.device_build_enabled? [:simulator_build_enabled] = Jxedt.config.simulator_build_enabled? [:disable_dsym] = Jxedt.config.disable_dsym? [:log_path] = Jxedt.config.build_log_path [:args] = Jxedt.config.build_args end |
#make_prebuild(targets, binary_output = nil) ⇒ Object
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 217 def make_prebuild(targets, binary_output=nil) lockfile = @source_installer.lockfile checksums = lockfile.internal_data["SPEC CHECKSUMS"] || {} = lockfile.internal_data["CHECKOUT OPTIONS"] || {} # 目标binary路径 binary_path = output_path.parent binary_path = binary_output if binary_output && binary_output.parent.exist? prebuild_targets = targets.map(&:name).to_a prebuild_targets.map {|target_name| target_path = binary_path + target_name target_path.rmtree if target_path.exist? } # make prebuild files configurations = Jxedt.config.support_configurations Jxedt.config.support_configurations.each do |configuration| configuration_path = output_path + configuration next unless configuration_path.exist? configuration_path.children().each do |child| if child.directory? and (not child.children.empty?) name = child.basename.to_s next unless prebuild_targets.include?(name) target_path = binary_path + name target_path += configuration if configurations.size > 1 target_path.mkpath unless target_path.exist? command = "cp -r #{child}/ #{target_path}" `#{command}` # touch checksum checksum = nil checksum = [name][:commit] unless [name].nil? # commitid有值则使用commitid checksum = checksums[name] if checksum.nil? `echo #{command} "\n" >> #{binary_path}/#{name}/#{checksum}.checksum` unless checksum.nil? end end end end |
#output_path ⇒ Object
278 279 280 281 |
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 278 def output_path sandbox = @source_installer.sandbox sandbox.standard_sandbox_root + Jxedt.config.binary_dir + "GeneratedFrameworks" end |
#targets_to_prebuild ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cocoapods-jxedt/binary/prebuild.rb', line 81 def targets_to_prebuild explicit_prebuild_pod_names = @source_installer.aggregate_targets.flat_map { |target| target.target_definition.explicit_prebuild_pod_names }.uniq reject_prebuild_pod_names = @source_installer.aggregate_targets.flat_map { |target| target.target_definition.reject_prebuild_pod_names }.uniq targets = all_supports_targets.select { |target| next if reject_prebuild_pod_names.include?(target.pod_name) explicit_prebuild_pod_names.include?(target.pod_name) || Jxedt.config.all_binary_enabled? } targets end |