Skip to content

Commit

Permalink
version 0.5.4.3 -- fowler directory fixes
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://rubyforge.org/var/svn/rake/trunk@436 5af023f1-ac1a-0410-98d6-829a145c37ef
  • Loading branch information
jimweirich committed Jul 2, 2005
1 parent 308f355 commit ceb84f1
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 16 deletions.
2 changes: 2 additions & 0 deletions rake/Rakefile
Expand Up @@ -20,6 +20,8 @@ CLEAN.include('**/*.o')
CLOBBER.include('doc/example/main', 'testdata')
CLOBBER.include('test/data/**/temp_*')
CLOBBER.include('test/data/chains/play.*')
CLOBBER.include('test/data/file_creation_task/build')
CLOBBER.include('test/data/file_creation_task/src')


def announce(msg='')
Expand Down
53 changes: 51 additions & 2 deletions rake/lib/rake.rb
Expand Up @@ -29,12 +29,13 @@
# referenced as a library via a require statement, but it can be
# distributed independently as an application.

RAKEVERSION = '0.5.4.2'
RAKEVERSION = '0.5.4.3'

require 'rbconfig'
require 'ftools'
require 'getoptlong'
require 'fileutils'
require 'singleton'

$last_comment = nil
$show_tasks = nil
Expand Down Expand Up @@ -367,6 +368,24 @@ def timestamp
end
end

######################################################################
# A FileCreationTask is a file task that when used as a dependency
# will be needed if and only if the file has not been created. Once
# created, it is not re-triggered if any of its dependencies are
# newer, nor does trigger any rebuilds of tasks that depend on it
# whenever it is updated.
class FileCreationTask < FileTask
# Is this file task needed? Yes if it doesn't exist.
def needed?
! File.exist?(name)
end

# Time stamp for file task.
def timestamp
Rake::EARLY
end
end

######################################################################
# Task Definition Functions ...

Expand Down Expand Up @@ -399,6 +418,10 @@ def file(args, &block)
FileTask.define_task(args, &block)
end

def file_create(args, &block)
FileCreationTask.define_task(args, &block)
end

# Declare a set of files tasks to create the given directories on
# demand.
#
Expand All @@ -407,7 +430,7 @@ def file(args, &block)
#
def directory(dir)
Rake.each_dir_parent(dir) do |d|
file d do |t|
file_create d do |t|
mkdir_p t.name if ! File.exist?(t.name)
end
end
Expand Down Expand Up @@ -1064,6 +1087,32 @@ def load(fn)
Kernel.load fn
end
end

# EarlyTime is a fake timestamp that occurs _before_ any other time
# value.
class EarlyTime
include Comparable
include Singleton

def <=>(other)
-1
end
end

EARLY = EarlyTime.instance
end

######################################################################
# Extensions to time to allow comparisons with an early time class.
class Time
alias pre_early_time_compare :<=>
def <=>(other)
if Rake::EarlyTime === other
- other.<=>(self)
else
pre_early_time_compare(other)
end
end
end

######################################################################
Expand Down
2 changes: 2 additions & 0 deletions rake/test/data/file_creation_task/.cvsignore
@@ -0,0 +1,2 @@
src
build
30 changes: 30 additions & 0 deletions rake/test/data/file_creation_task/Rakefile
@@ -0,0 +1,30 @@
N = 2

task :default => :run

BUILD_DIR = 'build'
task :clean do
rm_rf 'build'
rm_rf 'src'
end

task :run

TARGET_DIR = 'build/copies'

FileList['src/*'].each do |src|
directory TARGET_DIR
target = File.join TARGET_DIR, File.basename(src)
file target => [src, TARGET_DIR] do
cp src, target
sleep 3 if src !~ /foo#{N-1}$/
end
task :run => target
end

task :prep => :clean do
mkdir_p 'src'
N.times do |n|
touch "src/foo#{n}"
end
end
13 changes: 10 additions & 3 deletions rake/test/filecreation.rb
Expand Up @@ -3,6 +3,9 @@
require 'ftools'

module FileCreation
OLDFILE = "testdata/old"
NEWFILE = "testdata/new"

def create_timed_files(oldfile, newfile)
return if File.exist?(oldfile) && File.exist?(newfile)
old_time = create_file(oldfile)
Expand All @@ -12,10 +15,14 @@ def create_timed_files(oldfile, newfile)
end
end

def create_file(name)
dirname = File.dirname(name)
def create_dir(dirname)
FileUtils.mkdir_p(dirname) unless File.exist?(dirname)
open(name, "w") {|f| f.puts "HI" } unless File.exist?(name)
File.stat(dirname).mtime
end

def create_file(name)
create_dir(File.dirname(name))
FileUtils.touch(name) unless File.exist?(name)
File.stat(name).mtime
end

Expand Down
16 changes: 16 additions & 0 deletions rake/test/session_functional.rb
Expand Up @@ -22,6 +22,13 @@ def setup
lib_path = File.expand_path("lib")
@ruby_options = "-I#{lib_path} -I."
@verbose = ! ENV['VERBOSE'].nil?
if @verbose
puts
puts
puts "--------------------------------------------------------------------"
puts name
puts "--------------------------------------------------------------------"
end
end

def test_rake_default
Expand Down Expand Up @@ -114,6 +121,15 @@ def test_rules_chaining_to_file_task
remove_chaining_files
end

def test_file_creation_task
Dir.chdir("test/data/file_creation_task") do
rake "prep"
rake "run"
rake "run"
assert(@err !~ /^cp src/, "Should not recopy data")
end
end

private

def remove_chaining_files
Expand Down
26 changes: 26 additions & 0 deletions rake/test/test_earlytime.rb
@@ -0,0 +1,26 @@
#!/usr/bin/env ruby

require 'test/unit'
require 'rake'

class TestEarlyTime < Test::Unit::TestCase
def test_create
early = Rake::EarlyTime.instance
time = Time.mktime(1920, 1, 1, 0, 0, 0)
assert early <= Time.now
assert early < Time.now
assert early != Time.now
assert Time.now > early
assert Time.now >= early
assert Time.now != early
end

def test_original_time_compare_is_not_messed_up
t1 = Time.mktime(1920, 1, 1, 0, 0, 0)
t2 = Time.now
assert t1 < t2
assert t2 > t1
assert t1 == t1
assert t2 == t2
end
end
42 changes: 40 additions & 2 deletions rake/test/test_file_creation_task.rb
Expand Up @@ -7,11 +7,49 @@

######################################################################
class TestFileCreationTask < Test::Unit::TestCase
include FileCreation

DUMMY_DIR = 'testdata/dummy_dir'

def setup
Task.clear
end

def test_create

def teardown
FileUtils.rm_rf DUMMY_DIR
end

def test_file_needed
create_dir DUMMY_DIR
fc_task = Task[DUMMY_DIR]
assert_equal DUMMY_DIR, fc_task.name
FileUtils.rm_rf fc_task.name
assert fc_task.needed?, "file should be needed"
FileUtils.mkdir fc_task.name
assert_equal nil, fc_task.prerequisites.collect{|n| Task[n].timestamp}.max
assert ! fc_task.needed?, "file should not be needed"
end

def test_directory
directory DUMMY_DIR
fc_task = Task[DUMMY_DIR]
assert_equal DUMMY_DIR, fc_task.name
assert FileCreationTask === fc_task
end

def test_no_retriggers_on_filecreate_task
create_timed_files(OLDFILE, NEWFILE)
t1 = FileCreationTask.lookup(OLDFILE).enhance([NEWFILE])
t2 = FileCreationTask.lookup(NEWFILE)
assert ! t2.needed?, "Should not need to build new file"
assert ! t1.needed?, "Should not need to rebuild old file because of new"
end

def test_no_retriggers_on_file_task
create_timed_files(OLDFILE, NEWFILE)
t1 = FileTask.lookup(OLDFILE).enhance([NEWFILE])
t2 = FileCreationTask.lookup(NEWFILE)
assert ! t2.needed?, "Should not need to build new file"
assert ! t1.needed?, "Should not need to rebuild old file because of new"
end
end
15 changes: 6 additions & 9 deletions rake/test/test_file_task.rb
Expand Up @@ -29,9 +29,6 @@ def test_file_need
File.delete(ftask.name) rescue nil
end

OLDFILE = "testdata/old"
NEWFILE = "testdata/new"

def test_file_times_new_depends_on_old
create_timed_files(OLDFILE, NEWFILE)

Expand Down Expand Up @@ -97,9 +94,9 @@ def teardown
def test_directory
desc "DESC"
directory "testdata/a/b/c"
assert_equal FileTask, Task["testdata"].class
assert_equal FileTask, Task["testdata/a"].class
assert_equal FileTask, Task["testdata/a/b/c"].class
assert_equal FileCreationTask, Task["testdata"].class
assert_equal FileCreationTask, Task["testdata/a"].class
assert_equal FileCreationTask, Task["testdata/a/b/c"].class
assert_nil Task["testdata"].comment
assert_equal "DESC", Task["testdata/a/b/c"].comment
assert_nil Task["testdata/a/b"].comment
Expand All @@ -115,9 +112,9 @@ def test_directory_win32
FileUtils.mkdir_p("testdata")
Dir.chdir("testdata") do
directory 'c:/testdata/a/b/c'
assert_equal FileTask, Task['c:/testdata'].class
assert_equal FileTask, Task['c:/testdata/a'].class
assert_equal FileTask, Task['c:/testdata/a/b/c'].class
assert_equal FileCreationTask, Task['c:/testdata'].class
assert_equal FileCreationTask, Task['c:/testdata/a'].class
assert_equal FileCreationTask, Task['c:/testdata/a/b/c'].class
assert_nil Task['c:/testdata'].comment
assert_equal "WIN32 DESC", Task['c:/testdata/a/b/c'].comment
assert_nil Task['c:/testdata/a/b'].comment
Expand Down

0 comments on commit ceb84f1

Please sign in to comment.