Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/tags/rel_0-13-1/railties/Rakefile

Revision 1816, 13.6 kB (checked in by david, 3 years ago)

Tagged the 0.13.1 release

Line 
1 require 'rake'
2 require 'rake/testtask'
3 require 'rake/rdoctask'
4 require 'rake/gempackagetask'
5 require 'rake/contrib/rubyforgepublisher'
6
7 require 'date'
8 require 'rbconfig'
9
10 PKG_BUILD       = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
11 PKG_NAME        = 'rails'
12 PKG_VERSION     = '0.13.1' + PKG_BUILD
13 PKG_FILE_NAME   = "#{PKG_NAME}-#{PKG_VERSION}"
14 PKG_DESTINATION = ENV["RAILS_PKG_DESTINATION"] || "../#{PKG_NAME}"
15
16 RELEASE_NAME  = "REL #{PKG_VERSION}"
17
18 RUBY_FORGE_PROJECT = "rails"
19 RUBY_FORGE_USER    = "webster132"
20
21
22 BASE_DIRS   = %w( app config/environments components db doc log lib public script test vendor )
23 APP_DIRS    = %w( apis models controllers helpers views views/layouts )
24 PUBLIC_DIRS = %w( images javascripts stylesheets )
25 TEST_DIRS   = %w( fixtures unit functional mocks mocks/development mocks/test )
26
27 LOG_FILES    = %w( server.log development.log test.log production.log )
28 HTML_FILES   = %w( 404.html 500.html index.html favicon.ico javascripts/prototype.js javascripts/effects.js javascripts/dragdrop.js javascripts/controls.js )
29 BIN_FILES    = %w( generate destroy breakpointer console server update runner profiler benchmarker ) # listener tracker
30
31 VENDOR_LIBS = %w( actionpack activerecord actionmailer activesupport actionwebservice railties )
32
33
34 desc "Default Task"
35 task :default => [ :fresh_rails ]
36
37 desc "Generates a fresh Rails package with documentation"
38 task :fresh_rails => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_vendor_libraries, :copy_ties_content, :generate_documentation ]
39
40 desc "Generates a fresh Rails package using GEMs with documentation"
41 task :fresh_gem_rails => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_ties_content, :copy_gem_environment ]
42
43 desc "Generates a fresh Rails package without documentation (faster)"
44 task :fresh_rails_without_docs => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_vendor_libraries, :copy_ties_content ]
45
46 desc "Generates a fresh Rails package without documentation (faster)"
47 task :fresh_rails_without_docs_using_links => [ :clean, :make_dir_structure, :initialize_file_stubs, :link_vendor_libraries, :copy_ties_content ]
48
49 desc "Generates minimal Rails package using symlinks"
50 task :dev => [ :clean, :make_dir_structure, :initialize_file_stubs, :link_vendor_libraries, :copy_ties_content ]
51
52 desc "Packages the fresh Rails package with documentation"
53 task :package => [ :clean, :fresh_rails ] do
54   system %{cd ..; tar -czvf #{PKG_NAME}-#{PKG_VERSION}.tgz #{PKG_NAME}}
55   system %{cd ..; zip -r #{PKG_NAME}-#{PKG_VERSION}.zip #{PKG_NAME}}
56 end
57
58 task :clean do
59   rm_rf PKG_DESTINATION
60 end
61
62 # Get external spinoffs -------------------------------------------------------------------
63
64 desc "Updates railties to the latest version of the javascript spinoffs"
65 task :update_js do
66   for js in %w( prototype controls dragdrop effects )
67     rm "html/javascripts/#{js}.js"
68     cp "./../actionpack/lib/action_view/helpers/javascripts/#{js}.js", "html/javascripts"
69   end
70 end
71
72 # Make directory structure ----------------------------------------------------------------
73
74 def make_dest_dirs(dirs, path = nil)
75   mkdir_p dirs.map { |dir| File.join(PKG_DESTINATION, path, dir) }
76 end
77
78 desc "Make the directory structure for the new Rails application"
79 task :make_dir_structure => [ :make_base_dirs, :make_app_dirs, :make_public_dirs, :make_test_dirs ]
80
81 task(:make_base_dirs)   { make_dest_dirs BASE_DIRS              }
82 task(:make_app_dirs)    { make_dest_dirs APP_DIRS,    'app'     }
83 task(:make_public_dirs) { make_dest_dirs PUBLIC_DIRS, 'public'  }
84 task(:make_test_dirs)   { make_dest_dirs TEST_DIRS,   'test'    }
85
86
87 # Initialize file stubs -------------------------------------------------------------------
88
89 desc "Initialize empty file stubs (such as for logging)"
90 task :initialize_file_stubs => [ :initialize_log_files ]
91
92 task :initialize_log_files do
93   log_dir = File.join(PKG_DESTINATION, 'log')
94   chmod 0777, log_dir
95   LOG_FILES.each do |log_file|
96     log_path = File.join(log_dir, log_file)
97     touch log_path
98     chmod 0666, log_path
99   end
100 end
101
102
103 # Copy Vendors ----------------------------------------------------------------------------
104
105 desc "Copy in all the Rails packages to vendor"
106 task :copy_vendor_libraries do
107   mkdir File.join(PKG_DESTINATION, 'vendor', 'rails')
108   VENDOR_LIBS.each { |dir| cp_r File.join('..', dir), File.join(PKG_DESTINATION, 'vendor', 'rails', dir) }
109 end
110
111 desc "Link in all the Rails packages to vendor"
112 task :link_vendor_libraries do
113   mkdir File.join(PKG_DESTINATION, 'vendor', 'rails')
114   VENDOR_LIBS.each { |dir| ln_s File.join('..', '..', '..', dir), File.join(PKG_DESTINATION, 'vendor', 'rails', dir) }
115 end
116
117
118 # Copy Ties Content -----------------------------------------------------------------------
119
120 # :link_apache_config
121 desc "Make copies of all the default content of ties"
122 task :copy_ties_content => [
123   :copy_rootfiles, :copy_dispatches, :copy_html_files, :copy_application,
124   :copy_configs, :copy_binfiles, :copy_test_helpers, :copy_app_doc_readme ]
125
126 task :copy_dispatches do
127   copy_with_rewritten_ruby_path("dispatches/dispatch.rb", "#{PKG_DESTINATION}/public/dispatch.rb")
128   chmod 0755, "#{PKG_DESTINATION}/public/dispatch.rb"
129
130   copy_with_rewritten_ruby_path("dispatches/dispatch.rb", "#{PKG_DESTINATION}/public/dispatch.cgi")
131   chmod 0755, "#{PKG_DESTINATION}/public/dispatch.cgi"
132
133   copy_with_rewritten_ruby_path("dispatches/dispatch.fcgi", "#{PKG_DESTINATION}/public/dispatch.fcgi")
134   chmod 0755, "#{PKG_DESTINATION}/public/dispatch.fcgi"
135
136   # copy_with_rewritten_ruby_path("dispatches/gateway.cgi", "#{PKG_DESTINATION}/public/gateway.cgi")
137   # chmod 0755, "#{PKG_DESTINATION}/public/gateway.cgi"
138 end
139
140 task :copy_html_files do
141   HTML_FILES.each { |file| cp File.join('html', file), File.join(PKG_DESTINATION, 'public', file) }
142 end
143
144 task :copy_application do
145   cp "helpers/application.rb", "#{PKG_DESTINATION}/app/controllers/application.rb"
146   cp "helpers/application_helper.rb", "#{PKG_DESTINATION}/app/helpers/application_helper.rb"
147 end
148
149 task :copy_configs do
150   cp "configs/database.yml", "#{PKG_DESTINATION}/config/database.yml"
151   cp "configs/routes.rb", "#{PKG_DESTINATION}/config/routes.rb"
152
153   cp "configs/apache.conf", "#{PKG_DESTINATION}/public/.htaccess"
154
155   cp "environments/environment.rb", "#{PKG_DESTINATION}/config/environment.rb"
156   cp "environments/production.rb", "#{PKG_DESTINATION}/config/environments/production.rb"
157   cp "environments/development.rb", "#{PKG_DESTINATION}/config/environments/development.rb"
158   cp "environments/test.rb", "#{PKG_DESTINATION}/config/environments/test.rb"
159 end
160
161 task :copy_binfiles do
162   BIN_FILES.each do |file|
163     dest_file = File.join(PKG_DESTINATION, 'script', file)
164     copy_with_rewritten_ruby_path(File.join('bin', file), dest_file)
165     chmod 0755, dest_file
166   end
167 end
168
169 task :copy_rootfiles do
170   cp "fresh_rakefile", "#{PKG_DESTINATION}/Rakefile"
171   cp "README", "#{PKG_DESTINATION}/README"
172   cp "CHANGELOG", "#{PKG_DESTINATION}/CHANGELOG"
173 end
174
175 task :copy_test_helpers do
176   cp "helpers/test_helper.rb", "#{PKG_DESTINATION}/test/test_helper.rb"
177 end
178
179 task :copy_app_doc_readme do
180   cp "doc/README_FOR_APP", "#{PKG_DESTINATION}/doc/README_FOR_APP"
181 end
182
183 task :link_apache_config do
184   chdir(File.join(PKG_DESTINATION, 'config')) {
185     ln_s "../public/.htaccess", "apache.conf"
186   }
187 end
188
189 def copy_with_rewritten_ruby_path(src_file, dest_file)
190   ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
191
192   File.open(dest_file, 'w') do |df|
193     File.open(src_file) do |sf|
194       line = sf.gets
195       if (line =~ /#!.+ruby\s*/) != nil
196         df.puts("#!#{ruby}")
197       else
198         df.puts(line)
199       end
200       df.write(sf.read)
201     end
202   end
203 end
204
205
206 # Generate documentation ------------------------------------------------------------------
207
208 desc "Generate documentation for the framework and for the empty application"
209 task :generate_documentation => [ :generate_app_doc, :generate_rails_framework_doc ]
210
211 task :generate_rails_framework_doc do
212   system %{cd #{PKG_DESTINATION}; rake apidoc}
213 end
214
215 task :generate_app_doc do
216   File.cp "doc/README_FOR_APP", "#{PKG_DESTINATION}/doc/README_FOR_APP"
217   system %{cd #{PKG_DESTINATION}; rake appdoc}
218 end
219
220
221 # Generate GEM ----------------------------------------------------------------------------
222
223 task :copy_gem_environment do
224   cp "environments/environment.rb", "#{PKG_DESTINATION}/config/environment.rb"
225   dest_file = File.join(PKG_DESTINATION, 'script', 'breakpointer')
226   copy_with_rewritten_ruby_path(File.join('bin', 'breakpointer_for_gem'), dest_file)
227   chmod 0755, dest_file
228 end
229
230
231 PKG_FILES = FileList[
232   '[a-zA-Z]*',
233   'bin/**/*',
234   'configs/**/*',
235   'doc/**/*',
236   'dispatches/**/*',
237   'environments/**/*',
238   'helpers/**/*',
239   'generators/**/*',
240   'html/**/*',
241   'lib/**/*'
242 ]
243
244 spec = Gem::Specification.new do |s|
245   s.name = 'rails'
246   s.version = PKG_VERSION
247   s.summary = "Web-application framework with template engine, control-flow layer, and ORM."
248   s.description = <<-EOF
249     Rails is a framework for building web-application using CGI, FCGI, mod_ruby, or WEBrick
250     on top of either MySQL, PostgreSQL, SQLite, DB2, SQL Server, or Oracle with eRuby- or Builder-based templates.
251   EOF
252
253   s.add_dependency('rake', '>= 0.5.3')
254   s.add_dependency('activesupport',    '= 1.1.1' + PKG_BUILD)
255   s.add_dependency('activerecord',     '= 1.11.1' + PKG_BUILD)
256   s.add_dependency('actionpack',       '= 1.9.1' + PKG_BUILD)
257   s.add_dependency('actionmailer',     '= 1.0.1' + PKG_BUILD)
258   s.add_dependency('actionwebservice', '= 0.8.1' + PKG_BUILD)
259
260   s.rdoc_options << '--exclude' << '.'
261   s.has_rdoc = false
262
263   s.files = PKG_FILES.to_a.delete_if {|f| f.include?('.svn')}
264   s.require_path = 'lib'
265
266   s.bindir = "bin"                               # Use these for applications.
267   s.executables = ["rails"]
268   s.default_executable = "rails"
269
270   s.author = "David Heinemeier Hansson"
271   s.email = "david@loudthinking.com"
272   s.homepage = "http://www.rubyonrails.org"
273   s.rubyforge_project = "rails"
274 end
275
276 Rake::GemPackageTask.new(spec) do |pkg|
277 end
278
279
280 # Publishing -------------------------------------------------------
281 desc "Publish the API documentation"
282 task :pgem => [:gem] do
283   Rake::SshFilePublisher.new("davidhh@wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
284   `ssh davidhh@wrath.rubyonrails.org './gemupdate.sh'`
285 end
286
287 desc "Publish the release files to RubyForge."
288 task :release => [:gem] do
289   files = ["gem"].map { |ext| "pkg/#{PKG_FILE_NAME}.#{ext}" }
290
291   if RUBY_FORGE_PROJECT then
292     require 'net/http'
293     require 'open-uri'
294
295     project_uri = "http://rubyforge.org/projects/#{RUBY_FORGE_PROJECT}/"
296     project_data = open(project_uri) { |data| data.read }
297     group_id = project_data[/[?&]group_id=(\d+)/, 1]
298     raise "Couldn't get group id" unless group_id
299
300     # This echos password to shell which is a bit sucky
301     if ENV["RUBY_FORGE_PASSWORD"]
302       password = ENV["RUBY_FORGE_PASSWORD"]
303     else
304       print "#{RUBY_FORGE_USER}@rubyforge.org's password: "
305       password = STDIN.gets.chomp
306     end
307
308     login_response = Net::HTTP.start("rubyforge.org", 80) do |http|
309       data = [
310         "login=1",
311         "form_loginname=#{RUBY_FORGE_USER}",
312         "form_pw=#{password}"
313       ].join("&")
314       http.post("/account/login.php", data)
315     end
316
317     cookie = login_response["set-cookie"]
318     raise "Login failed" unless cookie
319     headers = { "Cookie" => cookie }
320
321     release_uri = "http://rubyforge.org/frs/admin/?group_id=#{group_id}"
322     release_data = open(release_uri, headers) { |data| data.read }
323     package_id = release_data[/[?&]package_id=(\d+)/, 1]
324     raise "Couldn't get package id" unless package_id
325
326     first_file = true
327     release_id = ""
328
329     files.each do |filename|
330       basename  = File.basename(filename)
331       file_ext  = File.extname(filename)
332       file_data = File.open(filename, "rb") { |file| file.read }
333
334       puts "Releasing #{basename}..."
335
336       release_response = Net::HTTP.start("rubyforge.org", 80) do |http|
337         release_date = Time.now.strftime("%Y-%m-%d %H:%M")
338         type_map = {
339           ".zip"    => "3000",
340           ".tgz"    => "3110",
341           ".gz"     => "3110",
342           ".gem"    => "1400"
343         }; type_map.default = "9999"
344         type = type_map[file_ext]
345         boundary = "rubyqMY6QN9bp6e4kS21H4y0zxcvoor"
346
347         query_hash = if first_file then
348           {
349             "group_id" => group_id,
350             "package_id" => package_id,
351             "release_name" => RELEASE_NAME,
352             "release_date" => release_date,
353             "type_id" => type,
354             "processor_id" => "8000", # Any
355             "release_notes" => "",
356             "release_changes" => "",
357             "preformatted" => "1",
358             "submit" => "1"
359           }
360         else
361           {
362             "group_id" => group_id,
363             "release_id" => release_id,
364             "package_id" => package_id,
365             "step2" => "1",
366             "type_id" => type,
367             "processor_id" => "8000", # Any
368             "submit" => "Add This File"
369           }
370         end
371
372         query = "?" + query_hash.map do |(name, value)|
373           [name, URI.encode(value)].join("=")
374         end.join("&")
375
376         data = [
377           "--" + boundary,
378           "Content-Disposition: form-data; name=\"userfile\"; filename=\"#{basename}\"",
379           "Content-Type: application/octet-stream",
380           "Content-Transfer-Encoding: binary",
381           "", file_data, ""
382           ].join("\x0D\x0A")
383
384         release_headers = headers.merge(
385           "Content-Type" => "multipart/form-data; boundary=#{boundary}"
386         )
387
388         target = first_file ? "/frs/admin/qrs.php" : "/frs/admin/editrelease.php"
389         http.post(target + query, data, release_headers)
390       end
391
392       if first_file then
393         release_id = release_response.body[/release_id=(\d+)/, 1]
394         raise("Couldn't get release id") unless release_id
395       end
396
397       first_file = false
398     end
399   end
400 end
Note: See TracBrowser for help on using the browser.