class PodAlexandria::Compiler

Attributes

build_dir[R]
configuration[R]
destination[R]
flags[R]
sandbox[R]

Public Class Methods

new(sandbox, build_dir, destination, configuration, flags) click to toggle source
# File lib/cocoapods-alexandria/rome/compiler.rb, line 5
def initialize(sandbox, build_dir, destination, configuration, flags)
  @sandbox = sandbox
  @build_dir = build_dir
  @destination = destination
  @configuration = configuration
  @flags = flags
end

Public Instance Methods

build(target) click to toggle source
# File lib/cocoapods-alexandria/rome/compiler.rb, line 13
def build(target)
  sdk = platform_sdk[target.platform_name]
  deployment_target = target.platform_deployment_target
  target_label = target.cocoapods_target_label

  # build each dependency of target
  spec_names = target.specs.map { |spec| [spec.root.name, spec.root.module_name] }.uniq
  
  spec_names.map { |root_name, module_name|
    next if skip_build?(root_name, module_name, sdk)
    if File.directory?(build_path(target, module_name, sdk))
      build_path(target, module_name, sdk)
    else
      xcodebuild(root_name, module_name, sdk, deployment_target)
    end
  }.compact
end

Private Instance Methods

build_path(target, module_name, sdk) click to toggle source
# File lib/cocoapods-alexandria/rome/compiler.rb, line 62
def build_path(target, module_name, sdk)
  "#{build_dir}/#{configuration}-#{sdk}/#{target}/#{module_name}.framework"
end
destination_path(module_name) click to toggle source
# File lib/cocoapods-alexandria/rome/compiler.rb, line 66
def destination_path(module_name)
  "#{destination}/#{module_name}.framework"
end
is_native_target?(target_name) click to toggle source
# File lib/cocoapods-alexandria/rome/compiler.rb, line 42
def is_native_target?(target_name)
  project.targets
    .find { |t| t.name == target_name }
    .is_a?(Xcodeproj::Project::Object::PBXNativeTarget)
end
platform_sdk() click to toggle source
# File lib/cocoapods-alexandria/rome/compiler.rb, line 33
def platform_sdk
  { :ios => 'iphoneos', :osx => 'macosx', :tvos => 'appletvos', :watchos => 'watchos' }
end
project() click to toggle source
# File lib/cocoapods-alexandria/rome/compiler.rb, line 58
def project
  @project ||= Xcodeproj::Project.open(sandbox.project_path)
end
skip_build?(target, module_name, sdk) click to toggle source
# File lib/cocoapods-alexandria/rome/compiler.rb, line 37
def skip_build?(target, module_name, sdk)
  File.directory?(destination_path(module_name)) ||
    !is_native_target?(target)
end
xcodebuild(target, module_name, sdk, deployment_target) click to toggle source
# File lib/cocoapods-alexandria/rome/compiler.rb, line 48
def xcodebuild(target, module_name, sdk, deployment_target)
  args = %W(-project #{sandbox.project_path.realdirpath} -scheme #{target} -configuration #{configuration} -sdk #{sdk})
  args += flags unless flags.nil? 
  
  Pod::UI.puts "Building '#{target}' for #{sdk}..."
  Pod::Executable.execute_command 'xcodebuild', args, true

  build_path(target, module_name, sdk)
end