2
require 'rake/testtask'
3
require 'rake/rdoctask'
4
require 'rake/gempackagetask'
9
require File.join(File.dirname(__FILE__), 'lib/rails', 'version')
11
PKG_BUILD = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
13
PKG_VERSION = Rails::VERSION::STRING + PKG_BUILD
14
PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
15
PKG_DESTINATION = ENV["RAILS_PKG_DESTINATION"] || "../#{PKG_NAME}"
17
RELEASE_NAME = "REL #{PKG_VERSION}"
19
RUBY_FORGE_PROJECT = "rails"
20
RUBY_FORGE_USER = "webster132"
23
task :default => :test
25
## This is required until the regular test task
26
## below passes. It's not ideal, but at least
27
## we can see the failures
29
Dir['test/**/*_test.rb'].all? do |file|
30
ruby = File.join(*RbConfig::CONFIG.values_at('bindir', 'RUBY_INSTALL_NAME'))
31
system(ruby, '-Itest', file)
32
end or raise "Failures"
35
Rake::TestTask.new("regular_test") do |t|
37
t.pattern = 'test/**/*_test.rb'
65
APP_DIRS = %w( models controllers helpers views views/layouts )
66
PUBLIC_DIRS = %w( images javascripts stylesheets )
67
TEST_DIRS = %w( fixtures unit functional mocks mocks/development mocks/test )
69
LOG_FILES = %w( server.log development.log test.log production.log )
70
HTML_FILES = %w( 422.html 404.html 500.html index.html robots.txt favicon.ico images/rails.png
71
javascripts/prototype.js javascripts/application.js
72
javascripts/effects.js javascripts/dragdrop.js javascripts/controls.js )
73
BIN_FILES = %w( about console destroy generate performance/benchmarker performance/profiler runner server plugin )
75
VENDOR_LIBS = %w( actionpack activerecord actionmailer activesupport activeresource railties )
78
desc "Generates a fresh Rails package with documentation"
79
task :fresh_rails => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_vendor_libraries, :copy_ties_content, :generate_documentation ]
81
desc "Generates a fresh Rails package using GEMs with documentation"
82
task :fresh_gem_rails => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_ties_content, :copy_gem_environment ]
84
desc "Generates a fresh Rails package without documentation (faster)"
85
task :fresh_rails_without_docs => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_vendor_libraries, :copy_ties_content ]
87
desc "Generates a fresh Rails package without documentation (faster)"
88
task :fresh_rails_without_docs_using_links => [ :clean, :make_dir_structure, :initialize_file_stubs, :link_vendor_libraries, :copy_ties_content ]
90
desc "Generates minimal Rails package using symlinks"
91
task :dev => [ :clean, :make_dir_structure, :initialize_file_stubs, :link_vendor_libraries, :copy_ties_content ]
93
desc "Packages the fresh Rails package with documentation"
94
task :package => [ :clean, :fresh_rails ] do
95
system %{cd ..; tar -czvf #{PKG_NAME}-#{PKG_VERSION}.tgz #{PKG_NAME}}
96
system %{cd ..; zip -r #{PKG_NAME}-#{PKG_VERSION}.zip #{PKG_NAME}}
100
rm_rf PKG_DESTINATION
103
# Get external spinoffs -------------------------------------------------------------------
105
desc "Updates railties to the latest version of the javascript spinoffs"
107
for js in %w( prototype controls dragdrop effects )
108
rm "html/javascripts/#{js}.js"
109
cp "./../actionpack/lib/action_view/helpers/javascripts/#{js}.js", "html/javascripts"
113
# Make directory structure ----------------------------------------------------------------
115
def make_dest_dirs(dirs, path = '.')
116
mkdir_p dirs.map { |dir| File.join(PKG_DESTINATION, path.to_s, dir) }
119
desc "Make the directory structure for the new Rails application"
120
task :make_dir_structure => [ :make_base_dirs, :make_app_dirs, :make_public_dirs, :make_test_dirs ]
122
task(:make_base_dirs) { make_dest_dirs BASE_DIRS }
123
task(:make_app_dirs) { make_dest_dirs APP_DIRS, 'app' }
124
task(:make_public_dirs) { make_dest_dirs PUBLIC_DIRS, 'public' }
125
task(:make_test_dirs) { make_dest_dirs TEST_DIRS, 'test' }
128
# Initialize file stubs -------------------------------------------------------------------
130
desc "Initialize empty file stubs (such as for logging)"
131
task :initialize_file_stubs => [ :initialize_log_files ]
133
task :initialize_log_files do
134
log_dir = File.join(PKG_DESTINATION, 'log')
136
LOG_FILES.each do |log_file|
137
log_path = File.join(log_dir, log_file)
144
# Copy Vendors ----------------------------------------------------------------------------
146
desc "Copy in all the Rails packages to vendor"
147
task :copy_vendor_libraries do
148
mkdir File.join(PKG_DESTINATION, 'vendor', 'rails')
149
VENDOR_LIBS.each { |dir| cp_r File.join('..', dir), File.join(PKG_DESTINATION, 'vendor', 'rails', dir) }
150
FileUtils.rm_r(Dir.glob(File.join(PKG_DESTINATION, 'vendor', 'rails', "**", ".svn")))
153
desc "Link in all the Rails packages to vendor"
154
task :link_vendor_libraries do
155
mkdir File.join(PKG_DESTINATION, 'vendor', 'rails')
156
VENDOR_LIBS.each { |dir| ln_s File.join('..', '..', '..', dir), File.join(PKG_DESTINATION, 'vendor', 'rails', dir) }
160
# Copy Ties Content -----------------------------------------------------------------------
162
desc "Make copies of all the default content of ties"
163
task :copy_ties_content => [
164
:copy_rootfiles, :copy_dispatches, :copy_html_files, :copy_application,
165
:copy_configs, :copy_binfiles, :copy_test_helpers, :copy_app_doc_readme ]
167
task :copy_dispatches do
168
copy_with_rewritten_ruby_path("dispatches/dispatch.rb", "#{PKG_DESTINATION}/public/dispatch.rb")
169
chmod 0755, "#{PKG_DESTINATION}/public/dispatch.rb"
171
copy_with_rewritten_ruby_path("dispatches/dispatch.rb", "#{PKG_DESTINATION}/public/dispatch.cgi")
172
chmod 0755, "#{PKG_DESTINATION}/public/dispatch.cgi"
174
copy_with_rewritten_ruby_path("dispatches/dispatch.fcgi", "#{PKG_DESTINATION}/public/dispatch.fcgi")
175
chmod 0755, "#{PKG_DESTINATION}/public/dispatch.fcgi"
178
task :copy_html_files do
179
HTML_FILES.each { |file| cp File.join('html', file), File.join(PKG_DESTINATION, 'public', file) }
182
task :copy_application do
183
cp "helpers/application_controller.rb", "#{PKG_DESTINATION}/app/controllers/application_controller.rb"
184
cp "helpers/application_helper.rb", "#{PKG_DESTINATION}/app/helpers/application_helper.rb"
187
task :copy_configs do
191
File.open("#{PKG_DESTINATION}/config/database.yml", 'w') {|f| f.write ERB.new(IO.read("configs/databases/sqlite3.yml"), nil, '-').result(binding)}
193
cp "configs/routes.rb", "#{PKG_DESTINATION}/config/routes.rb"
195
cp "configs/initializers/backtrace_silencers.rb", "#{PKG_DESTINATION}/config/initializers/backtrace_silencers.rb"
196
cp "configs/initializers/inflections.rb", "#{PKG_DESTINATION}/config/initializers/inflections.rb"
197
cp "configs/initializers/mime_types.rb", "#{PKG_DESTINATION}/config/initializers/mime_types.rb"
198
cp "configs/initializers/new_rails_defaults.rb", "#{PKG_DESTINATION}/config/initializers/new_rails_defaults.rb"
200
cp "configs/locales/en.yml", "#{PKG_DESTINATION}/config/locales/en.yml"
202
cp "configs/seeds.rb", "#{PKG_DESTINATION}/db/seeds.rb"
204
cp "environments/boot.rb", "#{PKG_DESTINATION}/config/boot.rb"
205
File.open("#{PKG_DESTINATION}/config/environment.rb", 'w') {|f| f.write ERB.new(IO.read("environments/environment.rb"), nil, '-').result(binding)}
206
cp "environments/production.rb", "#{PKG_DESTINATION}/config/environments/production.rb"
207
cp "environments/development.rb", "#{PKG_DESTINATION}/config/environments/development.rb"
208
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
250
desc 'Generate guides (for authors), use ONLY=foo to process just "foo.textile"'
251
task :generate_guides do
252
ruby "guides/rails_guides.rb"
256
# Generate documentation ------------------------------------------------------------------
258
desc "Generate documentation for the framework and for the empty application"
259
task :generate_documentation => [ :generate_app_doc, :generate_rails_framework_doc ]
261
task :generate_rails_framework_doc do
262
system %{cd #{PKG_DESTINATION}; rake doc:rails}
265
task :generate_app_doc do
266
cp "doc/README_FOR_APP", "#{PKG_DESTINATION}/doc/README_FOR_APP"
267
system %{cd #{PKG_DESTINATION}; rake doc:app}
270
Rake::RDocTask.new { |rdoc|
271
rdoc.rdoc_dir = 'doc'
272
rdoc.title = "Railties -- Gluing the Engine to the Rails"
273
rdoc.options << '--line-numbers' << '--inline-source' << '--accessor' << 'cattr_accessor=object'
274
rdoc.options << '--charset' << 'utf-8'
275
rdoc.template = ENV['template'] ? "#{ENV['template']}.rb" : '../doc/template/horo'
276
rdoc.rdoc_files.include('README', 'CHANGELOG')
277
rdoc.rdoc_files.include('lib/*.rb')
278
rdoc.rdoc_files.include('lib/rails/*.rb')
279
rdoc.rdoc_files.include('lib/rails_generator/*.rb')
280
rdoc.rdoc_files.include('lib/commands/**/*.rb')
283
# Generate GEM ----------------------------------------------------------------------------
285
task :copy_gem_environment do
286
cp "environments/environment.rb", "#{PKG_DESTINATION}/config/environment.rb"
287
chmod 0755, dest_file
291
PKG_FILES = FileList[
306
spec = Gem::Specification.new do |s|
307
s.platform = Gem::Platform::RUBY
309
s.version = PKG_VERSION
310
s.summary = "Web-application framework with template engine, control-flow layer, and ORM."
311
s.description = <<-EOF
312
Rails is a framework for building web-application using CGI, FCGI, mod_ruby, or WEBrick
313
on top of either MySQL, PostgreSQL, SQLite, DB2, SQL Server, or Oracle with eRuby- or Builder-based templates.
316
s.add_dependency('rake', '>= 0.8.3')
317
s.add_dependency('activesupport', '= 2.3.5' + PKG_BUILD)
318
s.add_dependency('activerecord', '= 2.3.5' + PKG_BUILD)
319
s.add_dependency('actionpack', '= 2.3.5' + PKG_BUILD)
320
s.add_dependency('actionmailer', '= 2.3.5' + PKG_BUILD)
321
s.add_dependency('activeresource', '= 2.3.5' + PKG_BUILD)
323
s.rdoc_options << '--exclude' << '.'
326
s.files = PKG_FILES.to_a.delete_if {|f| f =~ %r{\.svn|guides/output}}
327
s.require_path = 'lib'
328
s.bindir = "bin" # Use these for applications.
329
s.executables = ["rails"]
330
s.default_executable = "rails"
332
s.author = "David Heinemeier Hansson"
333
s.email = "david@loudthinking.com"
334
s.homepage = "http://www.rubyonrails.org"
335
s.rubyforge_project = "rails"
338
Rake::GemPackageTask.new(spec) do |pkg|
343
# Publishing -------------------------------------------------------
344
desc "Publish the rails gem"
345
task :pgem => [:gem] do
346
Rake::SshFilePublisher.new("gems.rubyonrails.org", "/u/sites/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
347
`ssh gems.rubyonrails.org '/u/sites/gems/gemupdate.sh'`
350
desc "Publish the guides"
351
task :pguides => :generate_guides do
353
`tar -czf pkg/guides.gz guides/output`
354
Rake::SshFilePublisher.new("web.rubyonrails.org", "/u/sites/guides.rubyonrails.org/public", "pkg", "guides.gz").upload
355
`ssh web.rubyonrails.org 'cd /u/sites/guides.rubyonrails.org/public/ && tar -xvzf guides.gz && mv guides/output/* . && rm -rf guides*'`
358
desc "Publish the release files to RubyForge."
359
task :release => [ :package ] do
360
require 'rake/contrib/rubyforgepublisher'
363
packages = %w( gem ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
365
rubyforge = RubyForge.new
367
rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages)