module Jxedt class Sandbox attr_accessor :sandbox def initialize(path=nil) @sandbox_path = path end def self.from_sandbox(sandbox) search_path = Jxedt.config.binary_dir binary_dir = search_path.empty? ? nil : sandbox.root + search_path check_sandbox = Sandbox.new(binary_dir) check_sandbox.sandbox = sandbox check_sandbox end def binary_dir @binary_dir ||= Pathname.new(@sandbox_path) end def target_paths return [] if @sandbox_path.nil? return [] unless binary_dir.exist? return [] if @sandbox.source_lockfile.nil? @targets ||= binary_dir.children().map do |target_path| if target_path.directory? && (not target_path.children.empty?) hash_key = @sandbox.source_lockfile.spec_checksums_hash_key(target_path.basename.to_s) target_path if !(hash_key.nil?) && (target_path + "#{hash_key}.checksum").exist? end end.reject(&:nil?).uniq @targets end def existed_target_names(name) target_paths.select { |pair| "#{pair.basename}" == "#{name}" }.map { |pair| pair.basename } end def framework_folder_path_for_target_name(name) target_paths.select { |pair| pair.basename == name }.last end def prebuild_vendored_frameworks(name) target_path = target_paths.select { |pair| "#{pair.basename}" == "#{name}" }.last return [] if target_path.nil? configuration_enable = target_path.children().select { |path| "#{path.basename}" == 'Debug' || "#{path.basename}" == 'Release' }.count == 2 if configuration_enable xcconfig_configuration_alias = Jxedt.config.xcconfig_configuration_alias ["#{xcconfig_configuration_alias}-Release/*.{framework,xcframework}"] else ["*.{framework,xcframework}"] end end def prebuild_bundles(name) target_path = target_paths.select { |pair| "#{pair.basename}" == "#{name}" }.last return [] if target_path.nil? configuration_enable = target_path.children().select { |path| "#{path.basename}" == 'Debug' || "#{path.basename}" == 'Release' }.count == 2 if configuration_enable xcconfig_configuration_alias = Jxedt.config.xcconfig_configuration_alias ["#{xcconfig_configuration_alias}-Release/*.bundle"] else ["*.bundle"] end end end class Prebuild def initialize(source_installer) @source_installer = source_installer end 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 = @source_installer.pod_targets.select { |target| next unless target.should_build? next unless target.name == target.pod_name next if reject_prebuild_pod_names.include?(target.pod_name) explicit_prebuild_pod_names.include?(target.pod_name) || Jxedt.config.all_binary_enabled? } targets.reject! { |target| @source_installer.sandbox.local?(target.pod_name) } unless Jxedt.config.dev_pods_enabled? targets.reject! { |target| Jxedt.config.excluded_pods.include?(target.pod_name) } targets end def pods_to_prebuild targets_to_prebuild.map(&:name).to_a end 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}" options = make_options options[:configuration] = configuration options[:targets] = targets options[:output_path] = output_path + configuration Jxedt::XcodebuildCommand.new(options).run end when :osx Jxedt.config.support_configurations.each do |configuration| Pod::UI.puts "Prebuild configuration: #{configuration}" options = make_options xcodebuild( sandbox: options[:sandbox], targets: targets, configuration: configuration, sdk: "macosx", args: options[:args] ) end else raise "Unsupported platform for '#{targets[0].name}': '#{targets[0].platform.name}'" end make_prebuild(targets) clear_output_path end def make_prebuild(targets) lockfile = @source_installer.lockfile checksums = lockfile.internal_data["SPEC CHECKSUMS"] || {} checkout_options = lockfile.internal_data["CHECKOUT OPTIONS"] || {} # 目标binary路径 binary_path = output_path.parent 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 = checkout_options[name][:commit] unless checkout_options[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 def make_options options = {} options[:sandbox] = @source_installer.sandbox options[:build_dir] = build_dir options[:output_path] = output_path options[:clean_build] = Jxedt.config.clean_build? options[:bitcode_enabled] = Jxedt.config.bitcode_enabled? options[:device_build_enabled] = Jxedt.config.device_build_enabled? options[:simulator_build_enabled] = Jxedt.config.simulator_build_enabled? options[:disable_dsym] = Jxedt.config.disable_dsym? options[:log_path] = Jxedt.config.build_log_path options[:args] = Jxedt.config.build_args options end def build_dir sandbox = @source_installer.sandbox sandbox.root.parent + "build" end def output_path sandbox = @source_installer.sandbox sandbox.root + Jxedt.config.binary_dir + "GeneratedFrameworks" end def clear_output_path path = output_path path.rmtree if path.exist? end end end