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

root/trunk/railties/Rakefile

Revision 9134, 11.8 kB (checked in by david, 8 months ago)

Removed the default .htaccess configuration as there are so many good deployment options now (kept it as an example in README) [DHH]

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 task :default => :test
25
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
29 task :test do
30   Dir['test/**/*_test.rb'].all? do |file|
31     system("ruby -Itest #{file}")
32   end or raise "Failures"
33 end
34
35 Rake::TestTask.new("regular_test") do |t|
36   t.libs << 'test'
37   t.pattern = 'test/**/*_test.rb'
38   t.warning = true
39   t.verbose = true
40 end
41
42
43 BASE_DIRS = %w(
44   app
45   config/environments
46   config/initializers
47   components
48   db
49   doc
50   log
51   lib
52   lib/tasks
53   public
54   script
55   script/performance
56   script/process
57   test
58   vendor
59   vendor/plugins
60   tmp/sessions
61   tmp/cache
62   tmp/sockets
63   tmp/pids
64 )
65
66 APP_DIRS    = %w( models controllers helpers views views/layouts )
67 PUBLIC_DIRS = %w( images javascripts stylesheets )
68 TEST_DIRS   = %w( fixtures unit functional mocks mocks/development mocks/test )
69
70 LOG_FILES    = %w( server.log development.log test.log production.log )
71 HTML_FILES   = %w( 422.html 404.html 500.html index.html robots.txt favicon.ico images/rails.png
72                    javascripts/prototype.js javascripts/application.js
73                    javascripts/effects.js javascripts/dragdrop.js javascripts/controls.js )
74 BIN_FILES    = %w( about console destroy generate performance/benchmarker performance/profiler process/reaper process/spawner process/inspector runner server plugin )
75
76 VENDOR_LIBS = %w( actionpack activerecord actionmailer activesupport activeresource railties )
77
78
79 desc "Generates a fresh Rails package with documentation"
80 task :fresh_rails => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_vendor_libraries, :copy_ties_content, :generate_documentation ]
81
82 desc "Generates a fresh Rails package using GEMs with documentation"
83 task :fresh_gem_rails => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_ties_content, :copy_gem_environment ]
84
85 desc "Generates a fresh Rails package without documentation (faster)"
86 task :fresh_rails_without_docs => [ :clean, :make_dir_structure, :initialize_file_stubs, :copy_vendor_libraries, :copy_ties_content ]
87
88 desc "Generates a fresh Rails package without documentation (faster)"
89 task :fresh_rails_without_docs_using_links => [ :clean, :make_dir_structure, :initialize_file_stubs, :link_vendor_libraries, :copy_ties_content ]
90
91 desc "Generates minimal Rails package using symlinks"
92 task :dev => [ :clean, :make_dir_structure, :initialize_file_stubs, :link_vendor_libraries, :copy_ties_content ]
93
94 desc "Packages the fresh Rails package with documentation"
95 task :package => [ :clean, :fresh_rails ] do
96   system %{cd ..; tar -czvf #{PKG_NAME}-#{PKG_VERSION}.tgz #{PKG_NAME}}
97   system %{cd ..; zip -r #{PKG_NAME}-#{PKG_VERSION}.zip #{PKG_NAME}}
98 end
99
100 task :clean do
101   rm_rf PKG_DESTINATION
102 end
103
104 # Get external spinoffs -------------------------------------------------------------------
105
106 desc "Updates railties to the latest version of the javascript spinoffs"
107 task :update_js do
108   for js in %w( prototype controls dragdrop effects )
109     rm "html/javascripts/#{js}.js"
110     cp "./../actionpack/lib/action_view/helpers/javascripts/#{js}.js", "html/javascripts"
111   end
112 end
113
114 # Make directory structure ----------------------------------------------------------------
115
116 def make_dest_dirs(dirs, path = '.')
117   mkdir_p dirs.map { |dir| File.join(PKG_DESTINATION, path.to_s, dir) }
118 end
119
120 desc "Make the directory structure for the new Rails application"
121 task :make_dir_structure => [ :make_base_dirs, :make_app_dirs, :make_public_dirs, :make_test_dirs ]
122
123 task(:make_base_dirs)   { make_dest_dirs BASE_DIRS              }
124 task(:make_app_dirs)    { make_dest_dirs APP_DIRS,    'app'     }
125 task(:make_public_dirs) { make_dest_dirs PUBLIC_DIRS, 'public'  }
126 task(:make_test_dirs)   { make_dest_dirs TEST_DIRS,   'test'    }
127
128
129 # Initialize file stubs -------------------------------------------------------------------
130
131 desc "Initialize empty file stubs (such as for logging)"
132 task :initialize_file_stubs => [ :initialize_log_files ]
133
134 task :initialize_log_files do
135   log_dir = File.join(PKG_DESTINATION, 'log')
136   chmod 0777, log_dir
137   LOG_FILES.each do |log_file|
138     log_path = File.join(log_dir, log_file)
139     touch log_path
140     chmod 0666, log_path
141   end
142 end
143
144
145 # Copy Vendors ----------------------------------------------------------------------------
146
147 desc "Copy in all the Rails packages to vendor"
148 task :copy_vendor_libraries do
149   mkdir File.join(PKG_DESTINATION, 'vendor', 'rails')
150   VENDOR_LIBS.each { |dir| cp_r File.join('..', dir), File.join(PKG_DESTINATION, 'vendor', 'rails', dir) }
151   FileUtils.rm_r(Dir.glob(File.join(PKG_DESTINATION, 'vendor', 'rails', "**", ".svn")))
152 end
153
154 desc "Link in all the Rails packages to vendor"
155 task :link_vendor_libraries do
156   mkdir File.join(PKG_DESTINATION, 'vendor', 'rails')
157   VENDOR_LIBS.each { |dir| ln_s File.join('..', '..', '..', dir), File.join(PKG_DESTINATION, 'vendor', 'rails', dir) }
158 end
159
160
161 # Copy Ties Content -----------------------------------------------------------------------
162
163 desc "Make copies of all the default content of ties"
164 task :copy_ties_content => [
165   :copy_rootfiles, :copy_dispatches, :copy_html_files, :copy_application,
166   :copy_configs, :copy_binfiles, :copy_test_helpers, :copy_app_doc_readme ]
167
168 task :copy_dispatches do
169   copy_with_rewritten_ruby_path("dispatches/dispatch.rb", "#{PKG_DESTINATION}/public/dispatch.rb")
170   chmod 0755, "#{PKG_DESTINATION}/public/dispatch.rb"
171
172   copy_with_rewritten_ruby_path("dispatches/dispatch.rb", "#{PKG_DESTINATION}/public/dispatch.cgi")
173   chmod 0755, "#{PKG_DESTINATION}/public/dispatch.cgi"
174
175   copy_with_rewritten_ruby_path("dispatches/dispatch.fcgi", "#{PKG_DESTINATION}/public/dispatch.fcgi")
176   chmod 0755, "#{PKG_DESTINATION}/public/dispatch.fcgi"
177
178   # copy_with_rewritten_ruby_path("dispatches/gateway.cgi", "#{PKG_DESTINATION}/public/gateway.cgi")
179   # chmod 0755, "#{PKG_DESTINATION}/public/gateway.cgi"
180 end
181
182 task :copy_html_files do
183   HTML_FILES.each { |file| cp File.join('html', file), File.join(PKG_DESTINATION, 'public', file) }
184 end
185
186 task :copy_application do
187   cp "helpers/application.rb", "#{PKG_DESTINATION}/app/controllers/application.rb"
188   cp "helpers/application_helper.rb", "#{PKG_DESTINATION}/app/helpers/application_helper.rb"
189 end
190
191 task :copy_configs do
192   app_name = "rails"
193   socket = nil
194   require 'erb'
195   File.open("#{PKG_DESTINATION}/config/database.yml", 'w') {|f| f.write ERB.new(IO.read("configs/databases/mysql.yml"), nil, '-').result(binding)}
196  
197   cp "configs/routes.rb", "#{PKG_DESTINATION}/config/routes.rb"
198
199   cp "configs/initializers/inflections.rb", "#{PKG_DESTINATION}/config/initializers/inflections.rb"
200   cp "configs/initializers/mime_types.rb",  "#{PKG_DESTINATION}/config/initializers/mime_types.rb"
201
202   cp "environments/boot.rb",        "#{PKG_DESTINATION}/config/boot.rb"
203   cp "environments/environment.rb", "#{PKG_DESTINATION}/config/environment.rb"
204   cp "environments/production.rb",  "#{PKG_DESTINATION}/config/environments/production.rb"
205   cp "environments/development.rb", "#{PKG_DESTINATION}/config/environments/development.rb"
206   cp "environments/test.rb",        "#{PKG_DESTINATION}/config/environments/test.rb"
207 end
208
209 task :copy_binfiles do
210   BIN_FILES.each do |file|
211     dest_file = File.join(PKG_DESTINATION, 'script', file)
212     copy_with_rewritten_ruby_path(File.join('bin', file), dest_file)
213     chmod 0755, dest_file
214   end
215 end
216
217 task :copy_rootfiles do
218   cp "fresh_rakefile", "#{PKG_DESTINATION}/Rakefile"
219   cp "README", "#{PKG_DESTINATION}/README"
220   cp "CHANGELOG", "#{PKG_DESTINATION}/CHANGELOG"
221 end
222
223 task :copy_test_helpers do
224   cp "helpers/test_helper.rb", "#{PKG_DESTINATION}/test/test_helper.rb"
225 end
226
227 task :copy_app_doc_readme do
228   cp "doc/README_FOR_APP", "#{PKG_DESTINATION}/doc/README_FOR_APP"
229 end
230
231 def copy_with_rewritten_ruby_path(src_file, dest_file)
232   ruby = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name'])
233
234   File.open(dest_file, 'w') do |df|
235     File.open(src_file) do |sf|
236       line = sf.gets
237       if (line =~ /#!.+ruby\s*/) != nil
238         df.puts("#!#{ruby}")
239       else
240         df.puts(line)
241       end
242       df.write(sf.read)
243     end
244   end
245 end
246
247
248 # Generate documentation ------------------------------------------------------------------
249
250 desc "Generate documentation for the framework and for the empty application"
251 task :generate_documentation => [ :generate_app_doc, :generate_rails_framework_doc ]
252
253 task :generate_rails_framework_doc do
254   system %{cd #{PKG_DESTINATION}; rake doc:rails}
255 end
256
257 task :generate_app_doc do
258   File.cp "doc/README_FOR_APP", "#{PKG_DESTINATION}/doc/README_FOR_APP"
259   system %{cd #{PKG_DESTINATION}; rake doc:app}
260 end
261
262 Rake::RDocTask.new { |rdoc|
263   rdoc.rdoc_dir = 'doc'
264   rdoc.title    = "Railties -- Gluing the Engine to the Rails"
265   rdoc.options << '--line-numbers' << '--inline-source' << '--accessor' << 'cattr_accessor=object'
266   rdoc.options << '--charset' << 'utf-8'
267   rdoc.template = "#{ENV['template']}.rb" if ENV['template']
268   rdoc.rdoc_files.include('README', 'CHANGELOG')
269   rdoc.rdoc_files.include('lib/*.rb')
270   rdoc.rdoc_files.include('lib/rails_generator/*.rb')
271   rdoc.rdoc_files.include('lib/commands/**/*.rb')
272 }
273
274 # Generate GEM ----------------------------------------------------------------------------
275
276 task :copy_gem_environment do
277   cp "environments/environment.rb", "#{PKG_DESTINATION}/config/environment.rb"
278   chmod 0755, dest_file
279 end
280
281
282 PKG_FILES = FileList[
283   '[a-zA-Z]*',
284   'bin/**/*',
285   'builtin/**/*',
286   'configs/**/*',
287   'doc/**/*',
288   'dispatches/**/*',
289   'environments/**/*',
290   'helpers/**/*',
291   'generators/**/*',
292   'html/**/*',
293   'lib/**/*'
294 ] - [ 'test' ]
295
296 spec = Gem::Specification.new do |s|
297   s.platform = Gem::Platform::RUBY
298   s.name = 'rails'
299   s.version = PKG_VERSION
300   s.summary = "Web-application framework with template engine, control-flow layer, and ORM."
301   s.description = <<-EOF
302     Rails is a framework for building web-application using CGI, FCGI, mod_ruby, or WEBrick
303     on top of either MySQL, PostgreSQL, SQLite, DB2, SQL Server, or Oracle with eRuby- or Builder-based templates.
304   EOF
305
306   s.add_dependency('rake', '>= 0.7.2')
307   s.add_dependency('activesupport',    '= 2.0.2' + PKG_BUILD)
308   s.add_dependency('activerecord',     '= 2.0.2' + PKG_BUILD)
309   s.add_dependency('actionpack',       '= 2.0.2' + PKG_BUILD)
310   s.add_dependency('actionmailer',     '= 2.0.2' + PKG_BUILD)
311   s.add_dependency('activeresource',   '= 2.0.2' + PKG_BUILD)
312
313   s.rdoc_options << '--exclude' << '.'
314   s.has_rdoc = false
315
316   s.files = PKG_FILES.to_a.delete_if {|f| f.include?('.svn')}
317   s.require_path = 'lib'
318   s.bindir = "bin"                               # Use these for applications.
319   s.executables = ["rails"]
320   s.default_executable = "rails"
321
322   s.author = "David Heinemeier Hansson"
323   s.email = "david@loudthinking.com"
324   s.homepage = "http://www.rubyonrails.org"
325   s.rubyforge_project = "rails"
326 end
327
328 Rake::GemPackageTask.new(spec) do |pkg|
329   pkg.gem_spec = spec
330 end
331
332
333 # Publishing -------------------------------------------------------
334 desc "Publish the API documentation"
335 task :pgem => [:gem] do
336   Rake::SshFilePublisher.new("davidhh@wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
337   `ssh davidhh@wrath.rubyonrails.org './gemupdate.sh'`
338 end
339
340 desc "Publish the release files to RubyForge."
341 task :release => [ :package ] do
342   require 'rubyforge'
343
344   packages = %w( gem ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
345
346   rubyforge = RubyForge.new
347   rubyforge.login
348   rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages)
349 end
Note: See TracBrowser for help on using the browser.