Class: Xcode::Buildspec::TaskBuilder

Inherits:
Rake::TaskLib
  • Object
show all
Includes:
Rake::DSL
Defined in:
lib/xcode/buildspec.rb

Instance Method Summary collapse

Constructor Details

#initializeTaskBuilder

Returns a new instance of TaskBuilder.



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

def initialize
  @before = lambda {|builder| return nil }
  @deployments = []
  @build_number = lambda do
    timestamp = Time.now.strftime("%Y%m%d%H%M%S")
    ENV['BUILD_NUMBER']||"SNAPSHOT-#{Socket.gethostname}-#{timestamp}"
  end

  # @profile = "Provisioning/#{name}.mobileprovision"
end

Instance Method Details

#before(&block) ⇒ Object

A block to run before each builder invocation

If supplied, the block will be yielded the builder object just before the invocation of clean/build/package

Parameters:

  • the

    block to call



102
103
104
# File 'lib/xcode/buildspec.rb', line 102

def before &block
  @before = block
end

#build_number(&block) ⇒ Object

A block to generate the build number

This is optional, by default it will use ENV or create a snapshot filename based on the hostname and time

Parameters:

  • the

    block to generate the build number



114
115
116
# File 'lib/xcode/buildspec.rb', line 114

def build_number &block
  @build_number = block
end

#builderObject

Internally used to lazily instantiate the builder given the properties that have been set.

Returns:

  • the appropriate builder



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/xcode/buildspec.rb', line 186

def builder
  return @builder unless @builder.nil?

  raise "profile must be defined" if @profile.nil?
  raise "project/workspace must be defined" if @filename.nil?

  begin 
    project = Xcode.project @filename
    @builder = project.target(@args[:target]).config(@args[:config]).builder
  rescue
    workspace = Xcode.workspace @filename
    @builder = workspace.scheme(@args[:scheme]).builder
  rescue
    raise "You must provide a project or workspace"          
  end          

  raise "Could not create a builder using #{@args}" if @builder.nil?
  
  unless @platform.nil?
    builder.sdk = @platform.sdk
  end 

  unless @identity.nil?
    builder.identity = @identity
  end

  unless @keychain.nil?
    keychain = Xcode::Keychain.new @keychain[:path]
    keychain.unlock @keychain[:password] unless @keychain[:password].nil?

    builder.identity = keychain.identities.first
    builder.keychain = keychain
  end
  
  builder.profile = @profile

  @before.call builder

  @builder
end

#deploy(type, args = {}) ⇒ Object

Set a deployment target.

This will configure a set of deploy: targets that will send the .ipa to various services (testflight, s3, ftp, sftp, etc)

Parameters:

  • the

    deployment type (testflight, etc)

  • arguments

    to pass to the deployment type



170
171
172
# File 'lib/xcode/buildspec.rb', line 170

def deploy type, args = {}
  @deployments << {:type => type, :args => args}
end

#generate_rake_tasksObject

Create a set of rake tasks for this buildspec



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/xcode/buildspec.rb', line 234

def generate_rake_tasks
require 'socket'

# namespace project_name.downcase do

  desc "Clean #{project_name}"
  task :clean do
    builder.clean
  end

  desc "Fetch dependencies for #{project_name}"
  task :deps do 
    builder.dependencies
  end

  desc "Build #{project_name}"
  task :build => [:clean, :deps] do
    builder.config.info_plist do |info|
      info.version = @build_number.call
      info.save
    end
    builder.build
  end

  desc "Test #{project_name}" 
  task :test => [:deps] do 
    builder.test
  end

  desc "Package (.ipa & .dSYM.zip) #{project_name}"
  task :package => [:build, :test] do
    builder.package
  end

  namespace :deploy do
    @deployments.each do |deployment|
      desc "Deploy #{project_name} to #{deployment[:type]}"
      task deployment[:type]  => [:package] do
        builder.deploy deployment[:type], deployment[:args]
      end
    end

    desc "Deploy #{project_name} to all"
    task :all  => [:package]+(@deployments.map{|k,v| k[:type]}) do
      puts "Deployed to all"
    end
  end
end

#identity(identity) ⇒ Object

Set’s the identity to use to sign the package

This should be the name of the identity in your keychain, such as ‘iPhone Distribution: My Name’

Parameters:

  • the

    name of the identity



149
150
151
# File 'lib/xcode/buildspec.rb', line 149

def identity identity
  @identity = identity
end

#keychain(path, password = nil) ⇒ Object

Configure a keychain to use (optional)

If specified, the keychain at the given path will be unlocked during the build and the first identity will be set on the builder

Parameters:

  • the

    path to the keychain

  • the

    password to unlock the keychain



127
128
129
# File 'lib/xcode/buildspec.rb', line 127

def keychain path, password = nil
  @keychain = {:path => path, :password => password}
end

#notify(type, args = {}) ⇒ Object



175
176
177
# File 'lib/xcode/buildspec.rb', line 175

def notify type, args = {}
  @notifications << {:type => type, :args => args}
end

#platform(name, version = nil) ⇒ Object

Specify the platform to build for

Parameters:

  • the

    platform, can be ‘iphone’, ‘iphonesimulator’, ‘macosx’

  • the

    version, can be any valid, installed sdk version for the appropriate platform or nil



137
138
139
# File 'lib/xcode/buildspec.rb', line 137

def platform name, version=nil
  @platform = Xcode::Platforms.find name, version
end

#profile(profile) ⇒ Object

Set the profile (i.e. .mobileprovision) to use

Parameters:

  • the

    name or path to the profile



157
158
159
# File 'lib/xcode/buildspec.rb', line 157

def profile profile
  @profile = profile
end

#project_nameObject



227
228
229
# File 'lib/xcode/buildspec.rb', line 227

def project_name
  builder.product_name
end

#use(filename, args = {}) ⇒ Object

Use the given project/workspace file

This must be provided.

Parameters:

  • the

    path to the .xcodeproj or .xcworkspace

  • a

    hash containing => ” or => ”, :config => ”



89
90
91
92
# File 'lib/xcode/buildspec.rb', line 89

def use filename, args={}
  @filename = filename
  @args = args
end