require 'tmpdir' module Pod class Command class Gd < Command self.summary = 'package a podspec into a static library.' self.arguments = [ CLAide::Argument.new('NAME', true), CLAide::Argument.new('SOURCE', false) ] def self.options [ ['--spec-sources=private,https://github.com/CocoaPods/Specs.git', '指定source源'], ['--upload', '是否上传,默认上传'], ['--upload-spec-name', '上传仓库必要参数,二进制源对应的spec版本仓库名称'], ['--upload-git-sources', '上传仓库必要参数,二进制源对应的git源码仓库名称'], ['--upload-local-path', '上传仓库必要参数,git源码仓库映射的本地路径'], ] end def initialize(argv) @gd_type = :static_framework @name = argv.shift_argument @source = argv.shift_argument @config = argv.option('configuration', 'Release') @source_dir = Dir.pwd @is_spec_from_path = false @spec = spec_with_path(@name) @is_spec_from_path = true if @spec @spec ||= spec_with_name(@name) # source源 @spec_sources = argv.option('spec-sources', 'https://gitlab.gaodun.com/iOSLibs/CocoaPods.git').split(',') # 'https://github.com/CocoaPods/Specs.git' @spec_sources.push('https://gitlab.gaodun.com/iOSLibs/Specs.git') # 是否上传 @upload = argv.option('upload') # 上传二进制源仓库名称 @upload_spec_name = argv.option('upload-spec-name') # 上传二进制源仓库地址 @upload_git_sources = argv.option('upload-git-sources') # 二进制源本地仓库地址 @upload_local_path = argv.option('upload-local-path') if @upload.nil? @upload = 1 end if @upload_spec_name.nil? @upload_spec_name = "frameworks-specs" end if @upload_git_sources.nil? @upload_git_sources = "https://gitlab.gaodun.com/iOSLibs/Frameworks/raw/master" end if @upload_local_path.nil? @upload_local_path = "/Users/lizuba/Desktop/Framework/Frameworks" end super end def validate! super end def run if @name == "install" # pod install走这里 Pod::InstallFramework.new.install() return end if @spec.nil? help! "Unable to find a podspec with path or name `#{@name}`." return end target_dir, work_dir = create_working_directory return if target_dir.nil? build_gd build_path="#{Dir.pwd}/build" if File.exist?("#{build_path}") FileUtils.rm_rf('build/') end `mv "#{work_dir}" "#{target_dir}"` Dir.chdir(@source_dir) if @upload == 1 uploader = Uploader.new(@spec, @upload_spec_name, @upload_local_path, @spec_sources) end end private def build_in_sandbox(platform) config.installation_root = Pathname.new(Dir.pwd) config.sandbox_root = 'Pods' static_sandbox = build_static_sandbox(@dynamic) static_installer = install_pod(platform.name, static_sandbox) if @dynamic dynamic_sandbox = build_dynamic_sandbox(static_sandbox, static_installer) install_dynamic_pod(dynamic_sandbox, static_sandbox, static_installer, platform) end begin perform_build(platform, static_sandbox, dynamic_sandbox, static_installer) ensure # in case the build fails; see Builder#xcodebuild. Pathname.new(config.sandbox_root).rmtree FileUtils.rm_f('Podfile.lock') end end def build_gd builder = SpecBuilder.new(@spec, @source, @embedded, @dynamic, @upload_git_sources) newspec = builder.spec_metadata @spec.available_platforms.each do |platform| if platform.name == :ios build_in_sandbox(platform) newspec += builder.spec_platform(platform) end end newspec += builder.spec_close File.open(@spec.name + '.podspec', 'w') { |file| file.write(newspec) } end def create_target_directory target_dir = "#{@source_dir}/#{@spec.name}-#{@spec.version}" if File.exist? target_dir if @force Pathname.new(target_dir).rmtree else UI.puts "Target directory '#{target_dir}' already exists." return nil end end target_dir end def create_working_directory target_dir = create_target_directory return if target_dir.nil? work_dir = Dir.tmpdir + '/cocoapods-' + Array.new(8) { rand(36).to_s(36) }.join Pathname.new(work_dir).mkdir Dir.chdir(work_dir) [target_dir, work_dir] end def perform_build(platform, static_sandbox, dynamic_sandbox, static_installer) static_sandbox_root = config.sandbox_root.to_s if @dynamic static_sandbox_root = "#{static_sandbox_root}/#{static_sandbox.root.to_s.split('/').last}" dynamic_sandbox_root = "#{config.sandbox_root}/#{dynamic_sandbox.root.to_s.split('/').last}" end builder = Pod::GDBuilder.new( platform, static_installer, @source_dir, static_sandbox_root, static_sandbox.public_headers.root, @spec, @embedded, @mangle, @dynamic, @config, @bundle_identifier, @exclude_deps ) builder.build(@gd_type) return unless @embedded builder.link_embedded_resources end end end end