2 require 'rake/testtask'
3 require 'rake/rdoctask'
4 require 'rake/gempackagetask'
5 require 'rake/contrib/rubyforgepublisher'
10 require File.join(File.dirname(__FILE__), 'lib/rails', 'version')
12 PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
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}"
18 RELEASE_NAME = "REL #{PKG_VERSION}"
20 RUBY_FORGE_PROJECT = "rails"
21 RUBY_FORGE_USER = "webster132"
24 task :default => :test
26 ## This is required until the regular test task
27 ## below passes. It's not ideal, but at least
28 ## we can see the failures
30 Dir['test/**/*_test.rb'].all? do |file|
31 system("ruby -Itest #{file}")
32 end or raise "Failures"
35 Rake::TestTask.new("regular_test") do |t|
37 t.pattern = 'test/**/*_test.rb'
67 APP_DIRS = %w( models controllers helpers views views/layouts )
68 PUBLIC_DIRS = %w( images javascripts stylesheets )
69 TEST_DIRS = %w( fixtures unit functional mocks mocks/development mocks/test )
71 LOG_FILES = %w( server.log development.log test.log production.log )
72 HTML_FILES = %w( 422.html 404.html 500.html index.html robots.txt favicon.ico images/rails.png
73 javascripts/prototype.js javascripts/application.js
74 javascripts/effects.js javascripts/dragdrop.js javascripts/controls.js )
75 BIN_FILES = %w( about console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner process/inspector runner server plugin )
77 VENDOR_LIBS = %w( actionpack activerecord actionmailer activesupport activeresource railties )
80 desc "Generates a fresh Rails package with documentation"
81 task :fresh_rails => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_vendor_libraries, :copy_ties_content, :generate_documentation ]
83 desc "Generates a fresh Rails package using GEMs with documentation"
84 task :fresh_gem_rails => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_ties_content, :copy_gem_environment ]
86 desc "Generates a fresh Rails package without documentation (faster)"
87 task :fresh_rails_without_docs => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_vendor_libraries, :copy_ties_content ]
89 desc "Generates a fresh Rails package without documentation (faster)"
90 task :fresh_rails_without_docs_using_links => [ :clean, :make_dir_structure, :initialize_file_stubs, :link_vendor_libraries, :copy_ties_content ]
92 desc "Generates minimal Rails package using symlinks"
93 task :dev => [ :clean, :make_dir_structure, :initialize_file_stubs, :link_vendor_libraries, :copy_ties_content ]
95 desc "Packages the fresh Rails package with documentation"
96 task :package => [ :clean, :fresh_rails ] do
97 system %{cd ..; tar -czvf #{PKG_NAME}-#{PKG_VERSION}.tgz #{PKG_NAME}}
98 system %{cd ..; zip -r #{PKG_NAME}-#{PKG_VERSION}.zip #{PKG_NAME}}
102 rm_rf PKG_DESTINATION
105 # Get external spinoffs -------------------------------------------------------------------
107 desc "Updates railties to the latest version of the javascript spinoffs"
109 for js in %w( prototype controls dragdrop effects )
110 rm "html/javascripts/#{js}.js"
111 cp "./../actionpack/lib/action_view/helpers/javascripts/#{js}.js", "html/javascripts"
115 # Make directory structure ----------------------------------------------------------------
117 def make_dest_dirs(dirs, path = '.')
118 mkdir_p dirs.map { |dir| File.join(PKG_DESTINATION, path.to_s, dir) }
121 desc "Make the directory structure for the new Rails application"
122 task :make_dir_structure => [ :make_base_dirs, :make_app_dirs, :make_public_dirs, :make_test_dirs ]
124 task(:make_base_dirs) { make_dest_dirs BASE_DIRS }
125 task(:make_app_dirs) { make_dest_dirs APP_DIRS, 'app' }
126 task(:make_public_dirs) { make_dest_dirs PUBLIC_DIRS, 'public' }
127 task(:make_test_dirs) { make_dest_dirs TEST_DIRS, 'test' }
130 # Initialize file stubs -------------------------------------------------------------------
132 desc "Initialize empty file stubs (such as for logging)"
133 task :initialize_file_stubs => [ :initialize_log_files ]
135 task :initialize_log_files do
136 log_dir = File.join(PKG_DESTINATION, 'log')
138 LOG_FILES.each do |log_file|
139 log_path = File.join(log_dir, log_file)
146 # Copy Vendors ----------------------------------------------------------------------------
148 desc "Copy in all the Rails packages to vendor"
149 task :copy_vendor_libraries do
150 mkdir File.join(PKG_DESTINATION, 'vendor', 'rails')
151 VENDOR_LIBS.each { |dir| cp_r File.join('..', dir), File.join(PKG_DESTINATION, 'vendor', 'rails', dir) }
152 FileUtils.rm_r(Dir.glob(File.join(PKG_DESTINATION, 'vendor', 'rails', "**", ".svn")))
155 desc "Link in all the Rails packages to vendor"
156 task :link_vendor_libraries do
157 mkdir File.join(PKG_DESTINATION, 'vendor', 'rails')
158 VENDOR_LIBS.each { |dir| ln_s File.join('..', '..', '..', dir), File.join(PKG_DESTINATION, 'vendor', 'rails', dir) }
162 # Copy Ties Content -----------------------------------------------------------------------
164 desc "Make copies of all the default content of ties"
165 task :copy_ties_content => [
166 :copy_rootfiles, :copy_dispatches, :copy_html_files, :copy_application,
167 :copy_configs, :copy_binfiles, :copy_test_helpers, :copy_app_doc_readme ]
169 task :copy_dispatches do
170 copy_with_rewritten_ruby_path("dispatches/dispatch.rb", "#{PKG_DESTINATION}/public/dispatch.rb")
171 chmod 0755, "#{PKG_DESTINATION}/public/dispatch.rb"
173 copy_with_rewritten_ruby_path("dispatches/dispatch.rb", "#{PKG_DESTINATION}/public/dispatch.cgi")
174 chmod 0755, "#{PKG_DESTINATION}/public/dispatch.cgi"
176 copy_with_rewritten_ruby_path("dispatches/dispatch.fcgi", "#{PKG_DESTINATION}/public/dispatch.fcgi")
177 chmod 0755, "#{PKG_DESTINATION}/public/dispatch.fcgi"
179 # copy_with_rewritten_ruby_path("dispatches/gateway.cgi", "#{PKG_DESTINATION}/public/gateway.cgi")
180 # chmod 0755, "#{PKG_DESTINATION}/public/gateway.cgi"
183 task :copy_html_files do
184 HTML_FILES.each { |file| cp File.join('html', file), File.join(PKG_DESTINATION, 'public', file) }
187 task :copy_application do
188 cp "helpers/application.rb", "#{PKG_DESTINATION}/app/controllers/application.rb"
189 cp "helpers/application_helper.rb", "#{PKG_DESTINATION}/app/helpers/application_helper.rb"
192 task :copy_configs do
196 File.open("#{PKG_DESTINATION}/config/database.yml", 'w') {|f| f.write ERB.new(IO.read("configs/databases/sqlite3.yml"), nil, '-').result(binding)}
198 cp "configs/routes.rb", "#{PKG_DESTINATION}/config/routes.rb"
200 cp "configs/initializers/inflections.rb", "#{PKG_DESTINATION}/config/initializers/inflections.rb"
201 cp "configs/initializers/mime_types.rb", "#{PKG_DESTINATION}/config/initializers/mime_types.rb"
203 cp "configs/locales/en.yml", "#{PKG_DESTINATION}/config/locales/en.yml"
205 cp "environments/boot.rb", "#{PKG_DESTINATION}/config/boot.rb"
206 cp "environments/environment.rb", "#{PKG_DESTINATION}/config/environment.rb"
207 cp "environments/production.rb", "#{PKG_DESTINATION}/config/environments/production.rb"
208 cp "environments/development.rb", "#{PKG_DESTINATION}/config/environments/development.rb"
209 cp "environments/test.rb", "#{PKG_DESTINATION}/config/environments/test.rb"
212 task :copy_binfiles do
213 BIN_FILES.each do |file|
214 dest_file = File.join(PKG_DESTINATION, 'script', file)
215 copy_with_rewritten_ruby_path(File.join('bin', file), dest_file)
216 chmod 0755, dest_file
220 task :copy_rootfiles do
221 cp "fresh_rakefile", "#{PKG_DESTINATION}/Rakefile"
222 cp "README", "#{PKG_DESTINATION}/README"
223 cp "CHANGELOG", "#{PKG_DESTINATION}/CHANGELOG"
226 task :copy_test_helpers do
227 cp "helpers/test_helper.rb", "#{PKG_DESTINATION}/test/test_helper.rb"
230 task :copy_app_doc_readme do
231 cp "doc/README_FOR_APP", "#{PKG_DESTINATION}/doc/README_FOR_APP"
234 def copy_with_rewritten_ruby_path(src_file, dest_file)
235 ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
237 File.open(dest_file, 'w') do |df|
238 File.open(src_file) do |sf|
240 if (line =~ /#!.+ruby\s*/) != nil
251 # Generate documentation ------------------------------------------------------------------
253 desc "Generate documentation for the framework and for the empty application"
254 task :generate_documentation => [ :generate_app_doc, :generate_rails_framework_doc ]
256 task :generate_rails_framework_doc do
257 system %{cd #{PKG_DESTINATION}; rake doc:rails}
260 task :generate_app_doc do
261 cp "doc/README_FOR_APP", "#{PKG_DESTINATION}/doc/README_FOR_APP"
262 system %{cd #{PKG_DESTINATION}; rake doc:app}
265 Rake::RDocTask.new { |rdoc|
266 rdoc.rdoc_dir = 'doc'
267 rdoc.title = "Railties -- Gluing the Engine to the Rails"
268 rdoc.options << '--line-numbers' << '--inline-source' << '--accessor' << 'cattr_accessor=object'
269 rdoc.options << '--charset' << 'utf-8'
270 rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo'
271 rdoc.rdoc_files.include('README', 'CHANGELOG')
272 rdoc.rdoc_files.include('lib/*.rb')
273 rdoc.rdoc_files.include('lib/rails/*.rb')
274 rdoc.rdoc_files.include('lib/rails_generator/*.rb')
275 rdoc.rdoc_files.include('lib/commands/**/*.rb')
278 desc "Generate guides for the framework"
280 require 'mizuho/generator'
282 source = "doc/guides/source/"
283 html = "doc/guides/html/"
284 FileUtils.rm_r(html) if File.directory?(html)
285 FileUtils.mkdir(html)
287 template = File.expand_path("doc/guides/source/templates/guides.html.erb")
289 ignore = ['..', 'icons', 'images', 'templates', 'stylesheets']
290 ignore << 'active_record_basics.txt'
292 indexless = ['index.txt', 'authors.txt']
294 # Traverse all entries in doc/guides/source/
295 Dir.entries(source).each do |entry|
296 next if ignore.include?(entry)
298 if File.directory?(File.join(source, entry))
299 # If the current entry is a directory, then we will want to compile
300 # the 'index.txt' file inside this directory.
302 input = File.join(source, 'index.txt')
303 output = File.join(html, "index.html")
305 input = File.join(source, entry, 'index.txt')
306 output = File.join(html, "#{entry}.html")
309 # If the current entry is a file, then we will want to compile this file.
310 input = File.join(source, entry)
311 output = File.join(html, entry).sub(/\.txt$/, '.html')
315 puts "GENERATING => #{output}"
316 ENV['MANUALSONRAILS_TOC'] = 'no' if indexless.include?(entry)
317 Mizuho::Generator.new(input, :output => output, :template => template).start
318 rescue Mizuho::GenerationError
319 STDERR.puts "*** ERROR"
322 ENV.delete('MANUALSONRAILS_TOC')
326 # Copy images and css files to html directory. These dirs are in .gitigore and shouldn't be source controlled.
327 FileUtils.cp_r File.join(source, 'images'), File.join(html, 'images')
328 FileUtils.cp_r File.join(source, 'stylesheets'), File.join(html, 'stylesheets')
331 # Generate GEM ----------------------------------------------------------------------------
333 task :copy_gem_environment do
334 cp "environments/environment.rb", "#{PKG_DESTINATION}/config/environment.rb"
335 chmod 0755, dest_file
339 PKG_FILES = FileList[
353 spec = Gem::Specification.new do |s|
354 s.platform = Gem::Platform::RUBY
356 s.version = PKG_VERSION
357 s.summary = "Web-application framework with template engine, control-flow layer, and ORM."
358 s.description = <<-EOF
359 Rails is a framework for building web-application using CGI, FCGI, mod_ruby, or WEBrick
360 on top of either MySQL, PostgreSQL, SQLite, DB2, SQL Server, or Oracle with eRuby- or Builder-based templates.
363 s.add_dependency('rake', '>= 0.8.3')
364 s.add_dependency('activesupport', '= 2.2.2' + PKG_BUILD)
365 s.add_dependency('activerecord', '= 2.2.2' + PKG_BUILD)
366 s.add_dependency('actionpack', '= 2.2.2' + PKG_BUILD)
367 s.add_dependency('actionmailer', '= 2.2.2' + PKG_BUILD)
368 s.add_dependency('activeresource', '= 2.2.2' + PKG_BUILD)
370 s.rdoc_options << '--exclude' << '.'
373 s.files = PKG_FILES.to_a.delete_if {|f| f.include?('.svn')}
374 s.require_path = 'lib'
375 s.bindir = "bin" # Use these for applications.
376 s.executables = ["rails"]
377 s.default_executable = "rails"
379 s.author = "David Heinemeier Hansson"
380 s.email = "david@loudthinking.com"
381 s.homepage = "http://www.rubyonrails.org"
382 s.rubyforge_project = "rails"
385 Rake::GemPackageTask.new(spec) do |pkg|
390 # Publishing -------------------------------------------------------
391 desc "Publish the rails gem"
392 task :pgem => [:gem] do
393 Rake::SshFilePublisher.new("gems.rubyonrails.org", "/u/sites/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
394 `ssh gems.rubyonrails.org '/u/sites/gems/gemupdate.sh'`
397 desc "Publish the API documentation"
398 task :pdoc => :rdoc do
399 # railties API isn't separately published
402 desc "Publish the release files to RubyForge."
403 task :release => [ :package ] do
406 packages = %w( gem ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
408 rubyforge = RubyForge.new
410 rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages)