iPhone Capistrano deployment

October 28th, 2008

You can automatically deploy your own application to the iPhonedevice by using Capistrano.

Requirements: Capistrano (gem install capistrano) and ldid (install via Cydia).

Build your application for the ARM architecture:

  bjam --toolset=darwin macosx-version=iphone-2.0 architecture=arm release

Deploy the application to the iPhone:

  cap deploy

Your app is packaged (tar), copied (scp) to your iphone and SpringBoards is restarted. I use the following Capfile:

set :application_name, "LocateMe" 
set :iphone_ip, "" 
set :user, "root" 
# password = alpine

desc "Package your iPhone application" 
task :package do
 %x[cd "~/Library/Application Support/iPhone Simulator/User/Applications/00000000-0000-0000-0000-000000000000" && \
    tar -czpvf #{application_name}.tar.gz #{application_name}.app && \
    scp #{application_name}.tar.gz #{user}@#{iphone_ip}:/Applications]

desc "Install the application on your iPhone" 
task :install, :hosts => "#{iphone_ip}" do
  run <<-CMD
    cd /Applications/;
    tar -xzpvf #{application_name}.tar.gz;
    rm #{application_name}.tar.gz;
    ldid -S /Applications/#{application_name}.app/#{application_name};
    killall SpringBoard;                  # OS 2.0
#   /Applications/; # OS 2.1

desc "Package and install the application on your iPhone" 
task :deploy, :hosts => "#{iphone_ip}" do

Here’s an example Jamfile that you can use to build the LocateMe example with BJAM. The jamfile basically just sums up the sources and resources that need to be compiled. BJAM already supports the Darwin toolset.

The application is compiled and installed in your iPhone Simulator user directory. If you want to compile for the iPhone Simulator you invoke bjam with the following command:

bjam --toolset=darwin macosx-version=iphonesim-2.0
If you want to compile for the iPhone device you have to change the architecture to ARM.

bjam --toolset=darwin macosx-version=iphone-2.0 architecture=arm release

Also see the article about automatically deploying your application to the iPhone using Capistrano.

The complete jamfile.v2 for reference:

# jamfile.v2
# bjam --toolset=darwin macosx-version=iphonesim-2.0
# bjam --toolset=darwin macosx-version=iphone-2.0 architecture=arm release

import ibtool ;

project locate_me
  : source-location .
  : requirements
  : usage-requirements

# RESOURCES = Background.png Default.png HelloWorld.xib MainWindow.xib Icon.png Info.plist ;
RESOURCES = Default.png Icon.png Info.plist Localizable.strings ;

nib resources/FlipsideView : en.lproj/FlipsideView.xib ;
nib resources/MainView : en.lproj/MainView.xib ;
nib resources/MainWindow : en.lproj/MainWindow.xib ;

alias compiled_resources : resources/FlipsideView resources/MainView resources/MainWindow ;

exe LocateMe
  : main.m
  : <framework>/System/Library/Frameworks/UIKit

install simulator
  : LocateMe
    <location>"~/Library/Application Support/iPhone Simulator/User/Applications/00000000-0000-0000-0000-000000000000/" 

install resources
  : $(RESOURCES) compiled_resources
  : <location>"~/Library/Application Support/iPhone Simulator/User/Applications/00000000-0000-0000-0000-000000000000/"