This repository has been archived by the owner on Jun 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
tasks.rb
116 lines (102 loc) · 2.62 KB
/
tasks.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
module Rake
class TargetTask < Task
def marker
"#{workdir name}.target"
end
# the first dependency is a special target dependency
def enhance(deps=nil, &block)
if deps
@target_dep = deps[0] if @prerequisites.empty?
@prerequisites |= deps
end
@actions << block if block_given?
self
end
# always run when using direct invocation
def invoke(*args)
out = `rm -vf #{marker}`
debug out
super
end
# stop the invocation chain if timestamp is later than every
# target in the target dependency chain
def invoke_with_call_chain(task_args, invocation_chain)
if !File.exist?(marker) or target_dep_timestamp > timestamp
pre = Rake.application.lookup "#{name}_pre"
pre.invoke if pre
super
post = Rake.application.lookup "#{name}_post"
post.invoke if post
puts "Target '#{name}' done\n\n"
end
end
def target_dep_timestamp
if @target_dep
td = application[@target_dep, @scope]
if td.respond_to? 'target_dep_timestamp'
stamp = td.target_dep_timestamp
return stamp > timestamp ? stamp : timestamp
end
end
timestamp
end
def timestamp
if File.exist? marker
File.mtime marker
else
Rake::EARLY
end
end
def execute(args=nil)
super
cmd = "touch #{marker}"
debug cmd
`#{cmd}`
end
end
class Package < Task
def invoke_with_call_chain(task_args, invocation_chain)
puts "Package: #{self.name}"
super
end
end
class ReleaseTask < Task
attr_reader :invoke_action
# the first block runs before the dependencies
# other actions as usual
def enhance(deps=nil, &block)
@prerequisites |= deps if deps
if block_given?
unless @invoke_action
@invoke_action = block
else
@actions << block
end
end
self
end
def clear_actions
@invoke_action = nil
super
end
def invoke(*args)
if @invoke_action
# use application.trace in > 0.9.2
$stderr.puts "** Execute #{name} (invoke_action)" if application.options.trace
@invoke_action.call(self)
end
super
end
def invoke_with_call_chain(task_args, invocation_chain)
puts "Release: #{self.name}"
super
end
class << self
def define_task(*args, &block)
t = Rake.application.define_task(self, *args, &block)
raise "ReleaseTask: taskname already in use: '#{t.name}'" unless ReleaseTask === t
t
end
end
end
end