module Shenzhen::XcodeBuild

Public Class Methods

info(*args) click to toggle source
# File lib/shenzhen/xcodebuild.rb, line 30
def info(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  output = `xcrun xcodebuild -list #{(args + args_from_options(options)).join(" ")} 2>&1`

  raise Error.new $1 if /^xcodebuild\: error\: (.+)$/ === output

  return nil unless /\S/ === output

  lines = output.split(/\n/)
  info, group = {}, nil

  info[:project] = lines.shift.match(/\"(.+)\"\:/)[1] rescue nil

  lines.each do |line|
    if /\:$/ === line
      group = line.strip[0...-1].downcase.gsub(/\s+/, '_')
      info[group] = []
      next
    end

    unless group.nil? or /\.$/ === line
      info[group] << line.strip
    end
  end

  info.each do |group, values|
    next unless Array === values
    values.delete("") and values.uniq!
  end

  Info.new(info)
end
settings(*args) click to toggle source
# File lib/shenzhen/xcodebuild.rb, line 63
def settings(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  output = `xcrun xcodebuild #{(args + args_from_options(options)).join(" ")} -showBuildSettings 2> /dev/null`

  return nil unless /\S/ === output

  raise Error.new $1 if /^xcodebuild\: error\: (.+)$/ === output

  lines = output.split(/\n/)

  settings, target = {}, nil
  lines.each do |line|
    case line
    when /Build settings for action build and target \"?([^":]+)/
      target = $1
      settings[target] = {}
    else
      key, value = line.split(/\=/).collect(&:strip)
      settings[target][key] = value if target
    end
  end

  Settings.new(settings)
end
version() click to toggle source
# File lib/shenzhen/xcodebuild.rb, line 88
def version
  output = `xcrun xcodebuild -version`
  output.scan(/([\d+\.?]+)/).flatten.first rescue nil
end

Private Class Methods

args_from_options(options = {}) click to toggle source
# File lib/shenzhen/xcodebuild.rb, line 95
def args_from_options(options = {})
  options.reject{|key, value| value.nil?}.collect{|key, value| "-#{key} '#{value}'"}
end