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