Rakefile 11.9 KB
Newer Older
D
Initial  
David Heinemeier Hansson 已提交
1 2 3 4 5 6 7
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'rake/contrib/rubyforgepublisher'

require 'date'
8
require 'rbconfig'
D
Initial  
David Heinemeier Hansson 已提交
9

10
require File.join(File.dirname(__FILE__), 'lib/rails', 'version')
11

D
Initial  
David Heinemeier Hansson 已提交
12 13
PKG_BUILD       = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
PKG_NAME        = 'rails'
14
PKG_VERSION     = Rails::VERSION::STRING + PKG_BUILD
D
Initial  
David Heinemeier Hansson 已提交
15 16 17
PKG_FILE_NAME   = "#{PKG_NAME}-#{PKG_VERSION}"
PKG_DESTINATION = ENV["RAILS_PKG_DESTINATION"] || "../#{PKG_NAME}"

18 19 20 21 22
RELEASE_NAME  = "REL #{PKG_VERSION}"

RUBY_FORGE_PROJECT = "rails"
RUBY_FORGE_USER    = "webster132"

D
David Heinemeier Hansson 已提交
23

24 25 26 27 28 29 30 31 32 33
## This is required until the regular test task
## below passes.  It's not ideal, but at least
## we can see the failures
task :test do 
  Dir['test/**/*_test.rb'].all? do |file|
    system("ruby #{file}")
  end or raise "Failures"
end

Rake::TestTask.new("regular_test") do |t|
34 35 36 37 38
  t.libs << 'test'
  t.pattern = 'test/**/*_test.rb'
  t.warning = true
  t.verbose = true
end
39 40


41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
BASE_DIRS = %w( 
  app
  config/environments
  config/initializers
  components
  db
  doc
  log
  lib
  lib/tasks
  public
  script
  script/performance
  script/process
  test
  vendor
  vendor/plugins
  tmp/sessions
  tmp/cache
  tmp/sockets
  tmp/pids
62 63
)

64
APP_DIRS    = %w( models controllers helpers views views/layouts )
65
PUBLIC_DIRS = %w( images javascripts stylesheets )
66
TEST_DIRS   = %w( fixtures unit functional mocks mocks/development mocks/test )
D
David Heinemeier Hansson 已提交
67

68
LOG_FILES    = %w( server.log development.log test.log production.log )
69
HTML_FILES   = %w( 404.html 500.html index.html robots.txt favicon.ico images/rails.png
70
                   javascripts/prototype.js javascripts/application.js
71
                   javascripts/effects.js javascripts/dragdrop.js javascripts/controls.js )
72
BIN_FILES    = %w( about breakpointer console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner process/inspector runner server plugin )
D
David Heinemeier Hansson 已提交
73

74
VENDOR_LIBS = %w( actionpack activerecord actionmailer activesupport actionwebservice railties )
D
David Heinemeier Hansson 已提交
75 76


D
Initial  
David Heinemeier Hansson 已提交
77
desc "Generates a fresh Rails package with documentation"
D
David Heinemeier Hansson 已提交
78
task :fresh_rails => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_vendor_libraries, :copy_ties_content, :generate_documentation ]
D
Initial  
David Heinemeier Hansson 已提交
79 80

desc "Generates a fresh Rails package using GEMs with documentation"
D
David Heinemeier Hansson 已提交
81
task :fresh_gem_rails => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_ties_content, :copy_gem_environment ]
D
Initial  
David Heinemeier Hansson 已提交
82 83

desc "Generates a fresh Rails package without documentation (faster)"
D
David Heinemeier Hansson 已提交
84
task :fresh_rails_without_docs => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_vendor_libraries, :copy_ties_content ]
D
Initial  
David Heinemeier Hansson 已提交
85

86 87 88
desc "Generates a fresh Rails package without documentation (faster)"
task :fresh_rails_without_docs_using_links => [ :clean, :make_dir_structure, :initialize_file_stubs, :link_vendor_libraries, :copy_ties_content ]

89 90 91
desc "Generates minimal Rails package using symlinks"
task :dev => [ :clean, :make_dir_structure, :initialize_file_stubs, :link_vendor_libraries, :copy_ties_content ]

D
Initial  
David Heinemeier Hansson 已提交
92 93 94 95 96 97 98
desc "Packages the fresh Rails package with documentation"
task :package => [ :clean, :fresh_rails ] do
  system %{cd ..; tar -czvf #{PKG_NAME}-#{PKG_VERSION}.tgz #{PKG_NAME}}
  system %{cd ..; zip -r #{PKG_NAME}-#{PKG_VERSION}.zip #{PKG_NAME}}
end

task :clean do
D
David Heinemeier Hansson 已提交
99
  rm_rf PKG_DESTINATION
D
Initial  
David Heinemeier Hansson 已提交
100 101
end

102 103 104
# Get external spinoffs -------------------------------------------------------------------

desc "Updates railties to the latest version of the javascript spinoffs"
D
David Heinemeier Hansson 已提交
105
task :update_js do
106
  for js in %w( prototype controls dragdrop effects )
D
David Heinemeier Hansson 已提交
107 108 109 110
    rm "html/javascripts/#{js}.js"
    cp "./../actionpack/lib/action_view/helpers/javascripts/#{js}.js", "html/javascripts"
  end
end
D
Initial  
David Heinemeier Hansson 已提交
111 112 113

# Make directory structure ----------------------------------------------------------------

114
def make_dest_dirs(dirs, path = '.')
115
  mkdir_p dirs.map { |dir| File.join(PKG_DESTINATION, path.to_s, dir) }
D
Initial  
David Heinemeier Hansson 已提交
116 117
end

D
David Heinemeier Hansson 已提交
118 119
desc "Make the directory structure for the new Rails application"
task :make_dir_structure => [ :make_base_dirs, :make_app_dirs, :make_public_dirs, :make_test_dirs ]
D
Initial  
David Heinemeier Hansson 已提交
120

D
David Heinemeier Hansson 已提交
121 122 123 124
task(:make_base_dirs)   { make_dest_dirs BASE_DIRS              }
task(:make_app_dirs)    { make_dest_dirs APP_DIRS,    'app'     }
task(:make_public_dirs) { make_dest_dirs PUBLIC_DIRS, 'public'  }
task(:make_test_dirs)   { make_dest_dirs TEST_DIRS,   'test'    }
D
Initial  
David Heinemeier Hansson 已提交
125 126 127 128 129


# Initialize file stubs -------------------------------------------------------------------

desc "Initialize empty file stubs (such as for logging)"
D
David Heinemeier Hansson 已提交
130
task :initialize_file_stubs => [ :initialize_log_files ]
D
Initial  
David Heinemeier Hansson 已提交
131 132

task :initialize_log_files do
D
David Heinemeier Hansson 已提交
133 134 135 136 137
  log_dir = File.join(PKG_DESTINATION, 'log')
  chmod 0777, log_dir
  LOG_FILES.each do |log_file|
    log_path = File.join(log_dir, log_file)
    touch log_path
138
    chmod 0666, log_path
D
David Heinemeier Hansson 已提交
139
  end
D
Initial  
David Heinemeier Hansson 已提交
140 141 142 143 144 145
end


# Copy Vendors ----------------------------------------------------------------------------

desc "Copy in all the Rails packages to vendor"
D
David Heinemeier Hansson 已提交
146
task :copy_vendor_libraries do
147
  mkdir File.join(PKG_DESTINATION, 'vendor', 'rails')
148
  VENDOR_LIBS.each { |dir| cp_r File.join('..', dir), File.join(PKG_DESTINATION, 'vendor', 'rails', dir) }
149
  FileUtils.rm_r(Dir.glob(File.join(PKG_DESTINATION, 'vendor', 'rails', "**", ".svn")))
D
Initial  
David Heinemeier Hansson 已提交
150 151
end

152 153
desc "Link in all the Rails packages to vendor"
task :link_vendor_libraries do
154 155
  mkdir File.join(PKG_DESTINATION, 'vendor', 'rails')
  VENDOR_LIBS.each { |dir| ln_s File.join('..', '..', '..', dir), File.join(PKG_DESTINATION, 'vendor', 'rails', dir) }
156 157
end

D
Initial  
David Heinemeier Hansson 已提交
158 159 160 161 162 163

# Copy Ties Content -----------------------------------------------------------------------

# :link_apache_config
desc "Make copies of all the default content of ties"
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 ]
D
Initial  
David Heinemeier Hansson 已提交
166 167

task :copy_dispatches do
168
  copy_with_rewritten_ruby_path("dispatches/dispatch.rb", "#{PKG_DESTINATION}/public/dispatch.rb")
D
Initial  
David Heinemeier Hansson 已提交
169 170
  chmod 0755, "#{PKG_DESTINATION}/public/dispatch.rb"

171
  copy_with_rewritten_ruby_path("dispatches/dispatch.rb", "#{PKG_DESTINATION}/public/dispatch.cgi")
D
Initial  
David Heinemeier Hansson 已提交
172 173
  chmod 0755, "#{PKG_DESTINATION}/public/dispatch.cgi"

174
  copy_with_rewritten_ruby_path("dispatches/dispatch.fcgi", "#{PKG_DESTINATION}/public/dispatch.fcgi")
D
Initial  
David Heinemeier Hansson 已提交
175
  chmod 0755, "#{PKG_DESTINATION}/public/dispatch.fcgi"
176

177 178
  # copy_with_rewritten_ruby_path("dispatches/gateway.cgi", "#{PKG_DESTINATION}/public/gateway.cgi")
  # chmod 0755, "#{PKG_DESTINATION}/public/gateway.cgi"
D
Initial  
David Heinemeier Hansson 已提交
179 180 181
end

task :copy_html_files do
182
  HTML_FILES.each { |file| cp File.join('html', file), File.join(PKG_DESTINATION, 'public', file) }
D
Initial  
David Heinemeier Hansson 已提交
183 184
end

185 186
task :copy_application do
  cp "helpers/application.rb", "#{PKG_DESTINATION}/app/controllers/application.rb"
D
David Heinemeier Hansson 已提交
187
  cp "helpers/application_helper.rb", "#{PKG_DESTINATION}/app/helpers/application_helper.rb"
D
Initial  
David Heinemeier Hansson 已提交
188 189 190
end

task :copy_configs do
191 192 193
  app_name = "rails"
  socket = nil
  require 'erb'
194
  File.open("#{PKG_DESTINATION}/config/database.yml", 'w') {|f| f.write ERB.new(IO.read("configs/databases/mysql.yml"), nil, '-').result(binding)}
195
  
196
  cp "configs/routes.rb", "#{PKG_DESTINATION}/config/routes.rb"
D
Initial  
David Heinemeier Hansson 已提交
197

D
David Heinemeier Hansson 已提交
198
  cp "configs/apache.conf", "#{PKG_DESTINATION}/public/.htaccess"
D
Initial  
David Heinemeier Hansson 已提交
199

200 201 202 203
  cp "configs/initializers/inflections.rb", "#{PKG_DESTINATION}/configs/initializers/inflections.rb"
  cp "configs/initializers/mime_types.rb",  "#{PKG_DESTINATION}/configs/initializers/mime_types.rb"

  cp "environments/boot.rb",        "#{PKG_DESTINATION}/config/boot.rb"
204
  cp "environments/environment.rb", "#{PKG_DESTINATION}/config/environment.rb"
205
  cp "environments/production.rb",  "#{PKG_DESTINATION}/config/environments/production.rb"
D
David Heinemeier Hansson 已提交
206
  cp "environments/development.rb", "#{PKG_DESTINATION}/config/environments/development.rb"
207
  cp "environments/test.rb",        "#{PKG_DESTINATION}/config/environments/test.rb"
D
Initial  
David Heinemeier Hansson 已提交
208 209
end

210 211 212
task :copy_binfiles do
  BIN_FILES.each do |file|
    dest_file = File.join(PKG_DESTINATION, 'script', file)
213
    copy_with_rewritten_ruby_path(File.join('bin', file), dest_file)
214 215 216 217
    chmod 0755, dest_file
  end
end

D
Initial  
David Heinemeier Hansson 已提交
218
task :copy_rootfiles do
D
David Heinemeier Hansson 已提交
219 220
  cp "fresh_rakefile", "#{PKG_DESTINATION}/Rakefile"
  cp "README", "#{PKG_DESTINATION}/README"
D
 
David Heinemeier Hansson 已提交
221
  cp "CHANGELOG", "#{PKG_DESTINATION}/CHANGELOG"
D
Initial  
David Heinemeier Hansson 已提交
222 223 224
end

task :copy_test_helpers do
D
David Heinemeier Hansson 已提交
225
  cp "helpers/test_helper.rb", "#{PKG_DESTINATION}/test/test_helper.rb"
D
Initial  
David Heinemeier Hansson 已提交
226 227 228
end

task :copy_app_doc_readme do
D
David Heinemeier Hansson 已提交
229
  cp "doc/README_FOR_APP", "#{PKG_DESTINATION}/doc/README_FOR_APP"
D
Initial  
David Heinemeier Hansson 已提交
230 231 232
end

task :link_apache_config do
D
David Heinemeier Hansson 已提交
233 234 235
  chdir(File.join(PKG_DESTINATION, 'config')) {
    ln_s "../public/.htaccess", "apache.conf"
  }
D
Initial  
David Heinemeier Hansson 已提交
236 237
end

238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253
def copy_with_rewritten_ruby_path(src_file, dest_file)
  ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])

  File.open(dest_file, 'w') do |df|
    File.open(src_file) do |sf|
      line = sf.gets
      if (line =~ /#!.+ruby\s*/) != nil
        df.puts("#!#{ruby}")
      else
        df.puts(line)
      end
      df.write(sf.read)
    end
  end
end

D
Initial  
David Heinemeier Hansson 已提交
254 255 256 257

# Generate documentation ------------------------------------------------------------------

desc "Generate documentation for the framework and for the empty application"
D
David Heinemeier Hansson 已提交
258
task :generate_documentation => [ :generate_app_doc, :generate_rails_framework_doc ]
D
Initial  
David Heinemeier Hansson 已提交
259 260 261 262 263 264 265 266 267 268

task :generate_rails_framework_doc do
  system %{cd #{PKG_DESTINATION}; rake apidoc}
end

task :generate_app_doc do
  File.cp "doc/README_FOR_APP", "#{PKG_DESTINATION}/doc/README_FOR_APP"
  system %{cd #{PKG_DESTINATION}; rake appdoc}
end

269 270 271
Rake::RDocTask.new { |rdoc|
  rdoc.rdoc_dir = 'doc'
  rdoc.title    = "Railties -- Gluing the Engine to the Rails"
272
  rdoc.options << '--line-numbers' << '--inline-source' << '--accessor' << 'cattr_accessor=object'
273 274 275 276 277 278
  rdoc.template = "#{ENV['template']}.rb" if ENV['template']
  rdoc.rdoc_files.include('README', 'CHANGELOG')
  rdoc.rdoc_files.include('lib/*.rb')
  rdoc.rdoc_files.include('lib/rails_generator/*.rb')
  rdoc.rdoc_files.include('lib/commands/**/*.rb')
}
D
Initial  
David Heinemeier Hansson 已提交
279 280 281 282

# Generate GEM ----------------------------------------------------------------------------

task :copy_gem_environment do
283
  cp "environments/environment.rb", "#{PKG_DESTINATION}/config/environment.rb"
284
  chmod 0755, dest_file
D
Initial  
David Heinemeier Hansson 已提交
285 286 287 288 289 290
end


PKG_FILES = FileList[
  '[a-zA-Z]*',
  'bin/**/*', 
291
  'builtin/**/*',
D
Initial  
David Heinemeier Hansson 已提交
292 293 294 295 296
  'configs/**/*', 
  'doc/**/*', 
  'dispatches/**/*', 
  'environments/**/*', 
  'helpers/**/*', 
297
  'generators/**/*', 
D
Initial  
David Heinemeier Hansson 已提交
298 299
  'html/**/*', 
  'lib/**/*'
300
] - [ 'test' ]
D
Initial  
David Heinemeier Hansson 已提交
301 302 303 304 305 306 307

spec = Gem::Specification.new do |s|
  s.name = 'rails'
  s.version = PKG_VERSION
  s.summary = "Web-application framework with template engine, control-flow layer, and ORM."
  s.description = <<-EOF
    Rails is a framework for building web-application using CGI, FCGI, mod_ruby, or WEBrick
308
    on top of either MySQL, PostgreSQL, SQLite, DB2, SQL Server, or Oracle with eRuby- or Builder-based templates.
D
Initial  
David Heinemeier Hansson 已提交
309 310
  EOF

311 312
  s.add_dependency('rake', '>= 0.7.1')
  s.add_dependency('activesupport',    '= 1.3.1' + PKG_BUILD)
313 314 315
  s.add_dependency('activerecord',     '= 1.14.4' + PKG_BUILD)
  s.add_dependency('actionpack',       '= 1.12.5' + PKG_BUILD)
  s.add_dependency('actionmailer',     '= 1.2.5' + PKG_BUILD)
D
David Heinemeier Hansson 已提交
316
  s.add_dependency('actionwebservice', '= 1.1.6' + PKG_BUILD)
D
Initial  
David Heinemeier Hansson 已提交
317

318
  s.rdoc_options << '--exclude' << '.'
D
David Heinemeier Hansson 已提交
319 320
  s.has_rdoc = false

321
  s.files = PKG_FILES.to_a.delete_if {|f| f.include?('.svn')}
D
Initial  
David Heinemeier Hansson 已提交
322 323 324 325 326 327 328 329 330 331 332 333 334
  s.require_path = 'lib'

  s.bindir = "bin"                               # Use these for applications.
  s.executables = ["rails"]
  s.default_executable = "rails"

  s.author = "David Heinemeier Hansson"
  s.email = "david@loudthinking.com"
  s.homepage = "http://www.rubyonrails.org"
  s.rubyforge_project = "rails"
end

Rake::GemPackageTask.new(spec) do |pkg|
335
  pkg.gem_spec = spec
D
Initial  
David Heinemeier Hansson 已提交
336 337
end

338 339

# Publishing -------------------------------------------------------
D
Initial  
David Heinemeier Hansson 已提交
340 341
desc "Publish the API documentation"
task :pgem => [:gem] do 
D
David Heinemeier Hansson 已提交
342 343
  Rake::SshFilePublisher.new("davidhh@wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
  `ssh davidhh@wrath.rubyonrails.org './gemupdate.sh'`
344 345 346
end

desc "Publish the release files to RubyForge."
347 348 349 350 351
task :release => [ :gem ] do
  `rubyforge login`
  release_command = "rubyforge add_release #{PKG_NAME} #{PKG_NAME} 'REL #{PKG_VERSION}' pkg/#{PKG_NAME}-#{PKG_VERSION}.gem"
  puts release_command
  system(release_command)
352
end