1# -*- mode:ruby; indent-tabs-mode:nil; coding:utf-8 -*- 2# vim:ts=2:sw=2:expandtab: 3require 'rubygems' 4require 'rake' 5require 'rake/clean' 6require 'rake/testtask' 7require 'pathname' 8 9# Application own Settings 10APPNAME = "«PROJECTNAME»" 11TARGET = "#{APPNAME}.app" 12#APPVERSION = "rev#{`svn info`[/Revision: (\d+)/, 1]}" 13APPVERSION = Time.now.strftime("%Y-%m-%d") 14PUBLISH = 'yourname@yourhost:path' 15DEFAULT_TARGET = APPNAME 16DEFAULT_CONFIGURATION = 'Release' 17RELEASE_CONFIGURATION = 'Release' 18 19# Tasks 20task :default => [:run] 21 22desc "Build the default and run it." 23task :run => [:build] do 24 sh %{open "build/Release/#{APPNAME}.app"} 25end 26 27desc 'Build the default target using the default configuration' 28task :build => "xcode:build:#{DEFAULT_TARGET}:#{DEFAULT_CONFIGURATION}" 29 30desc 'Deep clean of everything' 31task :clean do 32 puts %x{ xcodebuild -alltargets clean } 33end 34 35desc "Add files to Xcode project" 36task :add do |t| 37 files = ARGV[1..-1] 38 project = %x{ xcodebuild -list }[/Information about project "([^"]+)":/, 1] 39 files << "#{project}.xcodeproj" 40 exec("rubycocoa", "add", *files) 41end 42 43desc "Create ruby skelton and add to Xcode project" 44task :create do |t| 45 args = ARGV[1..-1] 46 if system("rubycocoa", "create", *args) 47 project = %x{ xcodebuild -list }[/Information about project "([^"]+)":/, 1] 48 exec("rubycocoa", "add", args.last + ".rb", "#{project}.xcodeproj") 49 end 50end 51 52desc "Update nib with ruby file" 53task :update do |t| 54 args = ARGV[1..-1] 55 args.unshift("English.lproj/MainMenu.nib") 56 exec("rubycocoa", "update", *args) 57end 58 59desc "Package the application" 60task :package => ["xcode:build:#{DEFAULT_TARGET}:#{RELEASE_CONFIGURATION}", "pkg"] do 61 name = "#{APPNAME}.#{APPVERSION}" 62 mkdir "image" 63 sh %{rubycocoa standaloneify "build/#{DEFAULT_CONFIGURATION}/#{APPNAME}.app" "image/#{APPNAME}.app"} 64 puts 'Creating Image...' 65 sh %{ 66 hdiutil create -volname '#{name}' -srcfolder image '#{name}'.dmg 67 rm -rf image 68 mv '#{name}.dmg' pkg 69 } 70end 71 72directory 'pkg' 73 74desc 'Make Localized nib from English.lproj and Lang.lproj/nib.strings' 75rule(/.nib$/ => [proc {|tn| File.dirname(tn) + '/nib.strings' }]) do |t| 76 p t.name 77 lproj = File.dirname(t.name) 78 target = File.basename(t.name) 79 rm_rf t.name 80 sh %{ 81 nibtool -d #{lproj}/nib.strings -w #{t.name} English.lproj/#{target} 82 } 83end 84 85# [Rubycocoa-devel 906] dynamically xcode rake tasks 86# [Rubycocoa-devel 907] 87# 88def xcode_targets 89 out = %x{ xcodebuild -list } 90 out.scan(/.*Targets:\s+(.*)Build Configurations:.*/m) 91 92 targets = [] 93 $1.each_line do |l| 94 l = l.strip.sub(' (Active)', '') 95 targets << l unless l.nil? or l.empty? 96 end 97 targets 98end 99 100def xcode_configurations 101 out = %x{ xcodebuild -list } 102 out.scan(/.*Build Configurations:\s+(.*)If no build configuration.*/m) 103 104 configurations = [] 105 $1.each_line do |l| 106 l = l.strip.sub(' (Active)', '') 107 configurations << l unless l.nil? or l.empty? 108 end 109 configurations 110end 111 112namespace :xcode do 113 targets = xcode_targets 114 configs = xcode_configurations 115 116 %w{build clean}.each do |action| 117 namespace "#{action}" do 118 119 targets.each do |target| 120 desc "#{action} #{target}" 121 task "#{target}" do |t| 122 puts %x{ xcodebuild -target '#{target}' #{action} } 123 end 124 125 # alias the task above using a massaged name 126 massaged_target = target.downcase.gsub(/[\s*|\-]/, '_') 127 task "#{massaged_target}" => "xcode:#{action}:#{target}" 128 129 130 namespace "#{target}" do 131 configs.each do |config| 132 desc "#{action} #{target} #{config}" 133 task "#{config}" do |t| 134 puts %x{ xcodebuild -target '#{target}' -configuration '#{config}' #{action} } 135 end 136 end 137 end 138 139 # namespace+task aliases of the above using massaged names 140 namespace "#{massaged_target}" do 141 configs.each { |conf| task "#{conf.downcase.gsub(/[\s*|\-]/, '_')}" => "xcode:#{action}:#{target}:#{conf}" } 142 end 143 144 end 145 146 end 147 end 148end 149 150 151if ["update", "add", "create"].include? ARGV[0] 152 # dupe rake 153 ARGV.map! {|a| a.sub(/^\+/, "-") } 154 Rake.application[ARGV[0].to_sym].invoke 155 exit # will not reach 156end 157