Rakefile 9.2 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 11

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

D
David Heinemeier Hansson 已提交
16

17
BASE_DIRS   = %w( app config/environments components db doc log lib public script test vendor )
18
APP_DIRS    = %w( apis models controllers helpers views views/layouts )
D
David Heinemeier Hansson 已提交
19 20 21 22 23
PUBLIC_DIRS = %w( images javascripts stylesheets _doc )
TEST_DIRS   = %w( fixtures unit functional mocks mocks/development mocks/testing )

LOG_FILES    = %w( apache.log development.log test.log production.log )
HTML_FILES   = %w( 404.html 500.html index.html )
24
BIN_FILES    = %w( generate destroy breakpointer console server update )
D
David Heinemeier Hansson 已提交
25

26
VENDOR_LIBS = %w( actionpack activerecord actionmailer activesupport actionwebservice railties )
D
David Heinemeier Hansson 已提交
27 28


D
Initial  
David Heinemeier Hansson 已提交
29 30 31 32
desc "Default Task"
task :default => [ :fresh_rails ]

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

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

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

41 42 43
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 ]

44 45 46
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 已提交
47 48 49 50 51 52 53
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 已提交
54
  rm_rf PKG_DESTINATION
D
Initial  
David Heinemeier Hansson 已提交
55 56 57 58 59
end


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

D
David Heinemeier Hansson 已提交
60 61
def make_dest_dirs(dirs, path = nil)
  mkdir_p dirs.map { |dir| File.join(PKG_DESTINATION, path, dir) }
D
Initial  
David Heinemeier Hansson 已提交
62 63
end

D
David Heinemeier Hansson 已提交
64 65
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 已提交
66

D
David Heinemeier Hansson 已提交
67 68 69 70
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 已提交
71 72 73 74 75


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

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

task :initialize_log_files do
D
David Heinemeier Hansson 已提交
79 80 81 82 83
  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
84
    chmod 0666, log_path
D
David Heinemeier Hansson 已提交
85
  end
D
Initial  
David Heinemeier Hansson 已提交
86 87 88 89 90 91
end


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

desc "Copy in all the Rails packages to vendor"
D
David Heinemeier Hansson 已提交
92 93 94
task :copy_vendor_libraries do
  cp_r VENDOR_LIBS.map { |dir| File.join('..', dir) },
       File.join(PKG_DESTINATION, 'vendor')
D
Initial  
David Heinemeier Hansson 已提交
95 96
end

97 98 99 100 101 102 103 104
desc "Link in all the Rails packages to vendor"
task :link_vendor_libraries do
  return_dir = File.dirname(File.expand_path(__FILE__))
  cd File.join(PKG_DESTINATION, 'vendor')
  VENDOR_LIBS.each { |dir| ln_s File.dirname(__FILE__) + "/../../#{dir}", "." }
  cd return_dir
end

D
Initial  
David Heinemeier Hansson 已提交
105 106 107 108 109 110

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

# :link_apache_config
desc "Make copies of all the default content of ties"
task :copy_ties_content => [ 
111
  :copy_rootfiles, :copy_dispatches, :copy_html_files, :copy_application,
112
  :copy_configs, :copy_binfiles, :copy_test_helpers, :copy_docs_in_public,
D
David Heinemeier Hansson 已提交
113
  :copy_app_doc_readme ]
D
Initial  
David Heinemeier Hansson 已提交
114 115

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

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

122
  copy_with_rewritten_ruby_path("dispatches/dispatch.fcgi", "#{PKG_DESTINATION}/public/dispatch.fcgi")
D
Initial  
David Heinemeier Hansson 已提交
123 124 125 126
  chmod 0755, "#{PKG_DESTINATION}/public/dispatch.fcgi"
end

task :copy_html_files do
D
David Heinemeier Hansson 已提交
127 128
  cp HTML_FILES.map { |dir| File.join('html', dir) },
     File.join(PKG_DESTINATION, 'public')
D
Initial  
David Heinemeier Hansson 已提交
129 130
end

131 132
task :copy_application do
  cp "helpers/application.rb", "#{PKG_DESTINATION}/app/controllers/application.rb"
D
David Heinemeier Hansson 已提交
133
  cp "helpers/application_helper.rb", "#{PKG_DESTINATION}/app/helpers/application_helper.rb"
D
Initial  
David Heinemeier Hansson 已提交
134 135 136
end

task :copy_configs do
D
David Heinemeier Hansson 已提交
137
  cp "configs/database.yml", "#{PKG_DESTINATION}/config/database.yml"
138
  cp "configs/routes.rb", "#{PKG_DESTINATION}/config/routes.rb"
D
Initial  
David Heinemeier Hansson 已提交
139

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

D
David Heinemeier Hansson 已提交
142 143 144 145
  cp "environments/shared.rb", "#{PKG_DESTINATION}/config/environment.rb"
  cp "environments/production.rb", "#{PKG_DESTINATION}/config/environments/production.rb"
  cp "environments/development.rb", "#{PKG_DESTINATION}/config/environments/development.rb"
  cp "environments/test.rb", "#{PKG_DESTINATION}/config/environments/test.rb"
D
Initial  
David Heinemeier Hansson 已提交
146 147
end

148 149 150
task :copy_binfiles do
  BIN_FILES.each do |file|
    dest_file = File.join(PKG_DESTINATION, 'script', file)
151
    copy_with_rewritten_ruby_path(File.join('bin', file), dest_file)
152 153 154 155
    chmod 0755, dest_file
  end
end

D
Initial  
David Heinemeier Hansson 已提交
156
task :copy_rootfiles do
D
David Heinemeier Hansson 已提交
157 158
  cp "fresh_rakefile", "#{PKG_DESTINATION}/Rakefile"
  cp "README", "#{PKG_DESTINATION}/README"
D
 
David Heinemeier Hansson 已提交
159
  cp "CHANGELOG", "#{PKG_DESTINATION}/CHANGELOG"
D
Initial  
David Heinemeier Hansson 已提交
160 161 162
end

task :copy_test_helpers do
D
David Heinemeier Hansson 已提交
163
  cp "helpers/test_helper.rb", "#{PKG_DESTINATION}/test/test_helper.rb"
D
Initial  
David Heinemeier Hansson 已提交
164 165 166
end

task :copy_docs_in_public do
D
David Heinemeier Hansson 已提交
167
  cp "doc/index.html", "#{PKG_DESTINATION}/public/_doc/index.html"
D
Initial  
David Heinemeier Hansson 已提交
168 169 170
end

task :copy_app_doc_readme do
D
David Heinemeier Hansson 已提交
171
  cp "doc/README_FOR_APP", "#{PKG_DESTINATION}/doc/README_FOR_APP"
D
Initial  
David Heinemeier Hansson 已提交
172 173 174
end

task :link_apache_config do
D
David Heinemeier Hansson 已提交
175 176 177
  chdir(File.join(PKG_DESTINATION, 'config')) {
    ln_s "../public/.htaccess", "apache.conf"
  }
D
Initial  
David Heinemeier Hansson 已提交
178 179
end

180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
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 已提交
196 197 198 199

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

desc "Generate documentation for the framework and for the empty application"
D
David Heinemeier Hansson 已提交
200
task :generate_documentation => [ :generate_app_doc, :generate_rails_framework_doc ]
D
Initial  
David Heinemeier Hansson 已提交
201 202 203 204 205 206 207 208 209 210 211 212 213 214

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


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

task :copy_gem_environment do
D
David Heinemeier Hansson 已提交
215
  cp "environments/shared_for_gem.rb", "#{PKG_DESTINATION}/config/environment.rb"
216 217 218
  dest_file = File.join(PKG_DESTINATION, 'script', 'breakpointer')
  copy_with_rewritten_ruby_path(File.join('bin', 'breakpointer_for_gem'), dest_file)
  chmod 0755, dest_file
D
Initial  
David Heinemeier Hansson 已提交
219 220 221 222 223 224 225 226 227 228 229
end


PKG_FILES = FileList[
  '[a-zA-Z]*',
  'bin/**/*', 
  'configs/**/*', 
  'doc/**/*', 
  'dispatches/**/*', 
  'environments/**/*', 
  'helpers/**/*', 
230
  'generators/**/*', 
D
Initial  
David Heinemeier Hansson 已提交
231 232 233 234 235 236 237 238 239 240 241 242 243
  'html/**/*', 
  'lib/**/*'
]

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
    on top of either MySQL, PostgreSQL, or SQLite with eRuby-based templates.
  EOF

244
  s.add_dependency('rake', '>= 0.4.15')
245
  s.add_dependency('activesupport', '>= 0.9.0')
246 247
  s.add_dependency('activerecord', '>= 1.6.0')
  s.add_dependency('actionpack', '>= 1.4.0')
248
  s.add_dependency('actionmailer', '>= 0.6.1')
249
  s.add_dependency('actionwebservice', '>= 0.4.0')
D
Initial  
David Heinemeier Hansson 已提交
250

251
  s.rdoc_options << '--exclude' << '.'
D
David Heinemeier Hansson 已提交
252 253
  s.has_rdoc = false

254
  s.files = PKG_FILES.to_a.delete_if {|f| f.include?('.svn')}
D
Initial  
David Heinemeier Hansson 已提交
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
  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|
end

# Publish beta gem
desc "Publish the API documentation"
task :pgem => [:gem] do 
273 274
  Rake::SshFilePublisher.new("davidhh@comox.textdrive.com", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
  `ssh davidhh@comox.textdrive.com './gemupdate.sh'`
D
David Heinemeier Hansson 已提交
275
end