jimweirich-rake 0.8.4.99 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGES +24 -1
- data/README +1 -1
- data/Rakefile +8 -4
- data/doc/rakefile.rdoc +20 -6
- data/doc/release_notes/rake-0.8.5.rdoc +53 -0
- data/lib/rake.rb +27 -2458
- data/lib/rake/application.rb +533 -0
- data/lib/rake/cloneable.rb +25 -0
- data/lib/rake/default_loader.rb +10 -0
- data/lib/rake/dsl.rb +117 -0
- data/lib/rake/early_time.rb +18 -0
- data/lib/rake/ext/module.rb +60 -0
- data/lib/rake/ext/string.rb +165 -0
- data/lib/rake/ext/time.rb +14 -0
- data/lib/rake/file_creation_task.rb +24 -0
- data/lib/rake/file_list.rb +410 -0
- data/lib/rake/file_task.rb +47 -0
- data/lib/rake/file_utils.rb +103 -0
- data/lib/rake/invocation_chain.rb +51 -0
- data/lib/rake/multi_task.rb +16 -0
- data/lib/rake/name_space.rb +25 -0
- data/lib/rake/psuedo_status.rb +24 -0
- data/lib/rake/rake_file_utils.rb +133 -0
- data/lib/rake/rake_module.rb +25 -0
- data/lib/rake/rule_recursion_overflow_error.rb +20 -0
- data/lib/rake/task.rb +301 -0
- data/lib/rake/task_argument_error.rb +7 -0
- data/lib/rake/task_arguments.rb +78 -0
- data/lib/rake/task_manager.rb +306 -0
- data/test/data/comments/Rakefile +18 -0
- data/test/session_functional.rb +29 -0
- data/test/test_fileutils.rb +1 -1
- metadata +28 -5
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'rake/task.rb'
|
2
|
+
require 'rake/early_time'
|
3
|
+
|
4
|
+
module Rake
|
5
|
+
# #########################################################################
|
6
|
+
# A FileTask is a task that includes time based dependencies. If any of a
|
7
|
+
# FileTask's prerequisites have a timestamp that is later than the file
|
8
|
+
# represented by this task, then the file must be rebuilt (using the
|
9
|
+
# supplied actions).
|
10
|
+
#
|
11
|
+
class FileTask < Task
|
12
|
+
|
13
|
+
# Is this file task needed? Yes if it doesn't exist, or if its time stamp
|
14
|
+
# is out of date.
|
15
|
+
def needed?
|
16
|
+
! File.exist?(name) || out_of_date?(timestamp)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Time stamp for file task.
|
20
|
+
def timestamp
|
21
|
+
if File.exist?(name)
|
22
|
+
File.mtime(name.to_s)
|
23
|
+
else
|
24
|
+
Rake::EARLY
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
# Are there any prerequisites with a later time than the given time stamp?
|
31
|
+
def out_of_date?(stamp)
|
32
|
+
@prerequisites.any? { |n| application[n].timestamp > stamp}
|
33
|
+
end
|
34
|
+
|
35
|
+
# ----------------------------------------------------------------
|
36
|
+
# Task class methods.
|
37
|
+
#
|
38
|
+
class << self
|
39
|
+
# Apply the scope to the task name according to the rules for this kind
|
40
|
+
# of task. File based tasks ignore the scope when creating the name.
|
41
|
+
def scope_name(scope, task_name)
|
42
|
+
task_name
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
@@ -0,0 +1,103 @@
|
|
1
|
+
# ###########################################################################
|
2
|
+
# This a FileUtils extension that defines several additional commands to be
|
3
|
+
# added to the FileUtils utility functions.
|
4
|
+
#
|
5
|
+
module FileUtils
|
6
|
+
RUBY = File.join(
|
7
|
+
Config::CONFIG['bindir'],
|
8
|
+
Config::CONFIG['ruby_install_name'] + Config::CONFIG['EXEEXT']).
|
9
|
+
sub(/.*\s.*/m, '"\&"')
|
10
|
+
|
11
|
+
OPT_TABLE['sh'] = %w(noop verbose)
|
12
|
+
OPT_TABLE['ruby'] = %w(noop verbose)
|
13
|
+
|
14
|
+
# Run the system command +cmd+. If multiple arguments are given the command
|
15
|
+
# is not run with the shell (same semantics as Kernel::exec and
|
16
|
+
# Kernel::system).
|
17
|
+
#
|
18
|
+
# Example:
|
19
|
+
# sh %{ls -ltr}
|
20
|
+
#
|
21
|
+
# sh 'ls', 'file with spaces'
|
22
|
+
#
|
23
|
+
# # check exit status after command runs
|
24
|
+
# sh %{grep pattern file} do |ok, res|
|
25
|
+
# if ! ok
|
26
|
+
# puts "pattern not found (status = #{res.exitstatus})"
|
27
|
+
# end
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
def sh(*cmd, &block)
|
31
|
+
options = (Hash === cmd.last) ? cmd.pop : {}
|
32
|
+
unless block_given?
|
33
|
+
show_command = cmd.join(" ")
|
34
|
+
show_command = show_command[0,42] + "..." unless $trace
|
35
|
+
# TODO code application logic heref show_command.length > 45
|
36
|
+
block = lambda { |ok, status|
|
37
|
+
ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
|
38
|
+
}
|
39
|
+
end
|
40
|
+
if RakeFileUtils.verbose_flag == :default
|
41
|
+
options[:verbose] = true
|
42
|
+
else
|
43
|
+
options[:verbose] ||= RakeFileUtils.verbose_flag
|
44
|
+
end
|
45
|
+
options[:noop] ||= RakeFileUtils.nowrite_flag
|
46
|
+
rake_check_options options, :noop, :verbose
|
47
|
+
rake_output_message cmd.join(" ") if options[:verbose]
|
48
|
+
unless options[:noop]
|
49
|
+
res = rake_system(*cmd)
|
50
|
+
status = $?
|
51
|
+
status = PseudoStatus.new(1) if !res && status.nil?
|
52
|
+
block.call(res, status)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def rake_system(*cmd)
|
57
|
+
Rake::AltSystem.system(*cmd)
|
58
|
+
end
|
59
|
+
private :rake_system
|
60
|
+
|
61
|
+
# Run a Ruby interpreter with the given arguments.
|
62
|
+
#
|
63
|
+
# Example:
|
64
|
+
# ruby %{-pe '$_.upcase!' <README}
|
65
|
+
#
|
66
|
+
def ruby(*args,&block)
|
67
|
+
options = (Hash === args.last) ? args.pop : {}
|
68
|
+
if args.length > 1 then
|
69
|
+
sh(*([RUBY] + args + [options]), &block)
|
70
|
+
else
|
71
|
+
sh("#{RUBY} #{args.first}", options, &block)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
LN_SUPPORTED = [true]
|
76
|
+
|
77
|
+
# Attempt to do a normal file link, but fall back to a copy if the link
|
78
|
+
# fails.
|
79
|
+
def safe_ln(*args)
|
80
|
+
unless LN_SUPPORTED[0]
|
81
|
+
cp(*args)
|
82
|
+
else
|
83
|
+
begin
|
84
|
+
ln(*args)
|
85
|
+
rescue StandardError, NotImplementedError => ex
|
86
|
+
LN_SUPPORTED[0] = false
|
87
|
+
cp(*args)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Split a file path into individual directory names.
|
93
|
+
#
|
94
|
+
# Example:
|
95
|
+
# split_all("a/b/c") => ['a', 'b', 'c']
|
96
|
+
#
|
97
|
+
def split_all(path)
|
98
|
+
head, tail = File.split(path)
|
99
|
+
return [tail] if head == '.' || tail == '/'
|
100
|
+
return [head, tail] if head == '/'
|
101
|
+
return split_all(head) + [tail]
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Rake
|
2
|
+
|
3
|
+
####################################################################
|
4
|
+
# InvocationChain tracks the chain of task invocations to detect
|
5
|
+
# circular dependencies.
|
6
|
+
class InvocationChain
|
7
|
+
def initialize(value, tail)
|
8
|
+
@value = value
|
9
|
+
@tail = tail
|
10
|
+
end
|
11
|
+
|
12
|
+
def member?(obj)
|
13
|
+
@value == obj || @tail.member?(obj)
|
14
|
+
end
|
15
|
+
|
16
|
+
def append(value)
|
17
|
+
if member?(value)
|
18
|
+
fail RuntimeError, "Circular dependency detected: #{to_s} => #{value}"
|
19
|
+
end
|
20
|
+
self.class.new(value, self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
"#{prefix}#{@value}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.append(value, chain)
|
28
|
+
chain.append(value)
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def prefix
|
34
|
+
"#{@tail.to_s} => "
|
35
|
+
end
|
36
|
+
|
37
|
+
class EmptyInvocationChain
|
38
|
+
def member?(obj)
|
39
|
+
false
|
40
|
+
end
|
41
|
+
def append(value)
|
42
|
+
InvocationChain.new(value, self)
|
43
|
+
end
|
44
|
+
def to_s
|
45
|
+
"TOP"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
EMPTY = EmptyInvocationChain.new
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Rake
|
2
|
+
|
3
|
+
# Same as a regular task, but the immediate prerequisites are done in
|
4
|
+
# parallel using Ruby threads.
|
5
|
+
#
|
6
|
+
class MultiTask < Task
|
7
|
+
private
|
8
|
+
def invoke_prerequisites(args, invocation_chain)
|
9
|
+
threads = @prerequisites.collect { |p|
|
10
|
+
Thread.new(p) { |r| application[r].invoke_with_call_chain(args, invocation_chain) }
|
11
|
+
}
|
12
|
+
threads.each { |t| t.join }
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Rake
|
2
|
+
|
3
|
+
# The NameSpace class will lookup task names in the the scope
|
4
|
+
# defined by a +namespace+ command.
|
5
|
+
#
|
6
|
+
class NameSpace
|
7
|
+
|
8
|
+
# Create a namespace lookup object using the given task manager
|
9
|
+
# and the list of scopes.
|
10
|
+
def initialize(task_manager, scope_list)
|
11
|
+
@task_manager = task_manager
|
12
|
+
@scope = scope_list.dup
|
13
|
+
end
|
14
|
+
|
15
|
+
# Lookup a task named +name+ in the namespace.
|
16
|
+
def [](name)
|
17
|
+
@task_manager.lookup(name, @scope)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Return the list of tasks defined in this and nested namespaces.
|
21
|
+
def tasks
|
22
|
+
@task_manager.tasks_in_scope(@scope)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Rake
|
2
|
+
|
3
|
+
####################################################################
|
4
|
+
# Exit status class for times the system just gives us a nil.
|
5
|
+
class PseudoStatus
|
6
|
+
attr_reader :exitstatus
|
7
|
+
def initialize(code=0)
|
8
|
+
@exitstatus = code
|
9
|
+
end
|
10
|
+
def to_i
|
11
|
+
@exitstatus << 8
|
12
|
+
end
|
13
|
+
def >>(n)
|
14
|
+
to_i >> n
|
15
|
+
end
|
16
|
+
def stopped?
|
17
|
+
false
|
18
|
+
end
|
19
|
+
def exited?
|
20
|
+
true
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'rake/file_utils'
|
2
|
+
|
3
|
+
# ###########################################################################
|
4
|
+
# RakeFileUtils provides a custom version of the FileUtils methods that
|
5
|
+
# respond to the <tt>verbose</tt> and <tt>nowrite</tt> commands.
|
6
|
+
#
|
7
|
+
module RakeFileUtils
|
8
|
+
include FileUtils
|
9
|
+
|
10
|
+
class << self
|
11
|
+
attr_accessor :verbose_flag, :nowrite_flag
|
12
|
+
end
|
13
|
+
RakeFileUtils.verbose_flag = :default
|
14
|
+
RakeFileUtils.nowrite_flag = false
|
15
|
+
|
16
|
+
$fileutils_verbose = true
|
17
|
+
$fileutils_nowrite = false
|
18
|
+
|
19
|
+
FileUtils::OPT_TABLE.each do |name, opts|
|
20
|
+
default_options = []
|
21
|
+
if opts.include?(:verbose) || opts.include?("verbose")
|
22
|
+
default_options << ':verbose => RakeFileUtils.verbose_flag'
|
23
|
+
end
|
24
|
+
if opts.include?(:noop) || opts.include?("noop")
|
25
|
+
default_options << ':noop => RakeFileUtils.nowrite_flag'
|
26
|
+
end
|
27
|
+
|
28
|
+
next if default_options.empty?
|
29
|
+
module_eval(<<-EOS, __FILE__, __LINE__ + 1)
|
30
|
+
def #{name}( *args, &block )
|
31
|
+
super(
|
32
|
+
*rake_merge_option(args,
|
33
|
+
#{default_options.join(', ')}
|
34
|
+
), &block)
|
35
|
+
end
|
36
|
+
EOS
|
37
|
+
end
|
38
|
+
|
39
|
+
# Get/set the verbose flag controlling output from the FileUtils utilities.
|
40
|
+
# If verbose is true, then the utility method is echoed to standard output.
|
41
|
+
#
|
42
|
+
# Examples:
|
43
|
+
# verbose # return the current value of the verbose flag
|
44
|
+
# verbose(v) # set the verbose flag to _v_.
|
45
|
+
# verbose(v) { code } # Execute code with the verbose flag set temporarily to _v_.
|
46
|
+
# # Return to the original value when code is done.
|
47
|
+
def verbose(value=nil)
|
48
|
+
oldvalue = RakeFileUtils.verbose_flag
|
49
|
+
RakeFileUtils.verbose_flag = value unless value.nil?
|
50
|
+
if block_given?
|
51
|
+
begin
|
52
|
+
yield
|
53
|
+
ensure
|
54
|
+
RakeFileUtils.verbose_flag = oldvalue
|
55
|
+
end
|
56
|
+
end
|
57
|
+
RakeFileUtils.verbose_flag
|
58
|
+
end
|
59
|
+
|
60
|
+
# Get/set the nowrite flag controlling output from the FileUtils utilities.
|
61
|
+
# If verbose is true, then the utility method is echoed to standard output.
|
62
|
+
#
|
63
|
+
# Examples:
|
64
|
+
# nowrite # return the current value of the nowrite flag
|
65
|
+
# nowrite(v) # set the nowrite flag to _v_.
|
66
|
+
# nowrite(v) { code } # Execute code with the nowrite flag set temporarily to _v_.
|
67
|
+
# # Return to the original value when code is done.
|
68
|
+
def nowrite(value=nil)
|
69
|
+
oldvalue = RakeFileUtils.nowrite_flag
|
70
|
+
RakeFileUtils.nowrite_flag = value unless value.nil?
|
71
|
+
if block_given?
|
72
|
+
begin
|
73
|
+
yield
|
74
|
+
ensure
|
75
|
+
RakeFileUtils.nowrite_flag = oldvalue
|
76
|
+
end
|
77
|
+
end
|
78
|
+
oldvalue
|
79
|
+
end
|
80
|
+
|
81
|
+
# Use this function to prevent protentially destructive ruby code from
|
82
|
+
# running when the :nowrite flag is set.
|
83
|
+
#
|
84
|
+
# Example:
|
85
|
+
#
|
86
|
+
# when_writing("Building Project") do
|
87
|
+
# project.build
|
88
|
+
# end
|
89
|
+
#
|
90
|
+
# The following code will build the project under normal conditions. If the
|
91
|
+
# nowrite(true) flag is set, then the example will print:
|
92
|
+
# DRYRUN: Building Project
|
93
|
+
# instead of actually building the project.
|
94
|
+
#
|
95
|
+
def when_writing(msg=nil)
|
96
|
+
if RakeFileUtils.nowrite_flag
|
97
|
+
puts "DRYRUN: #{msg}" if msg
|
98
|
+
else
|
99
|
+
yield
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
# Merge the given options with the default values.
|
104
|
+
def rake_merge_option(args, defaults)
|
105
|
+
if Hash === args.last
|
106
|
+
defaults.update(args.last)
|
107
|
+
args.pop
|
108
|
+
end
|
109
|
+
args.push defaults
|
110
|
+
args
|
111
|
+
end
|
112
|
+
private :rake_merge_option
|
113
|
+
|
114
|
+
# Send the message to the default rake output (which is $stderr).
|
115
|
+
def rake_output_message(message)
|
116
|
+
$stderr.puts(message)
|
117
|
+
end
|
118
|
+
private :rake_output_message
|
119
|
+
|
120
|
+
# Check that the options do not contain options not listed in +optdecl+. An
|
121
|
+
# ArgumentError exception is thrown if non-declared options are found.
|
122
|
+
def rake_check_options(options, *optdecl)
|
123
|
+
h = options.dup
|
124
|
+
optdecl.each do |name|
|
125
|
+
h.delete name
|
126
|
+
end
|
127
|
+
raise ArgumentError, "no such option: #{h.keys.join(' ')}" unless h.empty?
|
128
|
+
end
|
129
|
+
private :rake_check_options
|
130
|
+
|
131
|
+
extend self
|
132
|
+
end
|
133
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rake/application'
|
2
|
+
|
3
|
+
module Rake
|
4
|
+
|
5
|
+
# Rake module singleton methods.
|
6
|
+
#
|
7
|
+
class << self
|
8
|
+
# Current Rake Application
|
9
|
+
def application
|
10
|
+
@application ||= Rake::Application.new
|
11
|
+
end
|
12
|
+
|
13
|
+
# Set the current Rake application object.
|
14
|
+
def application=(app)
|
15
|
+
@application = app
|
16
|
+
end
|
17
|
+
|
18
|
+
# Return the original directory where the Rake application was started.
|
19
|
+
def original_dir
|
20
|
+
application.original_dir
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
module Rake
|
3
|
+
|
4
|
+
# Error indicating a recursion overflow error in task selection.
|
5
|
+
class RuleRecursionOverflowError < StandardError
|
6
|
+
def initialize(*args)
|
7
|
+
super
|
8
|
+
@targets = []
|
9
|
+
end
|
10
|
+
|
11
|
+
def add_target(target)
|
12
|
+
@targets << target
|
13
|
+
end
|
14
|
+
|
15
|
+
def message
|
16
|
+
super + ": [" + @targets.reverse.join(' => ') + "]"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|