class Pod::Builder

Public Class Methods

new(platform, static_installer, source_dir, static_sandbox_root, dynamic_sandbox_root, public_headers_root, spec, embedded, mangle, dynamic, config, bundle_identifier, exclude_deps,exclude_dep_items=[],select_archs=[]) click to toggle source
# File lib/cocoapods-packager-ext/ext/builder.rb, line 290
def initialize(platform, static_installer, source_dir, static_sandbox_root, dynamic_sandbox_root, public_headers_root, spec, embedded, mangle, dynamic, config, bundle_identifier, exclude_deps,exclude_dep_items=[],select_archs=[])
  @exclude_dep_items = ['libPods-packager.a']
  @exclude_dep_items.concat(exclude_dep_items) if exclude_dep_items
  @select_archs = select_archs
  initialize_t(platform, static_installer,source_dir, static_sandbox_root, dynamic_sandbox_root, public_headers_root, spec, embedded, mangle, dynamic, config, bundle_identifier, exclude_deps)
end
Also aliased as: initialize_t

Public Instance Methods

build_dynamic_framework_for_ios(defines, output) click to toggle source
# File lib/cocoapods-packager-ext/ext/builder.rb, line 123
def build_dynamic_framework_for_ios(defines, output)
  # Specify frameworks to link and search paths
  linker_flags = static_linker_flags_in_sandbox
  defines = "#{defines} OTHER_LDFLAGS='$(inherited) #{linker_flags.join(' ')}'"

  # Build Target Dynamic Framework for both device and Simulator
  device_defines = "#{defines} LIBRARY_SEARCH_PATHS=\"#{static_linker_defines}\""
  device_options = ios_build_options << ' -sdk iphoneos'
  xcodebuild(device_defines, device_options, 'build', @spec.name.to_s, @dynamic_sandbox_root.to_s)
  if @select_archs.size == 0 || @select_archs.include?('i386') || @select_archs.include?('x86_64')
    sim_defines = "#{defines} LIBRARY_SEARCH_PATHS=\"#{Dir.pwd}/#{@static_sandbox_root}/build-sim\" ONLY_ACTIVE_ARCH=NO"
    xcodebuild(sim_defines, '-sdk iphonesimulator', 'build-sim', @spec.name.to_s, @dynamic_sandbox_root.to_s)
    # Combine architectures
    `lipo #{@dynamic_sandbox_root}/build/#{@spec.name}.framework/#{@spec.name} #{@dynamic_sandbox_root}/build-sim/#{@spec.name}.framework/#{@spec.name} -create -output #{output}`
  else
    `mv #{@dynamic_sandbox_root}/build/#{@spec.name}.framework/#{@spec.name} #{output}`
  end

  FileUtils.mkdir(@platform.name.to_s)
  `mv #{@dynamic_sandbox_root}/build/#{@spec.name}.framework #{@platform.name}`
  `mv #{@dynamic_sandbox_root}/build/#{@spec.name}.framework.dSYM #{@platform.name}`
end
build_dynamic_framework_for_ios_t(defines, output)
build_sim_libraries(defines) click to toggle source
# File lib/cocoapods-packager-ext/ext/builder.rb, line 250
def build_sim_libraries(defines)
    if @select_archs.size != 0 && !@select_archs.include?('i386') && !@select_archs.include?('x86_64')
      return 
    else
      UI.puts 'start build sim'
      build_sim_libraries_t defines
    end
end
Also aliased as: build_sim_libraries_t
build_sim_libraries_t(defines)
Alias for: build_sim_libraries
build_static_library() click to toggle source
# File lib/cocoapods-packager-ext/ext/builder.rb, line 7
def build_static_library

  UI.puts("Building static library #{@spec} with configuration #{@config}")

  defines = compile
  build_sim_libraries(defines)

  platform_path = Pathname.new(@platform.name.to_s)
  platform_path.mkdir unless platform_path.exist?

  output = platform_path + "lib#{@spec.name}-#{@platform.name.to_s}.a"

  if @platform.name == :ios
    build_static_library_for_ios(output)
  else
    build_static_library_for_mac(output)
  end

  platform_path = Pathname.new(@platform.name.to_s)
  header_path = platform_path+'Headers'
  header_path.mkpath unless header_path.exist?

  module_map_path = platform_path+'Modules'
  module_map_path.mkpath unless module_map_path.exist?
  copy_headers_to_target header_path,module_map_path

  resources_path = platform_path+'Resources'
  resources_path.mkpath unless resources_path.exist?
  copy_resources_to_target resources_path
end
Also aliased as: build_static_library_t
build_static_library_for_ios(output) click to toggle source
# File lib/cocoapods-packager-ext/ext/builder.rb, line 38
def build_static_library_for_ios(output)
  if @exclude_dep_items.length > 0
    static_libs = static_libs_in_sandbox('build') + static_libs_in_sandbox('build-sim') + vendored_libraries
    static_libs.reject! {|lib| @exclude_dep_items.any? {|item| lib.to_s.include? item}}
    UI.section 'Fetch output libs' do
      static_libs.each do |lib|
        UI.message lib
      end
    end
    libs = ios_architectures.map do |arch|
      library = "#{@static_sandbox_root}/build/package-#{arch}.a"
      `libtool -arch_only #{arch} -static -o #{library} #{static_libs.join(' ')}`
      library
    end

    `lipo -create -output #{output} #{libs.join(' ')}`

    # static_libs = static_libs_in_sandbox('build')
    # sim_libs = static_libs_in_sandbox('build-sim')
    # for item in @black_deps
    #   static_libs.delete_if do |obj|
    #     obj.include? item
    #   end
    #   sim_libs.delete_if do |obj|
    #     obj.include? item
    #   end
    # end
    # UI.puts "links statics:#{static_libs.join(' ')}, sim_libs:#{sim_libs.join(' ')}"
    # `xcrun -r libtool -no_warning_for_no_symbols -static -o #{output} #{static_libs.join(' ')} #{sim_libs.join(' ')}`
  else
    build_static_library_for_ios_t output
  end
end
build_static_library_for_ios_t(output)
build_static_library_t()
compile() click to toggle source
# File lib/cocoapods-packager-ext/ext/builder.rb, line 93
def compile
  if ENV['GCC_PREPROCESSOR_DEFINITIONS']
    defines = "GCC_PREPROCESSOR_DEFINITIONS='$(inherited) PodsDummy_Pods_#{@spec.name}=PodsDummy_PodPackage_#{@spec.name} #{ENV['GCC_PREPROCESSOR_DEFINITIONS']}'"
    UI.puts "Set GCC_PREPROCESSOR_DEFINITIONS:#{defines}"
  else
    defines = "GCC_PREPROCESSOR_DEFINITIONS='$(inherited) PodsDummy_Pods_#{@spec.name}=PodsDummy_PodPackage_#{@spec.name}'"
  end
  defines << ' ' << @spec.consumer(@platform).compiler_flags.join(' ')

  if @platform.name == :ios
    options = ios_build_options
  end

  xcodebuild(defines, options)

  if @mangle
    return build_with_mangling(options)
  end

  defines
end
Also aliased as: compile_t
compile_t()
Alias for: compile
copy_headers() click to toggle source
# File lib/cocoapods-packager-ext/ext/builder.rb, line 156
def copy_headers
  copy_headers_to_target @fwk.headers_path
end
Also aliased as: copy_headers_t
copy_headers_t()
Alias for: copy_headers
copy_headers_to_target(headers_target_path = nil ,module_map_target_path = nil ) click to toggle source
# File lib/cocoapods-packager-ext/ext/builder.rb, line 160
    def copy_headers_to_target(headers_target_path = nil ,module_map_target_path = nil )
      headers_target_path = @fwk.headers_path if headers_target_path.nil?
      module_map_target_path = @fwk.module_map_path if module_map_target_path.nil?

      headers_source_root = "#{@public_headers_root}/#{@spec.name}"

      Dir.glob("#{headers_source_root}/**/*.h").
        each { |h| `ditto #{h} #{headers_target_path}/#{h.sub(headers_source_root, '')}` }

      # If custom 'module_map' is specified add it to the framework distribution
      # otherwise check if a header exists that is equal to 'spec.name', if so
      # create a default 'module_map' one using it.
      if !@spec.module_map.nil?
        module_map_file = @file_accessors.flat_map(&:module_map).first
        module_map = File.read(module_map_file) if Pathname(module_map_file).exist?
      elsif File.exist?("#{@public_headers_root}/#{@spec.name}/#{@spec.name}.h")
        module_map = <<MAP
framework module #{@spec.name} {
  umbrella header "#{@spec.name}.h"

  export *
  module * { export * }
}
MAP
      else

        f = File.new(File.join("#{headers_target_path}","#{@spec.name}.h"), "w+")
        f.puts("#import <UIKit/UIKit.h>")
        f.puts("#import <Foundation/Foundation.h>")
        Dir.foreach(headers_target_path) do |filename|
          if filename != "." and filename != ".."
            f.puts("#import \"#{filename}\"")
          end
        end
        f.close

        module_map = <<MAP
framework module #{@spec.name} {
  umbrella header "#{@spec.name}.h"

  export *
  module * { export * }
}
MAP
      end

      unless module_map.nil?
        module_map_target_path.mkpath unless module_map_target_path.exist?
        File.write("#{module_map_target_path}/module.modulemap", module_map)
      end
    end
copy_resources() click to toggle source
# File lib/cocoapods-packager-ext/ext/builder.rb, line 213
def copy_resources
  copy_resources_to_target @fwk.resources_path unless @dynamic
end
Also aliased as: copy_resources_t
copy_resources_t()
Alias for: copy_resources
copy_resources_to_target(resources_target_path = nil ) click to toggle source
# File lib/cocoapods-packager-ext/ext/builder.rb, line 216
def copy_resources_to_target(resources_target_path = nil )
  resources_target_path = @fwk.resources_path if resources_target_path.nil?
  if @exclude_deps
    bundles = @static_installer.pod_targets.flat_map(&:file_accessors).flat_map{|item|item.resources}
  else
    bundles = @static_installer.pod_targets.reject { |t| @exclude_dep_items.any?{|item|t.pod_name == item}}.flat_map(&:file_accessors).flat_map{|item|item.resources}
  end
  if @dynamic
    resources_path = "ios/#{@spec.name}.framework"
    bundles.tap{|path| FileUtils.cp_r path,resources_path}
    `cp -rp #{@static_sandbox_root}/build/*.bundle #{resources_path} 2>&1`
  else
    `cp -rp #{@static_sandbox_root}/build/*.bundle #{resources_path} 2>&1`
    resources = expand_paths(@spec.consumer(@platform).resources)
    if resources.count == 0 && bundles.count == 0
      if @fwk
        @fwk.delete_resources
      else
        if resources_target_path.exist?
          FileUtils.rm_rf resources_target_path
        end
      end
      return
    end
    if resources.count > 0
      `cp -rp #{resources.join(' ')} #{resources_target_path}`
    end
    if bundles.count > 0
      `cp -rp #{bundles.join(' ')} #{resources_target_path}`
    end
  end
end
initialize_t(platform, static_installer, source_dir, static_sandbox_root, dynamic_sandbox_root, public_headers_root, spec, embedded, mangle, dynamic, config, bundle_identifier, exclude_deps,exclude_dep_items=[],select_archs=[])
Alias for: new
ios_architectures() click to toggle source
# File lib/cocoapods-packager-ext/ext/builder.rb, line 147
def ios_architectures
  if @select_archs.size != 0
    return @select_archs
  else
    return ios_architectures_t
  end
end
ios_architectures_t()
Alias for: ios_architectures
ios_build_options() click to toggle source
# File lib/cocoapods-packager-ext/ext/builder.rb, line 84
def ios_build_options
  if ENV['DISABLE_BITCODE'] && (ENV['DISABLE_BITCODE'].upcase == 'YES' || ENV['DISABLE_BITCODE'].upcase == 'TRUE')
    "ARCHS=\'#{ios_architectures.join(' ')}\' OTHER_CFLAGS=\'-Qunused-arguments\'"
  else
    "ARCHS=\'#{ios_architectures.join(' ')}\' OTHER_CFLAGS=\'-fembed-bitcode -Qunused-arguments\'"
  end
end
static_linker_defines() click to toggle source
# File lib/cocoapods-packager-ext/ext/builder.rb, line 115
def static_linker_defines
  static_libs = static_libs_in_sandbox('build') + static_libs_in_sandbox('build-sim')
  static_libs = static_libs.map { |path| Pathname("#{Dir.pwd}/#{path}").parent.to_s }
  vendored_libs = vendored_libraries.map { |path| Pathname(path).parent.to_s }
  link_paths = static_libs + vendored_libs
  link_paths.uniq.join(" ")
end
static_linker_flags_in_sandbox() click to toggle source
# File lib/cocoapods-packager-ext/ext/builder.rb, line 74
def static_linker_flags_in_sandbox
  static_libs = static_libs_in_sandbox('build') + static_libs_in_sandbox('build-sim') + vendored_libraries
  linker_flags = static_libs.map do |lib|
    lib = lib.chomp('.a').split('/').last
    lib.slice!('lib')
    "-l#{lib}"
  end
  linker_flags.reject { |e| e == "-l#{@spec.name}" || e == '-lPods-packager' }
end
static_linker_flags_in_sandbox_t()
Alias for: ios_architectures
xcodebuild(defines = '', args = '', build_dir = 'build', target = 'Pods-packager', project_root = @static_sandbox_root, config = @config) click to toggle source
# File lib/cocoapods-packager-ext/ext/builder.rb, line 261
def xcodebuild(defines = '', args = '', build_dir = 'build', target = 'Pods-packager', project_root = @static_sandbox_root, config = @config)
  if defined?(Pod::DONT_CODESIGN)
    args = "#{args} CODE_SIGN_IDENTITY=\"\" CODE_SIGNING_REQUIRED=NO"
  end

  command = "xcodebuild #{defines} #{args} CONFIGURATION_BUILD_DIR=#{build_dir} clean build -configuration #{config} -target #{target} -project #{project_root}/Pods.xcodeproj 2>&1"
  UI.puts "exec command: #{command}"
  output = `#{command}`.lines.to_a

  if $?.exitstatus != 0
    if ENV['ENABLE_BACKUP_WORKSPACE'] && (ENV['ENABLE_BACKUP_WORKSPACE'].upcase == 'YES' || ENV['ENABLE_BACKUP_WORKSPACE'].upcase == 'TRUE')
      UI.title 'Backup Workspace' do
        target_dir = "#{@source_dir}/#{@spec.name}-#{@spec.version}"
        work_dir = Dir.pwd
        `mv "#{work_dir}" "#{target_dir}"`
      end
    end
    puts UI::BuildFailedReport.report(command, output)

    # Note: We use `Process.exit` here because it fires a `SystemExit`
    # exception, which gives the caller a chance to clean up before the
    # process terminates.
    #
    # See http://ruby-doc.org/core-1.9.3/Process.html#method-c-exit
    Process.exit
  end
end
Also aliased as: xcodebuild_t
xcodebuild_t(defines = '', args = '', build_dir = 'build', target = 'Pods-packager', project_root = @static_sandbox_root, config = @config)
Alias for: xcodebuild