class Pod::Command::Package

This is an example of a cocoapods plugin adding a top-level subcommand to the 'pod' command.

You can also create subcommands of existing or new commands. Say you wanted to add a subcommand to `list` to show newly deprecated pods, (e.g. `pod list deprecated`), there are a few things that would need to change.

@todo Create a PR to add your plugin to CocoaPods/cocoapods.org

in the `plugins.json` file, once your plugin is released.

Public Class Methods

new(argv) click to toggle source
# File lib/cocoapods-packager-ext/command/package_ext.rb, line 44
def initialize(argv)
    @exclude_dep_items = argv.option('exclude-deps','').split(',')
    @select_archs = argv.option('archs','').split(',')
    @podfile = argv.option('podfile','')
    @platform = argv.option('platform','')
    initialize_t argv
end
Also aliased as: initialize_t
options() click to toggle source
Calls superclass method
# File lib/cocoapods-packager-ext/command/package_ext.rb, line 29
def options
    o = options_t
    o.push(['--archs','select archs'])
    o.push(['--podfile','select deps version from podfile'])
    o.push(['--platform','select platform'])
    o.concat(super)
end
Also aliased as: options_t
options_t()
Alias for: options

Public Instance Methods

build_dynamic_target(dynamic_sandbox, static_installer, platform) click to toggle source
# File lib/cocoapods-packager-ext/ext/pod_utils.rb, line 11
def build_dynamic_target(dynamic_sandbox, static_installer, platform)
  spec_targets = static_installer.pod_targets.select do |target|
    target.name == @spec.name
  end
  static_target = spec_targets[0]

  file_accessors = create_file_accessors(static_target, dynamic_sandbox)

  archs = []
  dynamic_target = Pod::PodTarget.new(dynamic_sandbox, BuildType.dynamic_framework, static_target.user_build_configurations, archs, platform, static_target.specs, static_target.target_definitions, file_accessors)
  ln_source_to_dynamic_target(static_installer,dynamic_sandbox)
  dynamic_target
end
Also aliased as: build_dynamic_target_t
build_dynamic_target_t(dynamic_sandbox, static_installer, platform)

@param [Pod::Installer] static_installer

@return [Pod::PodTarget]

build_in_sandbox(platform) click to toggle source
# File lib/cocoapods-packager-ext/command/package_ext.rb, line 53
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.
        if ENV['ENABLE_BACKUP_WORKSPACE'] && (ENV['ENABLE_BACKUP_WORKSPACE'].upcase == 'YES' || ENV['ENABLE_BACKUP_WORKSPACE'].upcase == 'TRUE')
            UI.message 'Backup Workspace'
        else
            UI.message 'Delete Workspace'
            Pathname.new(config.sandbox_root).rmtree
            FileUtils.rm_f('Podfile.lock')
        end
    end
end
Also aliased as: build_in_sandbox_t
build_in_sandbox_t(platform)
Alias for: build_in_sandbox
build_package() click to toggle source
# File lib/cocoapods-packager-ext/command/package_ext.rb, line 99
def build_package
    if @platform == ''
        build_package_t
    else
        builder = SpecBuilder.new(@spec, @source, @embedded, @dynamic)
        newspec = builder.spec_metadata
        
        @spec.available_platforms.each do |platform|
            if @platform.include?(platform.name.to_s)
                UI.puts 'build package platform:'+platform.name.to_s
                build_in_sandbox(platform)
                if @library
                    newspec += spec_library(platform)
                else
                    newspec += builder.spec_platform(platform)
                end


            else
                UI.puts 'jump build platforms:'+platform.to_s
            end
        end

        newspec += builder.spec_close
        File.open(@spec.name + '.podspec', 'w') { |file| file.write(newspec) }
    end

end
Also aliased as: build_package_t
build_package_t()
Alias for: build_package
clean_dummy_files(path) click to toggle source
# File lib/cocoapods-packager-ext/command/package_ext.rb, line 128
def clean_dummy_files(path)
    Dir.entries(path).each do |sub|
        if sub != '.' && sub != '..'
            if File.directory?("#{path}/#{sub}")
                clean_dummy_files("#{path}/#{sub}")
            else
                if(sub =~ /-dummy.m$/)
                    File.open("#{path}/#{sub}",'w')do |file|
                        file.write('')
                        UI.message " - clean dummy file:#{sub}"
                    end
                end
            end
        end
    end
end
copy_dynamic_target(static_sandbox, _dynamic_target, dynamic_sandbox) click to toggle source
# File lib/cocoapods-packager-ext/ext/pod_utils.rb, line 25
def copy_dynamic_target(static_sandbox, _dynamic_target, dynamic_sandbox)
  if Dir.exist? static_sandbox.root+@spec.name
    command = "ln -sf #{static_sandbox.root}/#{@spec.name} #{dynamic_sandbox.root}"
    `#{command}`
  end
end
Also aliased as: copy_dynamic_target_t
copy_dynamic_target_t(static_sandbox, _dynamic_target, dynamic_sandbox)
Alias for: copy_dynamic_target
initialize_t(argv)
Alias for: new
ln_source_to_dynamic_target(static_installer, dynamic_sandbox) click to toggle source
# File lib/cocoapods-packager-ext/ext/pod_utils.rb, line 32
def ln_source_to_dynamic_target(static_installer, dynamic_sandbox)
  if not Dir.exist? static_installer.sandbox.root+@spec.name
    file_accessors = static_installer.pod_targets.select { |t| t.pod_name == @spec.name }.flat_map(&:file_accessors)
    if file_accessors && file_accessors.length > 0
      source_root = file_accessors[0].path_list.root
      command = "ln -sf #{source_root} #{dynamic_sandbox.root}/#{@spec.name}"
      `#{command}`
    else
      UI.puts "#{@spec.name} 根目录找不到"

    end
  end
end
perform_build(platform, static_sandbox, dynamic_sandbox,static_installer) click to toggle source
# File lib/cocoapods-packager-ext/command/package_ext.rb, line 146
def perform_build(platform, static_sandbox, dynamic_sandbox,static_installer)
    if @select_archs.length > 0 || @exclude_dep_items.length > 0
        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

        if (ENV['ENABLE_CLEAN_DUMMY_FILE'] && (ENV['ENABLE_CLEAN_DUMMY_FILE'].upcase == 'YES' || ENV['ENABLE_CLEAN_DUMMY_FILE'].upcase == 'TRUE'))
            UI.title 'Clean Dummy Files' do
                clean_dummy_files(static_sandbox.target_support_files_root)
                if @dynamic
                    clean_dummy_files(dynamic_sandbox.target_support_files_root)
                end
            end
        else
            UI.puts 'Jump clean dummy files'
        end

        builder = Pod::Builder.new(
          platform,
          static_installer,
          @source_dir,
          static_sandbox_root,
          dynamic_sandbox_root,
          static_sandbox.public_headers.root,
          @spec,
          @embedded,
          @mangle,
          @dynamic,
          @config,
          @bundle_identifier,
          @exclude_deps,
          @exclude_dep_items,
          @select_archs
        )

        builder.build(@package_type)

        return unless @embedded
        builder.link_embedded_resources
    else
        perform_build_t(platform,static_sandbox,dynamic_sandbox,static_installer)
    end
end
Also aliased as: perform_build_t
perform_build_t(platform, static_sandbox, dynamic_sandbox,static_installer)
Alias for: perform_build
spec_framework(platform) click to toggle source
# File lib/cocoapods-packager-ext/command/package_ext.rb, line 89
        def spec_framework(platform)
            spec = <<RB
  s.#{platform.name.to_s}.public_header_files = ['#{platform.name.to_s}/Headers/*.{h}']
  s.#{platform.name.to_s}.source_files = ['#{platform.name.to_s}/**/Headers/*.{h}']
  s.#{platform.name.to_s}.resource = ['#{platform.name.to_s}/**/Resources/*.bundle']
  s.#{platform.name.to_s}.module_map   = "#{platform.name.to_s}/**/Modules/module.modulemap"
RB
        end
spec_library(platform) click to toggle source
# File lib/cocoapods-packager-ext/command/package_ext.rb, line 78
        def spec_library(platform)
            spec = <<RB
  s.#{platform.name.to_s}.deployment_target    = '#{platform.deployment_target}'
  s.#{platform.name.to_s}.vendored_libraries  = ['#{platform.name.to_s}/*.a']
  s.#{platform.name.to_s}.public_header_files = ['#{platform.name.to_s}/Headers/*.{h}']
  s.#{platform.name.to_s}.source_files = ['#{platform.name.to_s}/Headers/*.{h}',"#{platform.name.to_s}/Modules/module.modulemap"]
  s.#{platform.name.to_s}.resource = ['#{platform.name.to_s}/Resources/*.bundle']
  s.#{platform.name.to_s}.module_map   = "#{platform.name.to_s}/Modules/module.modulemap"
RB
        end
write_pod_project(dynamic_project, dynamic_sandbox) click to toggle source
# File lib/cocoapods-packager-ext/ext/pod_utils.rb, line 47
def write_pod_project(dynamic_project, dynamic_sandbox)
  UI.message "- Writing Xcode project file to #{UI.path dynamic_sandbox.project_path}" do
    dynamic_project.pods.remove_from_project if dynamic_project.pods.empty?
    dynamic_project.development_pods.remove_from_project if dynamic_project.development_pods.empty?
    dynamic_project.sort(:groups_position => :below)
    dynamic_project.recreate_user_schemes(false)

    # Edit search paths so that we can find our dependency headers
    dynamic_project.targets.first.build_configuration_list.build_configurations.each do |config|
      header_path = Dir.glob("#{Dir.pwd}/Pods/Static/Headers/*/*")
      header_path.push "#{Dir.pwd}/Pods/Static/Headers/Public"
      header_path.push "#{Dir.pwd}/Pods/Static/Headers/Private"
      header_path.reject! {|item|item.split('/').last == dynamic_project.targets.first.name}
      header_path = header_path.join " "
      config.build_settings['HEADER_SEARCH_PATHS'] = "$(inherited) #{header_path}"
      config.build_settings['USER_HEADER_SEARCH_PATHS'] = "$(inherited) #{header_path}"
      config.build_settings['OTHER_LDFLAGS'] = '$(inherited) -ObjC'

      if ENV['DISABLE_BITCODE'] && (ENV['DISABLE_BITCODE'].upcase == 'YES' || ENV['DISABLE_BITCODE'].upcase == 'TRUE')
        config.build_settings['ENABLE_BITCODE'] = 'NO'
      end
    end
    dynamic_project.save
  end
end
Also aliased as: write_pod_project_t
write_pod_project_t(dynamic_project, dynamic_sandbox)
Alias for: write_pod_project