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

root/tags/rel_0-14-4/railties/Rakefile

Revision 3250, 14.4 kB (checked in by david, 3 years ago)

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