Module: Shenzhen::XcodeBuild

Defined in:
lib/shenzhen/xcodebuild.rb

Defined Under Namespace

Classes: Error, Info, NilOutputError, Settings

Class Method Summary collapse

Class Method Details

.info(*args) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/shenzhen/xcodebuild.rb', line 30

def info(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  output = `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) ⇒ Object


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/shenzhen/xcodebuild.rb', line 63

def settings(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  output = `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

.versionObject


88
89
90
91
# File 'lib/shenzhen/xcodebuild.rb', line 88

def version
  output = `xcodebuild -version`
  output.scan(/([\d+\.?]+)/).flatten.first rescue nil
end