diff --git a/lib/rubixir/rake.rb b/lib/rubixir/rake.rb index 6c459e90..06d66647 100644 --- a/lib/rubixir/rake.rb +++ b/lib/rubixir/rake.rb @@ -1,24 +1,20 @@ +require 'rubixir/rake/app' require 'rubixir/rake/config' require 'rubixir/rake/builder' -module Rubixir - CONFIG = Config.new('.') - BUILDER = Builder.new -end - desc "Build the project, then run the simulator" task :default => :simulator namespace :build do desc "Build the simulator version" task :simulator do - Rubixir::BUILDER.build(Rubixir::CONFIG, 'iPhoneSimulator') + Motion::App.build('iPhoneSimulator') end desc "Build the iOS version" task :ios do - Rubixir::BUILDER.build(Rubixir::CONFIG, 'iPhoneOS') - Rubixir::BUILDER.codesign(Rubixir::CONFIG, 'iPhoneOS') + Motion::App.build('iPhoneOS') + Motion::App.codesign('iPhoneOS') end desc "Build everything" @@ -27,11 +23,12 @@ end desc "Run the simulator" task :simulator => ['build:simulator'] do - sim = File.join(Rubixir::CONFIG.datadir, 'sim') + sim = File.join(Motion::App.config.datadir, 'sim') debug = (ENV['debug'] || '0') == '1' ? 1 : 0 - app = Rubixir::CONFIG.app_bundle('iPhoneSimulator') - family = Rubixir::CONFIG.device_family_ints[0] - sh "#{sim} #{debug} #{family} #{Rubixir::CONFIG.sdk_version} \"#{app}\"" + app = Motion::App.config.app_bundle('iPhoneSimulator') + family = Motion::App.config.device_family_ints[0] + sdk_version = Motion::App.config.sdk_version + sh "#{sim} #{debug} #{family} #{sdk_version} \"#{app}\"" end desc "Create an .ipa package" @@ -39,29 +36,29 @@ task :package => ['build:ios'] do tmp = "/tmp/ipa_root" sh "/bin/rm -rf #{tmp}" sh "/bin/mkdir -p #{tmp}/Payload" - sh "/bin/cp -r \"#{Rubixir::CONFIG.app_bundle('iPhoneOS')}\" #{tmp}/Payload" + sh "/bin/cp -r \"#{Motion::App.config.app_bundle('iPhoneOS')}\" #{tmp}/Payload" Dir.chdir(tmp) do sh "/bin/chmod -R 755 Payload" sh "/usr/bin/zip -q -r archive.zip Payload" end - sh "/bin/cp #{tmp}/archive.zip \"#{Rubixir::CONFIG.archive}\"" + sh "/bin/cp #{tmp}/archive.zip \"#{Motion::App.config.archive}\"" end desc "Deploy on the device" task :deploy => :package do - deploy = File.join(Rubixir::CONFIG.datadir, 'deploy') + deploy = File.join(Motion::App.config.datadir, 'deploy') flags = Rake.application.options.trace ? '-d' : '' - sh "#{deploy} #{flags} \"#{Rubixir::CONFIG.archive}\"" + sh "#{deploy} #{flags} \"#{Motion::App.config.archive}\"" end desc "Clear build objects" task :clean do - rm_rf(Rubixir::CONFIG.build_dir) + rm_rf(Motion::App.config.build_dir) end desc "Show project config" task :config do - map = Rubixir::CONFIG.variables + map = Motion::App.config.variables map.keys.sort.each do |key| puts key.ljust(20) + " = #{map[key].inspect}" end diff --git a/lib/rubixir/rake/app.rb b/lib/rubixir/rake/app.rb new file mode 100644 index 00000000..673516b2 --- /dev/null +++ b/lib/rubixir/rake/app.rb @@ -0,0 +1,25 @@ +module Motion + class App + class << self + def config + @config ||= Motion::Config.new('.') + end + + def builder + @builder ||= Motion::Builder.new + end + + def setup + yield config + end + + def build(platform) + builder.build(config, platform) + end + + def codesign(platform) + builder.codesign(config, platform) + end + end + end +end diff --git a/lib/rubixir/rake/builder.rb b/lib/rubixir/rake/builder.rb index 3d9be487..fbdfeba1 100644 --- a/lib/rubixir/rake/builder.rb +++ b/lib/rubixir/rake/builder.rb @@ -1,4 +1,4 @@ -module Rubixir +module Motion class Builder def build(config, platform) datadir = config.datadir @@ -120,7 +120,7 @@ EOS rb_vm_print_current_exception(); rb_exit(1); } - int retval = UIApplicationMain(argc, argv, nil, @"AppDelegate"); + int retval = UIApplicationMain(argc, argv, nil, @"#{config.delegate_class}"); [pool release]; rb_exit(retval); } @@ -136,11 +136,11 @@ EOS end # Prepare bundle. - bundle_path = File.join(build_dir, config.app_name + '.app') + bundle_path = File.join(build_dir, config.name + '.app') FileUtils.mkdir_p(bundle_path) # Link executable. - main_exec = File.join(bundle_path, config.app_name) + main_exec = File.join(bundle_path, config.name) objs_list = objs.map { |path, _| path }.unshift(main_o).map { |x| "\"#{x}\"" }.join(' ') frameworks = config.frameworks.map { |x| "-framework #{x}" }.join(' ') framework_stubs_objs = [] @@ -169,7 +169,7 @@ EOS end def codesign(config, platform) - bundle_path = File.join(config.build_dir, platform, config.app_name + '.app') + bundle_path = File.join(config.build_dir, platform, config.name + '.app') raise unless File.exist?(bundle_path) # Create bundle/ResourceRules.plist. diff --git a/lib/rubixir/rake/config.rb b/lib/rubixir/rake/config.rb index dfcedc33..2a544a4d 100644 --- a/lib/rubixir/rake/config.rb +++ b/lib/rubixir/rake/config.rb @@ -1,4 +1,4 @@ -module Rubixir +module Motion class Config VARS = [] @@ -23,7 +23,7 @@ module Rubixir end variable :files, :platforms_dir, :sdk_version, :frameworks, - :app_delegate_class, :app_name, :build_dir, :resources_dir, + :delegate_class, :name, :build_dir, :resources_dir, :codesign_certificate, :provisioning_profile, :device_family def initialize(project_dir) @@ -32,8 +32,8 @@ module Rubixir @dependencies = {} @platforms_dir = '/Developer/Platforms' @frameworks = ['UIKit', 'Foundation', 'CoreGraphics'] - @app_delegate_class = 'AppDelegate' - @app_name = 'My App' + @delegate_class = 'AppDelegate' + @name = 'My App' @build_dir = File.join(project_dir, 'build') @resources_dir = File.join(project_dir, 'resources') @device_family = :iphone @@ -106,11 +106,11 @@ module Rubixir end def app_bundle(platform) - File.join(@build_dir, platform, @app_name + '.app') + File.join(@build_dir, platform, @name + '.app') end def archive - File.join(@build_dir, @app_name + '.ipa') + File.join(@build_dir, @name + '.ipa') end def device_family_ints @@ -137,15 +137,15 @@ module Rubixir CFBundleDevelopmentRegion en CFBundleDisplayName - #{@app_name} + #{@name} CFBundleExecutable - #{@app_name} + #{@name} CFBundleIdentifier - com.omgwtf.#{@app_name} + com.omgwtf.#{@name} CFBundleInfoDictionaryVersion 6.0 CFBundleName - #{@app_name} + #{@name} CFBundlePackageType APPL CFBundleResourceSpecification diff --git a/sample/hello/Rakefile b/sample/hello/Rakefile index 93d2a6ce..1c3786b4 100644 --- a/sample/hello/Rakefile +++ b/sample/hello/Rakefile @@ -1,5 +1,7 @@ $:.unshift('../../lib') require 'rubixir/rake' -Rubixir::CONFIG.app_name = 'Hello' -Rubixir::CONFIG.device_family = :iphone +Motion::App.setup do |app| + app.name = 'Hello' + app.device_family = :iphone +end diff --git a/sample/mapview/Rakefile b/sample/mapview/Rakefile index da2e3695..de61c803 100644 --- a/sample/mapview/Rakefile +++ b/sample/mapview/Rakefile @@ -1,7 +1,9 @@ $:.unshift('../../lib') require 'rubixir/rake' -Rubixir::CONFIG.app_name = 'mapview' -Rubixir::CONFIG.frameworks << 'CoreLocation' -Rubixir::CONFIG.frameworks << 'MapKit' -Rubixir::CONFIG.frameworks << 'AddressBook' +Motion::App.setup do |app| + app.name = 'mapview' + app.frameworks << 'CoreLocation' + app.frameworks << 'MapKit' + app.frameworks << 'AddressBook' +end diff --git a/sample/paint/Rakefile b/sample/paint/Rakefile index dc65138c..49ebf057 100644 --- a/sample/paint/Rakefile +++ b/sample/paint/Rakefile @@ -1,5 +1,7 @@ $:.unshift('../../lib') require 'rubixir/rake' -Rubixir::CONFIG.app_name = 'paint' -Rubixir::CONFIG.frameworks << 'AVFoundation' +Motion::App.setup do |app| + app.name = 'Paint' + app.frameworks << 'AVFoundation' +end diff --git a/sample/tableview/Rakefile b/sample/tableview/Rakefile index 8d40c650..ad9546ec 100644 --- a/sample/tableview/Rakefile +++ b/sample/tableview/Rakefile @@ -1,5 +1,6 @@ $:.unshift('../../lib') require 'rubixir/rake' -Rubixir::CONFIG.app_name = 'TableView' -Rubixir::CONFIG.device_family = :iphone +Motion::App.setup do |app| + app.name = 'TableView' +end