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

root/trunk/activesupport/Rakefile

Revision 9153, 5.2 kB (checked in by gbuesing, 6 months ago)

TZInfo: Removing unneeded TimezoneProxy class

Line 
1 require 'rake/testtask'
2 require 'rake/rdoctask'
3 require 'rake/gempackagetask'
4 require 'rake/contrib/sshpublisher'
5
6 require File.join(File.dirname(__FILE__), 'lib', 'active_support', 'version')
7
8 PKG_BUILD     = ENV['PKG_BUILD'] ? '.' + ENV['PKG_BUILD'] : ''
9 PKG_NAME      = 'activesupport'
10 PKG_VERSION   = ActiveSupport::VERSION::STRING + PKG_BUILD
11 PKG_FILE_NAME = "#{PKG_NAME}-#{PKG_VERSION}"
12
13 RELEASE_NAME  = "REL #{PKG_VERSION}"
14
15 RUBY_FORGE_PROJECT = "activesupport"
16 RUBY_FORGE_USER    = "webster132"
17
18 task :default => :test
19 Rake::TestTask.new { |t|
20   t.libs << "test"
21   t.pattern = 'test/**/*_test.rb'
22   t.verbose = true
23   t.warning = true
24 }
25
26 # Create compressed packages
27 dist_dirs = [ "lib", "test"]
28
29 # Genereate the RDoc documentation
30
31 Rake::RDocTask.new { |rdoc|
32   rdoc.rdoc_dir = 'doc'
33   rdoc.title    = "Active Support -- Utility classes and standard library extensions from Rails"
34   rdoc.options << '--line-numbers' << '--inline-source'
35   rdoc.options << '--charset' << 'utf-8'
36   rdoc.template = "#{ENV['template']}.rb" if ENV['template']
37   rdoc.rdoc_files.include('README', 'CHANGELOG')
38   rdoc.rdoc_files.include('lib/active_support.rb')
39   rdoc.rdoc_files.include('lib/active_support/*.rb')
40   rdoc.rdoc_files.include('lib/active_support/**/*.rb')
41 }
42
43 spec = Gem::Specification.new do |s|
44   s.platform = Gem::Platform::RUBY
45   s.name = PKG_NAME
46   s.version = PKG_VERSION
47   s.summary = "Support and utility classes used by the Rails framework."
48   s.description = %q{Utility library which carries commonly used classes and goodies from the Rails framework}
49
50   s.files = [ "CHANGELOG", "README" ] + Dir.glob( "lib/**/*" ).delete_if { |item| item.include?( "\.svn" ) }
51   s.require_path = 'lib'
52   s.has_rdoc = true
53
54   s.author = "David Heinemeier Hansson"
55   s.email = "david@loudthinking.com"
56   s.homepage = "http://www.rubyonrails.org"
57   s.rubyforge_project = "activesupport"
58 end
59
60 Rake::GemPackageTask.new(spec) do |p|
61   p.gem_spec = spec
62   p.need_tar = true
63   p.need_zip = true
64 end
65
66 desc "Publish the beta gem"
67 task :pgem => [:package] do
68   Rake::SshFilePublisher.new("davidhh@wrath.rubyonrails.org", "public_html/gems/gems", "pkg", "#{PKG_FILE_NAME}.gem").upload
69   `ssh davidhh@wrath.rubyonrails.org './gemupdate.sh'`
70 end
71
72 desc "Publish the API documentation"
73 task :pdoc => [:rdoc] do
74   Rake::SshDirPublisher.new("davidhh@wrath.rubyonrails.org", "public_html/as", "doc").upload
75 end
76
77 desc "Publish the release files to RubyForge."
78 task :release => [ :package ] do
79   require 'rubyforge'
80   require 'rake/contrib/rubyforgepublisher'
81
82   packages = %w( gem tgz zip ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
83
84   rubyforge = RubyForge.new
85   rubyforge.login
86   rubyforge.add_release(PKG_NAME, PKG_NAME, "REL #{PKG_VERSION}", *packages)
87 end
88
89
90 require 'lib/active_support/values/time_zone'
91
92 namespace :tzinfo do
93   desc "Update bundled tzinfo gem. Only copies the subset of classes and definitions required to support Rails time zone features."
94   task :update => ['tzinfo:copy_classes', 'tzinfo:copy_definitions'] do
95     Rake::Task['tzinfo:cleanup_tmp'].invoke
96   end
97  
98   task :unpack_gem do
99     mkdir_p "tmp"
100     cd "tmp"
101     sh "gem unpack --version #{ENV['VERSION'] || "'> 0'"} tzinfo"
102     cd ".."
103   end
104  
105   task :copy_classes => :unpack_gem do
106     mkdir_p "#{destination_path}/tzinfo"
107     cp "#{tmp_path}/lib/tzinfo.rb", destination_path
108     comment_requires_for_excluded_classes!('tzinfo.rb')
109     files = FileList["#{tmp_path}/lib/tzinfo/*.rb"]
110     files.each do |file|
111       filename = File.basename(file)
112       unless excluded_classes.include? filename.sub(/.rb$/, '')
113         cp "#{tmp_path}/lib/tzinfo/#{filename}", "#{destination_path}/tzinfo"
114         comment_requires_for_excluded_classes!("tzinfo/#{filename}")
115       end
116     end
117   end
118  
119   task :copy_definitions => :unpack_gem do
120     definitions_path = "#{destination_path}/tzinfo/definitions/"
121     mkdir_p definitions_path
122     TimeZone::MAPPING.values.each do |zone|
123       subdir = nil
124       if /\// === zone
125         subdir = zone.sub(/\w+$/, '')
126         mkdir_p "#{definitions_path}/#{subdir}"
127       end
128       cp "#{tmp_path}/lib/tzinfo/definitions/#{zone}.rb", "#{definitions_path}/#{subdir}"
129     end
130   end
131
132   task :cleanup_tmp do
133     rm_rf "tmp"
134   end
135  
136   def comment_requires_for_excluded_classes!(file)
137     lines = open("#{destination_path}/#{file}") {|f| f.readlines}
138     updated = false
139    
140     new_lines = []
141     lines.each do |line|
142       if Regexp.new("require 'tzinfo/(#{excluded_classes.join('|')})'") === line
143         updated = true
144         new_lines << "# #{line}"
145       else
146         new_lines << line
147       end
148     end
149    
150     if updated
151       open("#{destination_path}/#{file}", "w") {|f| f.write(new_lines.join)}
152     end
153   end
154  
155   def version
156     ENV['VERSION'] ||= get_unpacked_version
157   end
158  
159   def get_unpacked_version
160     m = (FileList["tmp/tzinfo-*"].to_s.match /\d+\.\d+\.\d+/)
161     m ? m[0] : raise(LoadError, "TZInfo gem must be installed locally. `gem install tzinfo` and try again")
162   end
163  
164   def tmp_path
165     "tmp/tzinfo-#{version}"
166   end
167  
168   def destination_path
169     "lib/active_support/vendor/tzinfo-#{version}"
170   end
171  
172   def excluded_classes
173     %w(country country_index_definition country_info country_timezone timezone_index_definition timezone_proxy tzdataparser)
174   end
175 end
Note: See TracBrowser for help on using the browser.