Ray Yamamoto Hilton
Freelance Mobile Architect & iOS Developer in Melbourne, Australia
~

Control XCode builds from Ruby

Previously I had created an Xcode plugin for Hudson to allow you to configure and invoke builds directly. Although this worked for some cases, there are a few projects where the build process is more complex or non-standard enough to force me back to scripting things manually. Rather than update the plugin to try and cope with every esoteric use case, I decided to flip things around and simple create a ruby-wrapper for Xcode. This allows me to take what i need and create a custom Rakefile to control the build process.

The aim of this gem is to provide an object model for navigating the project structure and be able to invoke some common types of modifications. I aim to gradually add more functionality to this gem as I come across new use cases.

The source is available on github, but it is available to install from ruby forge by using the command:

$ gem install xcoder

A simple use-case would be to find the only project in a directory, update the project’s build number and then invoke a build:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Find the first project in the current directory
project = Xcode.find_projects.first

# Find the target called "TargetName"
target = project.target(:TargetName)

# Find the configuration called "Debug"
config = config.config(:Debug)

# Update the build number
config.info_plist do |info|
    info.version = ENV['BUILD_NUMBER']
    info.save
end

# Clean the build for this target's configuration 
config.clean

# Build the target using this configuration
config.build

# Create an IPA for this target's configuration signed using the provided identity and embed the provided profile
config.package :sign => 'iPhone Distribution: Developer Name, :profile => 'Provisioning/ProfileToEmbed.mobileprovision'

It’s early days yet, but I plan on adding support for OCUnit => JUnit output mapping (like the xcode-hudson-plugin) as well as loading provisioning profiles from the file system and generally manipulating the project file. Please send issues/feature requests to the Xcoder page on github