Class: Xcode::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/xcode/builder.rb

Overview

This class tries to pull various bits of Xcoder together to provide a higher-level API for common project build tasks.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Builder

Returns a new instance of Builder.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/xcode/builder.rb', line 15

def initialize(config)
  if config.is_a? Xcode::Scheme
    @scheme = config
    config = config.launch
  end
  
  #puts "CONFIG: #{config}"
  @target = config.target
  @sdk = @target.project.sdk
  @config = config
  @build_path = "#{File.dirname(@target.project.path)}/build/"
  @objroot = @build_path
  @symroot = @build_path
end

Instance Attribute Details

#build_pathObject

Returns the value of attribute build_path.



13
14
15
# File 'lib/xcode/builder.rb', line 13

def build_path
  @build_path
end

#identityObject

Returns the value of attribute identity.



13
14
15
# File 'lib/xcode/builder.rb', line 13

def identity
  @identity
end

#keychainObject

Returns the value of attribute keychain.



13
14
15
# File 'lib/xcode/builder.rb', line 13

def keychain
  @keychain
end

#objrootObject

Returns the value of attribute objroot.



13
14
15
# File 'lib/xcode/builder.rb', line 13

def objroot
  @objroot
end

#profileObject

Returns the value of attribute profile.



13
14
15
# File 'lib/xcode/builder.rb', line 13

def profile
  @profile
end

#sdkObject

Returns the value of attribute sdk.



13
14
15
# File 'lib/xcode/builder.rb', line 13

def sdk
  @sdk
end

#symrootObject

Returns the value of attribute symroot.



13
14
15
# File 'lib/xcode/builder.rb', line 13

def symroot
  @symroot
end

Instance Method Details

#app_pathObject



169
170
171
# File 'lib/xcode/builder.rb', line 169

def app_path
  "#{configuration_build_path}/#{@config.product_name}.app"
end

#build(options = {:sdk => @sdk}) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/xcode/builder.rb', line 31

def build(options = {:sdk => @sdk})    
  cmd = build_command(options)
  with_keychain do
    Xcode::Shell.execute(cmd)
  end
  self
end

#cleanObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/xcode/builder.rb', line 80

def clean
  cmd = []
  cmd << "xcodebuild"
  cmd << "-project \"#{@target.project.path}\""
  cmd << "-sdk #{@sdk}" unless @sdk.nil?
  
  cmd << "-scheme \"#{@scheme.name}\"" unless @scheme.nil?
  cmd << "-target \"#{@target.name}\"" if @scheme.nil?
  cmd << "-configuration \"#{@config.name}\"" if @scheme.nil?
  
  cmd << "OBJROOT=\"#{@build_path}\""
  cmd << "SYMROOT=\"#{@build_path}\""
  cmd << "clean"
  Xcode::Shell.execute(cmd)
  
  @built = false
  @packaged = false
  # FIXME: Totally not safe
  # cmd = []
  # cmd << "rm -Rf #{build_path}"
  # Xcode::Shell.execute(cmd)
  self
end

#configuration_build_pathObject



161
162
163
# File 'lib/xcode/builder.rb', line 161

def configuration_build_path
  "#{build_path}/#{@config.name}-#{@sdk}"
end

#dsym_pathObject



183
184
185
# File 'lib/xcode/builder.rb', line 183

def dsym_path
  "#{app_path}.dSYM"
end

#dsym_zip_pathObject



187
188
189
# File 'lib/xcode/builder.rb', line 187

def dsym_zip_path
  "#{product_version_basename}.dSYM.zip"
end

#entitlements_pathObject



165
166
167
# File 'lib/xcode/builder.rb', line 165

def entitlements_path
  "#{build_path}/#{@target.name}.build/#{name}-#{@target.project.sdk}/#{@target.name}.build/#{@config.product_name}.xcent"
end

#ipa_pathObject



179
180
181
# File 'lib/xcode/builder.rb', line 179

def ipa_path
  "#{product_version_basename}.ipa"
end

#packageObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/xcode/builder.rb', line 124

def package
  raise "Can't find #{app_path}, do you need to call builder.build?" unless File.exists? app_path
  
  #package IPA
  cmd = []      
  cmd << "xcrun"
  cmd << "-sdk #{@sdk}" unless @sdk.nil?
  cmd << "PackageApplication"
  cmd << "-v \"#{app_path}\""
  cmd << "-o \"#{ipa_path}\""
  
  # cmd << "OTHER_CODE_SIGN_FLAGS=\"--keychain #{@keychain.path}\"" unless @keychain.nil?
  # 
  # unless @identity.nil?
  #   cmd << "--sign \"#{@identity}\""
  # end
  
  unless @profile.nil?
    cmd << "--embed \"#{@profile}\""
  end
  
  with_keychain do
    Xcode::Shell.execute(cmd)
  end
  
  # package dSYM
  cmd = []
  cmd << "zip"
  cmd << "-r"
  cmd << "-T"
  cmd << "-y \"#{dsym_zip_path}\""
  cmd << "\"#{dsym_path}\""
  Xcode::Shell.execute(cmd)

  self
end

#product_version_basenameObject



173
174
175
176
177
# File 'lib/xcode/builder.rb', line 173

def product_version_basename
  version = @config.info_plist.version
  version = "SNAPSHOT" if version.nil? or version==""
  "#{configuration_build_path}/#{@config.product_name}-#{@config.name}-#{version}"
end

#signObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/xcode/builder.rb', line 104

def sign
  cmd = []
  cmd << "codesign"
  cmd << "--force"
  cmd << "--sign \"#{@identity}\""
  cmd << "--resource-rules=\"#{app_path}/ResourceRules.plist\""
  cmd << "--entitlements \"#{entitlements_path}\""
  cmd << "\"#{ipa_path}\""
  Xcode::Shell.execute(cmd)
 
# CodeSign build/AdHoc-iphoneos/Dial.app
#     cd "/Users/ray/Projects/Clients/CBAA/Community Radio"
#     setenv CODESIGN_ALLOCATE /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/codesign_allocate
#     setenv PATH "/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Developer/usr/bin:/Users/ray/.rvm/gems/ruby-1.9.2-p290@cbaa/bin:/Users/ray/.rvm/gems/ruby-1.9.2-p290@global/bin:/Users/ray/.rvm/rubies/ruby-1.9.2-p290/bin:/Users/ray/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin"
#     /usr/bin/codesign --force --sign "iPhone Distribution: Community Broadcasting Association of Australia" "--resource-rules=/Users/ray/Projects/Clients/CBAA/Community Radio/build/AdHoc-iphoneos/Dial.app/ResourceRules.plist" --keychain "\"/Users/ray/Projects/Clients/CBAA/Community\\" "Radio/Provisioning/CBAA.keychain\"" --entitlements "/Users/ray/Projects/Clients/CBAA/Community Radio/build/CommunityRadio.build/AdHoc-iphoneos/CommunityRadio.build/Dial.xcent" "/Users/ray/Projects/Clients/CBAA/Community Radio/build/AdHoc-iphoneos/Dial.app"
# iPhone Distribution: Community Broadcasting Association of Australia: no identity found
# Command /usr/bin/codesign failed with exit code 1
  self
end

#test(options = {:sdk => 'iphonesimulator'}) ⇒ Object

Invoke the configuration’s test target and parse the resulting output

If a block is provided, the report is yielded for configuration before the test is run



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/xcode/builder.rb', line 44

def test(options = {:sdk => 'iphonesimulator'}) #, :parser => :OCUnit })
  cmd = build_command(options)
  cmd << "TEST_AFTER_BUILD=YES"
  
  report = Xcode::Test::Report.new
  if block_given?
    yield(report)
  else
    report.add_formatter :stdout
    report.add_formatter :junit, 'test-reports'
  end
  
  parser = Xcode::Test::Parsers::OCUnitParser.new report
  
  begin
    Xcode::Shell.execute(cmd, false) do |line|
      parser << line
    end
  rescue Xcode::Shell::ExecutionError => e
    puts "Test platform exited: #{e.message}"
  ensure
    parser.flush
  end
  
  report
end

#testflight(api_token, team_token) {|testflight| ... } ⇒ Object

Yields:



71
72
73
74
75
76
77
78
# File 'lib/xcode/builder.rb', line 71

def testflight(api_token, team_token)
  raise "Can't find #{ipa_path}, do you need to call builder.package?" unless File.exists? ipa_path
  raise "Can't fins #{dsym_zip_path}, do you need to call builder.package?" unless File.exists? dsym_zip_path
  
  testflight = Xcode::Testflight.new(api_token, team_token)
  yield(testflight) if block_given?
  testflight.upload(ipa_path, dsym_zip_path)
end