Skip to content

Instantly share code, notes, and snippets.

@burtlo
Created March 1, 2012 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burtlo/1953158 to your computer and use it in GitHub Desktop.
Save burtlo/1953158 to your computer and use it in GitHub Desktop.
Initial Xcode Project Rakefile
require 'tmpdir'
CONFIGURATION = "Debug"
SIMULATOR_DIR = File.expand_path('~/Library/Application Support/iPhone Simulator/5.0')
BUILD_DIR = File.join(File.dirname(__FILE__), "build")
XCODEBUILD_BIN = 'xcodebuild'
SDK_DIR = "/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk"
def output_file(target)
Dir.mkdir(BUILD_DIR) unless File.exists?(BUILD_DIR)
output_dir = BUILD_DIR
output_file = File.join(output_dir, "#{target}.output")
puts "Output: #{output_file}"
output_file
end
def build(target)
puts "--------- Building target: #{target}"
system_or_exit(%Q[#{XCODEBUILD_BIN} -project project-ios.xcodeproj -target #{target} -configuration #{CONFIGURATION} build -sdk iphonesimulator5.0 -arch 'i386' SYMROOT=#{BUILD_DIR}], output_file("uispecs"))
end
def build_dir(effective_platform_name)
File.join(BUILD_DIR, CONFIGURATION + effective_platform_name)
end
def system_or_exit(cmd, stdout = nil)
puts "Executing #{cmd}"
puts
cmd += " >#{stdout}" if stdout
system(cmd) or raise "******** Build failed ********"
end
def run_specs(target)
puts "--------- Running specs for: #{target}"
ENV["DYLD_ROOT_PATH"] = SDK_DIR
ENV["IPHONE_SIMULATOR_ROOT"] = SDK_DIR
tempHome = Dir.mktmpdir("Cedar")
# Create commonly used application directories which the app might expect to exist
# http://developer.apple.com/library/ios/DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/RuntimeEnvironment/RuntimeEnvironment.html#//apple_ref/doc/uid/TP40007072-CH2-SW12
Dir.mkdir File.join(tempHome, "Documents")
Dir.mkdir File.join(tempHome, "Library")
Dir.mkdir File.join(tempHome, "Library/Preferences")
Dir.mkdir File.join(tempHome, "Library/Caches")
Dir.mkdir File.join(tempHome, "tmp")
ENV["CFFIXED_USER_HOME"] = tempHome
ENV["CEDAR_HEADLESS_SPECS"] = "1"
ENV["CEDAR_REPORTER_CLASS"] ||= "CDRColorizedReporter"
ENV['CEDAR_REPORTER_OPTS'] ||= 'nested'
puts `env |grep -E "(DYLD|CEDAR|IPHONE|CFFIXED)" | sort`
system_or_exit(%Q[#{File.join(build_dir("-iphonesimulator"), "#{target}.app", target)} -RegisterForSystemEvents])
end
task :default => :specs
desc 'Run the specs'
task :specs => ["build:specs", "simulator:quit" ] do
run_specs "project-specs"
end
namespace :build do
desc "Build the Project Specs"
task :specs do
build "project-specs"
end
end
namespace :simulator do
desc "Reset the iOS simulator"
task :reset do
FileUtils.rm_rf(SIMULATOR_DIR)
end
desc "Quit the iOS simulator if it is open"
task :quit do
`osascript -e 'tell application "iPhone Simulator" to quit'`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment