Skip to content

Commit

Permalink
Simplify code to ensure file permissions are correct in packaged rele…
Browse files Browse the repository at this point in the history
…ases (now matches tzinfo-data's Rakefile).

Move gemspec into separate file.
Update copyright years in LICENSE file.
Remove no longer needed Timezone module building code from Rakefile.
  • Loading branch information
philr committed Nov 7, 2012
1 parent 25d5937 commit 722c9a6
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 196 deletions.
4 changes: 2 additions & 2 deletions LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2005-2006 Philip Ross
Copyright (c) 2005-2012 Philip Ross

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
Expand All @@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
225 changes: 31 additions & 194 deletions Rakefile
Expand Up @@ -3,28 +3,15 @@
# rake test - Runs all test cases.
# rake package - Runs test cases and builds packages for distribution.
# rake rdoc - Builds API documentation in doc dir.
# rake build_tz_modules - Builds Timezone modules and the Country index.
# Expects to find source data in ../data.
# rake build_tz_module zone=Zone/Name - Builds a single Timezone module.
# Expects to find source data in ../data.
# rake build_countries - Builds the Country index.
# Expects to find source data in ../data.

require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/gempackagetask'
require 'rubygems'
require 'rubygems/package_task'
require 'fileutils'

Rake::TaskManager.class_eval do
def remove_task(task_name)
@tasks.delete(task_name.to_s)
end
end

def remove_task(task_name)
Rake.application.remove_task(task_name)
end
spec = eval(File.read('tzinfo.gemspec'))

self.class.class_eval { alias_method :orig_sh, :sh }
private :orig_sh
Expand All @@ -39,82 +26,41 @@ def sh(*cmd, &block)
orig_sh(*cmd, &block)
end


PKG_VERSION = "0.3.22"
PKG_FILES = FileList[
'CHANGES',
'LICENSE',
'Rakefile',
'README',
'lib',
'lib/**/*'
].delete_if {|f| f.include?('.svn')}
PKG_TEST_FILES = FileList['test', 'test/**/*'].delete_if {|f| f.include?('.svn')}

RDOC_OPTIONS = %w[--exclude definitions --exclude indexes]
RDOC_EXTRA_FILES = %w[README CHANGES]

BUILD_TZ_CLASSES_DIR = 'lib/tzinfo.build_tz_classes'

SPEC = Gem::Specification.new do |s|
s.name = "tzinfo"
s.version = PKG_VERSION
s.author = "Philip Ross"
s.email = "phil.ross@gmail.com"
s.homepage = "http://tzinfo.rubyforge.org/"
s.platform = Gem::Platform::RUBY
s.summary = "Daylight-savings aware timezone library"
s.description = "TZInfo is a Ruby library that uses the standard tz (Olson) database to provide daylight savings aware transformations between times in different time zones."
s.files = PKG_FILES
s.test_files = PKG_TEST_FILES
s.require_path = "lib"
s.has_rdoc = true
s.extra_rdoc_files = RDOC_EXTRA_FILES
s.rdoc_options = RDOC_OPTIONS
s.rubyforge_project = "tzinfo"
end

package_task = Rake::GemPackageTask.new(SPEC) do |pkg|
package_task = Gem::PackageTask.new(spec) do |pkg|
pkg.need_zip = true
pkg.need_tar = true
pkg.need_tar_gz = true
pkg.tar_command = '__tar_with_owner__'
end

# Replace the Rake::PackageTask task that prepares the files to package with
# a version that ensures the permissions are correct for the package.
# Also just copy rather than link the files so that old versions are maintained.
remove_task package_task.package_dir_path
file package_task.package_dir_path => [package_task.package_dir] + package_task.package_files do
mkdir_p package_task.package_dir_path rescue nil
chmod(0755, package_task.package_dir_path)
package_task.package_files.each do |fn|
f = File.join(package_task.package_dir_path, fn)
fdir = File.dirname(f)
mkdir_p(fdir) if !File.exist?(fdir)
if File.directory?(fn)
mkdir_p(f)
chmod(0755, f)
else
rm_f f
cp(fn, f)
chmod(0644, f)
end
end
Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.title = "TZInfo Data"
rdoc.options << '--inline-source'
rdoc.options.concat spec.rdoc_options
rdoc.rdoc_files.include(spec.extra_rdoc_files)
rdoc.rdoc_files.include('lib')
end

Rake::Task[package_task.package_dir_path].enhance do
File.chmod(0755, package_task.package_dir_path)
recurse_chmod(package_task.package_dir_path)
end

# Replace the Rake::GemPackageTask task that builds the gem with a version that
# changes to the copied package directory first. This allows the gem builder
# to pick up the correct file permissions.
remove_task "#{package_task.package_dir}/#{package_task.gem_file}"
file "#{package_task.package_dir}/#{package_task.gem_file}" => [package_task.package_dir] + package_task.gem_spec.files do
when_writing("Creating GEM") do
chdir(package_task.package_dir_path) do
Gem::Builder.new(package_task.gem_spec).build
end

verbose(true) do
mv File.join(package_task.package_dir_path, package_task.gem_file), "#{package_task.package_dir}/#{package_task.gem_file}"
Rake::Task[:package].enhance do
FileUtils.rm_rf(package_task.package_dir_path)
end

def recurse_chmod(dir)
File.chmod(0755, dir)

Dir.entries(dir).each do |entry|
if entry != '.' && entry != '..'
path = File.join(dir, entry)
if File.directory?(path)
recurse_chmod(path)
else
File.chmod(0644, path)
end
end
end
end
Expand All @@ -137,112 +83,3 @@ end
Rake::TestTask.new('test_zoneinfo') do |t|
setup_tests(t, :zoneinfo)
end

Rake::RDocTask.new do |rdoc|
rdoc.rdoc_dir = 'doc'
rdoc.title = "TZInfo"
rdoc.options << '--inline-source'
rdoc.options.concat RDOC_OPTIONS
rdoc.rdoc_files.include(*RDOC_EXTRA_FILES)
rdoc.rdoc_files.include('lib')
end

task :build_tz_modules do
require 'lib/tzinfo/tzdataparser'

FileUtils.mkdir_p(BUILD_TZ_CLASSES_DIR)
begin
p = TZInfo::TZDataParser.new('../data', BUILD_TZ_CLASSES_DIR)
p.execute

['indexes', 'definitions'].each {|dir|
sync_svn("#{BUILD_TZ_CLASSES_DIR}/#{dir}", "lib/tzinfo/#{dir}")
}
ensure
FileUtils.rm_rf(BUILD_TZ_CLASSES_DIR)
end
end

def sync_svn(source_dir, target_dir)
puts "SVN Sync from #{source_dir} to #{target_dir}"

# Assumes a directory will never turn into a file and vice-versa
# (files will all end in .rb, directories won't).
# SVN wouldn't allow the change in a single commit anyway.

source_entries, target_entries = [source_dir, target_dir].collect {|dir|
Dir.entries(dir).delete_if {|entry| entry =~ /^\.(\.?|svn)$/}.sort
}

until source_entries.empty? || target_entries.empty?
if source_entries.last == target_entries.last
source_file = "#{source_dir}/#{source_entries.last}"
target_file = "#{target_dir}/#{target_entries.last}"

if File.directory?(source_file)
sync_svn(source_file, target_file)
else
FileUtils.cp(source_file, target_file)
end

source_entries.pop
target_entries.pop
elsif source_entries.last < target_entries.last
sync_svn_only_in_target(target_dir, target_entries)
else
sync_svn_only_in_source(source_dir, target_dir, source_entries)
end
end

until target_entries.empty?
sync_svn_only_in_target(target_dir, target_entries)
end

until source_entries.empty?
sync_svn_only_in_source(source_dir, target_dir, source_entries)
end
end

def sync_svn_only_in_target(target_dir, target_entries)
target_file = "#{target_dir}/#{target_entries.last}"
exec_svn "delete \"#{target_file}\""
target_entries.pop
end

def sync_svn_only_in_source(source_dir, target_dir, source_entries)
source_file = "#{source_dir}/#{source_entries.last}"
target_file = "#{target_dir}/#{source_entries.last}"

if File.directory?(source_file)
Dir.mkdir(target_file)
exec_svn "add \"#{target_file}\""
sync_svn(source_file, target_file)
else
FileUtils.cp(source_file, target_file)
exec_svn "add \"#{target_file}\""
end

source_entries.pop
end

def exec_svn(params)
puts "svn #{params}"
`svn #{params}`
raise "SVN exited with status #$?" if $? != 0
end

task :build_tz_module do
require 'lib/tzinfo/tzdataparser'
p = TZInfo::TZDataParser.new('../data', 'lib/tzinfo')
p.generate_countries = false
p.only_zones = [ENV['zone']]
p.execute
end

task :build_countries do
require 'lib/tzinfo/tzdataparser'
p = TZInfo::TZDataParser.new('../data', 'lib/tzinfo')
p.generate_countries = true
p.generate_zones = false
p.execute
end
17 changes: 17 additions & 0 deletions tzinfo.gemspec
@@ -0,0 +1,17 @@
Gem::Specification.new do |s|
s.name = 'tzinfo'
s.version = '1.0.0.pre1'
s.summary = 'Daylight-savings aware timezone library'
s.description = 'TZInfo is a Ruby library that uses the standard tz (Olson) database to provide daylight savings aware transformations between times in different time zones.'
s.author = 'Philip Ross'
s.email = 'phil.ross@gmail.com'
s.homepage = 'http://tzinfo.rubyforge.org'
s.license = 'MIT'
s.files = ['CHANGES', 'LICENSE', 'Rakefile', 'README', 'lib', 'test'] +
Dir['lib/**/*.rb'].delete_if {|f| f.include?('.svn')} +
Dir['test/**/*'].delete_if {|f| f.include?('.svn')}
s.platform = Gem::Platform::RUBY
s.require_path = 'lib'
s.extra_rdoc_files = ['README', 'CHANGES', 'LICENSE']
s.required_ruby_version = '>= 1.8.6'
end

0 comments on commit 722c9a6

Please sign in to comment.