root/lang/ruby/Chemr/Rakefile

Revision 1256, 4.9 kB (checked in by cho45, 13 months ago)

lang/ruby/Chemr/Rakefile,
lang/ruby/Chemr/CHMDocument.rb:

Leopard でなんかエラーでるらしいやつの解決
原因不明だけどデバッグできない

Line 
1require 'rubygems'
2require 'rake'
3require 'rake/clean'
4require 'rake/testtask'
5require 'pathname'
6
7# Application own Settings
8APPNAME               = "Chemr"
9TARGET                = "#{APPNAME}.app"
10#VERSION               = "rev#{`svn info`[/Revision: (\d+)/, 1]}"
11VERSION               = Time.now.strftime("%Y-%m-%d")
12PUBLISH               = 'yourname@yourhost:path'
13DEFAULT_TARGET        = APPNAME
14DEFAULT_CONFIGURATION = 'Release'
15RELEASE_CONFIGURATION = 'Release'
16
17# Tasks
18task :default => [:run]
19
20desc "Build the default and run it."
21task :run => [:build] do
22        sh %{open "build/Release/#{APPNAME}.app"}
23end
24
25desc 'Build the default target using the default configuration'
26task :build => "xcode:build:#{DEFAULT_TARGET}:#{DEFAULT_CONFIGURATION}"
27
28desc 'Deep clean of everything'
29task :clean do
30        puts %x{ xcodebuild -alltargets clean }
31end
32
33desc "Add files to Xcode project"
34task :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)
39end
40
41desc "Create ruby skelton and add to Xcode project"
42task :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
48end
49
50desc "Update nib with ruby file"
51task :update do |t|
52        args = ARGV[1..-1]
53        args.unshift("English.lproj/MainMenu.nib")
54        exec("rubycocoa", "update", *args)
55end
56
57desc "Package the application"
58task :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        }
88end
89
90desc "Publish package to my site"
91task :publish => [:package] do
92        name = "#{APPNAME}.#{VERSION}"
93        sh %{scp "pkg/#{name}.dmg" c:www/lab.lowreal.net/public/test/chemr/}
94end
95
96directory 'pkg'
97
98desc 'Make Localized nib from English.lproj and Lang.lproj/nib.strings'
99rule(/.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        }
107end
108
109# [Rubycocoa-devel 906] dynamically xcode rake tasks
110# [Rubycocoa-devel 907]
111#
112def 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
122end
123
124def 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
134end
135
136namespace :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
172end
173
174
175if ["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
180end
Note: See TracBrowser for help on using the browser.