refactor rake config

This commit is contained in:
Laurent Sansonetti
2011-10-24 19:45:20 +02:00
parent f4d913db46
commit 082f0b7050
8 changed files with 72 additions and 43 deletions

View File

@@ -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

25
lib/rubixir/rake/app.rb Normal file
View File

@@ -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

View File

@@ -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.

View File

@@ -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
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>#{@app_name}</string>
<string>#{@name}</string>
<key>CFBundleExecutable</key>
<string>#{@app_name}</string>
<string>#{@name}</string>
<key>CFBundleIdentifier</key>
<string>com.omgwtf.#{@app_name}</string>
<string>com.omgwtf.#{@name}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>#{@app_name}</string>
<string>#{@name}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleResourceSpecification</key>

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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