class Pod::Command::Gd

Public Class Methods

new(argv) click to toggle source
Calls superclass method
# File lib/pod/command/gd.rb, line 21
      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.flag?('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_spec_name.nil?
          @upload_spec_name = "lizuba-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
options() click to toggle source
# File lib/pod/command/gd.rb, line 11
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

Public Instance Methods

run() click to toggle source
# File lib/pod/command/gd.rb, line 66
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
  podspec_path="#{Dir.pwd}/replaced.podspec"
  if File.exist?("#{podspec_path}")
    FileUtils.rm_rf("#{podspec_path}")
  end
  json_path="#{Dir.pwd}/replaced.podspec.json"
  if File.exist?("#{json_path}")
    FileUtils.rm_rf("#{json_path}")
  end
  `mv "#{work_dir}" "#{target_dir}"`
  Dir.chdir(@source_dir)

  if @upload == true
    uploader = Pod::GDUploader.new(@spec, @upload_spec_name, @upload_local_path, @spec_sources)
  end
end
validate!() click to toggle source
Calls superclass method
# File lib/pod/command/gd.rb, line 62
def validate!
  super
end

Private Instance Methods

binary_only?(spec) click to toggle source
# File lib/cocoapods-gd/pod_utils.rb, line 107
def binary_only?(spec)
  deps = spec.dependencies.map { |dep| spec_with_name(dep.name) }
  [spec, *deps].each do |specification|
    %w(vendored_frameworks vendored_libraries).each do |attrib|
      if specification.attributes_hash[attrib]
        return true
      end
    end
  end

  false
end
build_dynamic_sandbox(_static_sandbox, _static_installer) click to toggle source
# File lib/cocoapods-gd/pod_utils.rb, line 154
def build_dynamic_sandbox(_static_sandbox, _static_installer)
  dynamic_sandbox_root = Pathname.new(config.sandbox_root + '/Dynamic')
  dynamic_sandbox = Sandbox.new(dynamic_sandbox_root)

  dynamic_sandbox
end
build_dynamic_target(dynamic_sandbox, static_installer, platform) click to toggle source

@param [Pod::Installer] static_installer

@return [Pod::PodTarget]

# File lib/cocoapods-gd/pod_utils.rb, line 193
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 = []
  buildy_type = Pod::BuildType.static_framework()
  dynamic_target = Pod::PodTarget.new(dynamic_sandbox, buildy_type, static_target.user_build_configurations, archs, platform, static_target.specs, static_target.target_definitions, file_accessors)
  dynamic_target
end
build_gd() click to toggle source
# File lib/pod/command/gd.rb, line 122
def build_gd
  builder = GDSpecBuilder.new(@spec, @source, @embedded, @dynamic, @upload_git_sources)
  newspec = builder.spec_metadata

  @spec.available_platforms.each do |platform|
    if platform.name == :ios
      gd_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
build_static_sandbox(dynamic) click to toggle source
# File lib/cocoapods-gd/pod_utils.rb, line 6
def build_static_sandbox(dynamic)
  static_sandbox_root = if dynamic
                          Pathname.new(config.sandbox_root + '/Static')
                        else
                          Pathname.new(config.sandbox_root)
                        end
  Sandbox.new(static_sandbox_root)
end
copy_dynamic_target(static_sandbox, _dynamic_target, dynamic_sandbox) click to toggle source
# File lib/cocoapods-gd/pod_utils.rb, line 230
def copy_dynamic_target(static_sandbox, _dynamic_target, dynamic_sandbox)
  command = "cp -a #{static_sandbox.root}/#{@spec.name} #{dynamic_sandbox.root}"
  `#{command}`
end
create_file_accessors(target, dynamic_sandbox) click to toggle source
# File lib/cocoapods-gd/pod_utils.rb, line 235
def create_file_accessors(target, dynamic_sandbox)
  pod_root = dynamic_sandbox.pod_dir(target.root_spec.name)

  path_list = Sandbox::PathList.new(pod_root)
  target.specs.map do |spec|
    Sandbox::FileAccessor.new(path_list, spec.consumer(target.platform))
  end
end
create_new_podspec(path) click to toggle source
# File lib/cocoapods-gd/pod_utils.rb, line 68
def create_new_podspec(path)
  include_json = "#{path}".end_with?(".json")
  if include_json
    local_podspec = "#{Dir.pwd}/replaced.podspec.json"
  else
    local_podspec = "#{Dir.pwd}/replaced.podspec"
  end
  
  FileUtils.cp("#{path}", local_podspec)
  has_swift_version = false
  lines = IO.readlines(local_podspec).map do |line|
    if line.include?("swift_version")
      has_swift_version = true
    end
    if include_json 
      if line.include?("homepage")
         line = "#{line} \n  \"swift_version\": \"5.0\","
      end 
    else
      spec = ""
      if line.include?("s.homepage")
        spec = "s"
        line = "#{line} \n  #{spec}.swift_version = '5.0'"
      end
      if line.include?("spec.homepage")
        spec = "spec"
        line = "#{line} \n  #{spec}.swift_version = '5.0'"
      end
    end
    line
  end
  if !has_swift_version
    File.open(local_podspec, 'w') do |file|
      file.puts lines
    end
  end
  local_podspec
end
create_target_directory() click to toggle source
# File lib/pod/command/gd.rb, line 137
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
create_working_directory() click to toggle source
# File lib/pod/command/gd.rb, line 150
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
gd_build_in_sandbox(platform) click to toggle source
# File lib/pod/command/gd.rb, line 102
def gd_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
    gd_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
gd_perform_build(platform, static_sandbox, dynamic_sandbox, static_installer) click to toggle source
# File lib/pod/command/gd.rb, line 161
def gd_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
install_dynamic_pod(dynamic_sandbox, static_sandbox, static_installer, platform) click to toggle source

@param [Pod::Sandbox] dynamic_sandbox

@param [Pod::Sandbox] static_sandbox

@param [Pod::Installer] static_installer

@param [Pod::Platform] platform

# File lib/cocoapods-gd/pod_utils.rb, line 169
def install_dynamic_pod(dynamic_sandbox, static_sandbox, static_installer, platform)
  # 1 Create a dynamic target for only the spec pod.
  dynamic_target = build_dynamic_target(dynamic_sandbox, static_installer, platform)

  # 2. Build a new xcodeproj in the dynamic_sandbox with only the spec pod as a target.
  project = prepare_pods_project(dynamic_sandbox, dynamic_target.name, static_installer)

  # 3. Copy the source directory for the dynamic framework from the static sandbox.
  copy_dynamic_target(static_sandbox, dynamic_target, dynamic_sandbox)

  # 4. Create the file references.
  install_file_references(dynamic_sandbox, [dynamic_target], project)

  # 5. Install the target.
  install_library(dynamic_sandbox, dynamic_target, project)

  # 6. Write the actual .xcodeproj to the dynamic sandbox.
  write_pod_project(project, dynamic_sandbox)
end
install_file_references(dynamic_sandbox, pod_targets, pods_project) click to toggle source
# File lib/cocoapods-gd/pod_utils.rb, line 244
def install_file_references(dynamic_sandbox, pod_targets, pods_project)
  installer = Pod::Installer::Xcode::PodsProjectGenerator::FileReferencesInstaller.new(dynamic_sandbox, pod_targets, pods_project)
  installer.install!
end
install_library(dynamic_sandbox, dynamic_target, project) click to toggle source
# File lib/cocoapods-gd/pod_utils.rb, line 249
def install_library(dynamic_sandbox, dynamic_target, project)
  return if dynamic_target.target_definitions.flat_map(&:dependencies).empty?
  target_installer = Pod::Installer::Xcode::PodsProjectGenerator::PodTargetInstaller.new(dynamic_sandbox, project, dynamic_target)
  result = target_installer.install!
  native_target = result.native_target

  # Installs System Frameworks
  if dynamic_target.should_build?
    dynamic_target.file_accessors.each do |file_accessor|
      file_accessor.spec_consumer.frameworks.each do |framework|
        native_target.add_system_framework(framework)
      end
      file_accessor.spec_consumer.libraries.each do |library|
        native_target.add_system_library(library)
      end
    end
  end
end
install_pod(platform_name, sandbox) click to toggle source
# File lib/cocoapods-gd/pod_utils.rb, line 15
def install_pod(platform_name, sandbox)
  podfile = podfile_from_spec(
    @path,
    @spec.name,
    platform_name,
    @spec.deployment_target(platform_name),
    @subspecs,
    @spec_sources
  )

  static_installer = Installer.new(sandbox, podfile)
  static_installer.install!

  unless static_installer.nil?
    static_installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        config.build_settings['CLANG_MODULES_AUTOLINK'] = 'NO'
        config.build_settings['GCC_GENERATE_DEBUGGING_SYMBOLS'] = 'NO'
      end
    end
    static_installer.pods_project.save
  end

  static_installer
end
podfile_from_spec(path, spec_name, platform_name, deployment_target, subspecs, sources) click to toggle source
# File lib/cocoapods-gd/pod_utils.rb, line 41
def podfile_from_spec(path, spec_name, platform_name, deployment_target, subspecs, sources)
  new_path = create_new_podspec(path)
  options = {}
  if new_path
    if @local
      options[:path] = new_path
    else
      options[:podspec] = new_path
    end
  end
  options[:subspecs] = subspecs if subspecs
  Pod::Podfile.new do
    sources.each { |s| source s }
    platform(platform_name, deployment_target)
    pod(spec_name, options)

    install!('cocoapods',
             :integrate_targets => false,
             :deterministic_uuids => false)

    target('gd') do
      use_modular_headers!
      inherit! :complete
    end
  end
end
prepare_pods_project(dynamic_sandbox, spec_name, installer) click to toggle source

@param [Pod::Sandbox] dynamic_sandbox

@param [String] spec_name

@param [Pod::Installer] installer

# File lib/cocoapods-gd/pod_utils.rb, line 213
def prepare_pods_project(dynamic_sandbox, spec_name, installer)
  # Create a new pods project
  pods_project = Pod::Project.new(dynamic_sandbox.project_path)

  # Update build configurations
  installer.analysis_result.all_user_build_configurations.each do |name, type|
    pods_project.add_build_configuration(name, type)
  end

  # Add the pod group for only the dynamic framework
  local = dynamic_sandbox.local?(spec_name)
  path = dynamic_sandbox.pod_dir(spec_name)
  was_absolute = dynamic_sandbox.local_path_was_absolute?(spec_name)
  pods_project.add_pod_group(spec_name, path, local, was_absolute)
  pods_project
end
spec_with_name(name) click to toggle source
# File lib/cocoapods-gd/pod_utils.rb, line 120
def spec_with_name(name)
  return if name.nil?

  set = Pod::Config.instance.sources_manager.search(Dependency.new(name))
  return nil if set.nil?

  set.specification.root
end
spec_with_path(path) click to toggle source
# File lib/cocoapods-gd/pod_utils.rb, line 129
def spec_with_path(path)
  return if path.nil?
  path = Pathname.new(path)
  path = Pathname.new(Dir.pwd).join(path) unless path.absolute?
  return unless path.exist?

  @path = path.expand_path

  if @path.directory?
    help! @path + ': is a directory.'
    return
  end

  unless ['.podspec', '.json'].include? @path.extname
    help! @path + ': is not a podspec.'
    return
  end

  Specification.from_file(@path)
end
write_pod_project(dynamic_project, dynamic_sandbox) click to toggle source
# File lib/cocoapods-gd/pod_utils.rb, line 268
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|
      config.build_settings['HEADER_SEARCH_PATHS'] = "$(inherited) #{Dir.pwd}/Pods/Static/Headers/**"
      config.build_settings['USER_HEADER_SEARCH_PATHS'] = "$(inherited) #{Dir.pwd}/Pods/Static/Headers/**"
      config.build_settings['OTHER_LDFLAGS'] = '$(inherited) -ObjC'
    end
    dynamic_project.save
  end
end