rake 12.3.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +7 -0
  2. data/CONTRIBUTING.rdoc +43 -0
  3. data/Gemfile +3 -0
  4. data/History.rdoc +2344 -0
  5. data/MIT-LICENSE +21 -0
  6. data/README.rdoc +156 -0
  7. data/Rakefile +41 -0
  8. data/azure-pipelines.yml +11 -0
  9. data/bin/bundle +105 -0
  10. data/bin/console +7 -0
  11. data/bin/rake +29 -0
  12. data/bin/rdoc +29 -0
  13. data/bin/rubocop +29 -0
  14. data/bin/setup +6 -0
  15. data/doc/command_line_usage.rdoc +158 -0
  16. data/doc/example/Rakefile1 +38 -0
  17. data/doc/example/Rakefile2 +35 -0
  18. data/doc/example/a.c +6 -0
  19. data/doc/example/b.c +6 -0
  20. data/doc/example/main.c +11 -0
  21. data/doc/glossary.rdoc +42 -0
  22. data/doc/jamis.rb +592 -0
  23. data/doc/proto_rake.rdoc +127 -0
  24. data/doc/rake.1 +156 -0
  25. data/doc/rakefile.rdoc +622 -0
  26. data/doc/rational.rdoc +151 -0
  27. data/exe/rake +27 -0
  28. data/lib/rake.rb +71 -0
  29. data/lib/rake/application.rb +824 -0
  30. data/lib/rake/backtrace.rb +24 -0
  31. data/lib/rake/clean.rb +78 -0
  32. data/lib/rake/cloneable.rb +17 -0
  33. data/lib/rake/cpu_counter.rb +107 -0
  34. data/lib/rake/default_loader.rb +15 -0
  35. data/lib/rake/dsl_definition.rb +195 -0
  36. data/lib/rake/early_time.rb +22 -0
  37. data/lib/rake/ext/core.rb +26 -0
  38. data/lib/rake/ext/string.rb +176 -0
  39. data/lib/rake/file_creation_task.rb +25 -0
  40. data/lib/rake/file_list.rb +435 -0
  41. data/lib/rake/file_task.rb +54 -0
  42. data/lib/rake/file_utils.rb +137 -0
  43. data/lib/rake/file_utils_ext.rb +145 -0
  44. data/lib/rake/invocation_chain.rb +57 -0
  45. data/lib/rake/invocation_exception_mixin.rb +17 -0
  46. data/lib/rake/late_time.rb +18 -0
  47. data/lib/rake/linked_list.rb +112 -0
  48. data/lib/rake/loaders/makefile.rb +54 -0
  49. data/lib/rake/multi_task.rb +14 -0
  50. data/lib/rake/name_space.rb +38 -0
  51. data/lib/rake/packagetask.rb +207 -0
  52. data/lib/rake/phony.rb +16 -0
  53. data/lib/rake/private_reader.rb +21 -0
  54. data/lib/rake/promise.rb +100 -0
  55. data/lib/rake/pseudo_status.rb +30 -0
  56. data/lib/rake/rake_module.rb +67 -0
  57. data/lib/rake/rake_test_loader.rb +27 -0
  58. data/lib/rake/rule_recursion_overflow_error.rb +20 -0
  59. data/lib/rake/scope.rb +43 -0
  60. data/lib/rake/task.rb +413 -0
  61. data/lib/rake/task_argument_error.rb +8 -0
  62. data/lib/rake/task_arguments.rb +109 -0
  63. data/lib/rake/task_manager.rb +324 -0
  64. data/lib/rake/tasklib.rb +12 -0
  65. data/lib/rake/testtask.rb +224 -0
  66. data/lib/rake/thread_history_display.rb +49 -0
  67. data/lib/rake/thread_pool.rb +163 -0
  68. data/lib/rake/trace_output.rb +23 -0
  69. data/lib/rake/version.rb +10 -0
  70. data/lib/rake/win32.rb +51 -0
  71. data/rake.gemspec +42 -0
  72. metadata +199 -0
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ module Rake
3
+
4
+ # Error indicating an ill-formed task declaration.
5
+ class TaskArgumentError < ArgumentError
6
+ end
7
+
8
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+ module Rake
3
+
4
+ ##
5
+ # TaskArguments manage the arguments passed to a task.
6
+ #
7
+ class TaskArguments
8
+ include Enumerable
9
+
10
+ # Argument names
11
+ attr_reader :names
12
+
13
+ # Create a TaskArgument object with a list of argument +names+ and a set
14
+ # of associated +values+. +parent+ is the parent argument object.
15
+ def initialize(names, values, parent=nil)
16
+ @names = names
17
+ @parent = parent
18
+ @hash = {}
19
+ @values = values
20
+ names.each_with_index { |name, i|
21
+ next if values[i].nil? || values[i] == ""
22
+ @hash[name.to_sym] = values[i]
23
+ }
24
+ end
25
+
26
+ # Retrieve the complete array of sequential values
27
+ def to_a
28
+ @values.dup
29
+ end
30
+
31
+ # Retrieve the list of values not associated with named arguments
32
+ def extras
33
+ @values[@names.length..-1] || []
34
+ end
35
+
36
+ # Create a new argument scope using the prerequisite argument
37
+ # names.
38
+ def new_scope(names)
39
+ values = names.map { |n| self[n] }
40
+ self.class.new(names, values + extras, self)
41
+ end
42
+
43
+ # Find an argument value by name or index.
44
+ def [](index)
45
+ lookup(index.to_sym)
46
+ end
47
+
48
+ # Specify a hash of default values for task arguments. Use the
49
+ # defaults only if there is no specific value for the given
50
+ # argument.
51
+ def with_defaults(defaults)
52
+ @hash = defaults.merge(@hash)
53
+ end
54
+
55
+ # Enumerates the arguments and their values
56
+ def each(&block)
57
+ @hash.each(&block)
58
+ end
59
+
60
+ # Extracts the argument values at +keys+
61
+ def values_at(*keys)
62
+ keys.map { |k| lookup(k) }
63
+ end
64
+
65
+ # Returns the value of the given argument via method_missing
66
+ def method_missing(sym, *args)
67
+ lookup(sym.to_sym)
68
+ end
69
+
70
+ # Returns a Hash of arguments and their values
71
+ def to_hash
72
+ @hash.dup
73
+ end
74
+
75
+ def to_s # :nodoc:
76
+ inspect
77
+ end
78
+
79
+ def inspect # :nodoc:
80
+ inspection = @hash.map do |k,v|
81
+ "#{k.to_s}: #{v.to_s}"
82
+ end.join(", ")
83
+
84
+ "#<#{self.class} #{inspection}>"
85
+ end
86
+
87
+ # Returns true if +key+ is one of the arguments
88
+ def has_key?(key)
89
+ @hash.has_key?(key)
90
+ end
91
+ alias key? has_key?
92
+
93
+ def fetch(*args, &block)
94
+ @hash.fetch(*args, &block)
95
+ end
96
+
97
+ protected
98
+
99
+ def lookup(name) # :nodoc:
100
+ if @hash.has_key?(name)
101
+ @hash[name]
102
+ elsif @parent
103
+ @parent.lookup(name)
104
+ end
105
+ end
106
+ end
107
+
108
+ EMPTY_TASK_ARGS = TaskArguments.new([], []) # :nodoc:
109
+ end
@@ -0,0 +1,324 @@
1
+ # frozen_string_literal: true
2
+ module Rake
3
+
4
+ # The TaskManager module is a mixin for managing tasks.
5
+ module TaskManager
6
+ # Track the last comment made in the Rakefile.
7
+ attr_accessor :last_description
8
+
9
+ def initialize # :nodoc:
10
+ super
11
+ @tasks = Hash.new
12
+ @rules = Array.new
13
+ @scope = Scope.make
14
+ @last_description = nil
15
+ end
16
+
17
+ def create_rule(*args, &block) # :nodoc:
18
+ pattern, args, deps = resolve_args(args)
19
+ pattern = Regexp.new(Regexp.quote(pattern) + "$") if String === pattern
20
+ @rules << [pattern, args, deps, block]
21
+ end
22
+
23
+ def define_task(task_class, *args, &block) # :nodoc:
24
+ task_name, arg_names, deps = resolve_args(args)
25
+
26
+ original_scope = @scope
27
+ if String === task_name and
28
+ not task_class.ancestors.include? Rake::FileTask
29
+ task_name, *definition_scope = *(task_name.split(":").reverse)
30
+ @scope = Scope.make(*(definition_scope + @scope.to_a))
31
+ end
32
+
33
+ task_name = task_class.scope_name(@scope, task_name)
34
+ deps = [deps] unless deps.respond_to?(:to_ary)
35
+ deps = deps.map { |d| Rake.from_pathname(d).to_s }
36
+ task = intern(task_class, task_name)
37
+ task.set_arg_names(arg_names) unless arg_names.empty?
38
+ if Rake::TaskManager.record_task_metadata
39
+ add_location(task)
40
+ task.add_description(get_description(task))
41
+ end
42
+ task.enhance(deps, &block)
43
+ ensure
44
+ @scope = original_scope
45
+ end
46
+
47
+ # Lookup a task. Return an existing task if found, otherwise
48
+ # create a task of the current type.
49
+ def intern(task_class, task_name)
50
+ @tasks[task_name.to_s] ||= task_class.new(task_name, self)
51
+ end
52
+
53
+ # Find a matching task for +task_name+.
54
+ def [](task_name, scopes=nil)
55
+ task_name = task_name.to_s
56
+ self.lookup(task_name, scopes) or
57
+ enhance_with_matching_rule(task_name) or
58
+ synthesize_file_task(task_name) or
59
+ fail generate_message_for_undefined_task(task_name)
60
+ end
61
+
62
+ def generate_message_for_undefined_task(task_name)
63
+ message = "Don't know how to build task '#{task_name}' "\
64
+ "(See the list of available tasks with `#{Rake.application.name} --tasks`)"
65
+ message + generate_did_you_mean_suggestions(task_name)
66
+ end
67
+
68
+ def generate_did_you_mean_suggestions(task_name)
69
+ return "" unless defined?(::DidYouMean::SpellChecker)
70
+
71
+ suggestions = ::DidYouMean::SpellChecker.new(dictionary: @tasks.keys).correct(task_name.to_s)
72
+ if ::DidYouMean.respond_to?(:formatter)# did_you_mean v1.2.0 or later
73
+ ::DidYouMean.formatter.message_for(suggestions)
74
+ elsif defined?(::DidYouMean::Formatter) # before did_you_mean v1.2.0
75
+ ::DidYouMean::Formatter.new(suggestions).to_s
76
+ else
77
+ ""
78
+ end
79
+ end
80
+
81
+ def synthesize_file_task(task_name) # :nodoc:
82
+ return nil unless File.exist?(task_name)
83
+ define_task(Rake::FileTask, task_name)
84
+ end
85
+
86
+ # Resolve the arguments for a task/rule. Returns a triplet of
87
+ # [task_name, arg_name_list, prerequisites].
88
+ def resolve_args(args)
89
+ if args.last.is_a?(Hash)
90
+ deps = args.pop
91
+ resolve_args_with_dependencies(args, deps)
92
+ else
93
+ resolve_args_without_dependencies(args)
94
+ end
95
+ end
96
+
97
+ # Resolve task arguments for a task or rule when there are no
98
+ # dependencies declared.
99
+ #
100
+ # The patterns recognized by this argument resolving function are:
101
+ #
102
+ # task :t
103
+ # task :t, [:a]
104
+ #
105
+ def resolve_args_without_dependencies(args)
106
+ task_name = args.shift
107
+ if args.size == 1 && args.first.respond_to?(:to_ary)
108
+ arg_names = args.first.to_ary
109
+ else
110
+ arg_names = args
111
+ end
112
+ [task_name, arg_names, []]
113
+ end
114
+ private :resolve_args_without_dependencies
115
+
116
+ # Resolve task arguments for a task or rule when there are
117
+ # dependencies declared.
118
+ #
119
+ # The patterns recognized by this argument resolving function are:
120
+ #
121
+ # task :t => [:d]
122
+ # task :t, [a] => [:d]
123
+ #
124
+ def resolve_args_with_dependencies(args, hash) # :nodoc:
125
+ fail "Task Argument Error" if hash.size != 1
126
+ key, value = hash.map { |k, v| [k, v] }.first
127
+ if args.empty?
128
+ task_name = key
129
+ arg_names = []
130
+ deps = value || []
131
+ else
132
+ task_name = args.shift
133
+ arg_names = key
134
+ deps = value
135
+ end
136
+ deps = [deps] unless deps.respond_to?(:to_ary)
137
+ [task_name, arg_names, deps]
138
+ end
139
+ private :resolve_args_with_dependencies
140
+
141
+ # If a rule can be found that matches the task name, enhance the
142
+ # task with the prerequisites and actions from the rule. Set the
143
+ # source attribute of the task appropriately for the rule. Return
144
+ # the enhanced task or nil of no rule was found.
145
+ def enhance_with_matching_rule(task_name, level=0)
146
+ fail Rake::RuleRecursionOverflowError,
147
+ "Rule Recursion Too Deep" if level >= 16
148
+ @rules.each do |pattern, args, extensions, block|
149
+ if pattern && pattern.match(task_name)
150
+ task = attempt_rule(task_name, pattern, args, extensions, block, level)
151
+ return task if task
152
+ end
153
+ end
154
+ nil
155
+ rescue Rake::RuleRecursionOverflowError => ex
156
+ ex.add_target(task_name)
157
+ fail ex
158
+ end
159
+
160
+ # List of all defined tasks in this application.
161
+ def tasks
162
+ @tasks.values.sort_by { |t| t.name }
163
+ end
164
+
165
+ # List of all the tasks defined in the given scope (and its
166
+ # sub-scopes).
167
+ def tasks_in_scope(scope)
168
+ prefix = scope.path
169
+ tasks.select { |t|
170
+ /^#{prefix}:/ =~ t.name
171
+ }
172
+ end
173
+
174
+ # Clear all tasks in this application.
175
+ def clear
176
+ @tasks.clear
177
+ @rules.clear
178
+ end
179
+
180
+ # Lookup a task, using scope and the scope hints in the task name.
181
+ # This method performs straight lookups without trying to
182
+ # synthesize file tasks or rules. Special scope names (e.g. '^')
183
+ # are recognized. If no scope argument is supplied, use the
184
+ # current scope. Return nil if the task cannot be found.
185
+ def lookup(task_name, initial_scope=nil)
186
+ initial_scope ||= @scope
187
+ task_name = task_name.to_s
188
+ if task_name =~ /^rake:/
189
+ scopes = Scope.make
190
+ task_name = task_name.sub(/^rake:/, "")
191
+ elsif task_name =~ /^(\^+)/
192
+ scopes = initial_scope.trim($1.size)
193
+ task_name = task_name.sub(/^(\^+)/, "")
194
+ else
195
+ scopes = initial_scope
196
+ end
197
+ lookup_in_scope(task_name, scopes)
198
+ end
199
+
200
+ # Lookup the task name
201
+ def lookup_in_scope(name, scope)
202
+ loop do
203
+ tn = scope.path_with_task_name(name)
204
+ task = @tasks[tn]
205
+ return task if task
206
+ break if scope.empty?
207
+ scope = scope.tail
208
+ end
209
+ nil
210
+ end
211
+ private :lookup_in_scope
212
+
213
+ # Return the list of scope names currently active in the task
214
+ # manager.
215
+ def current_scope
216
+ @scope
217
+ end
218
+
219
+ # Evaluate the block in a nested namespace named +name+. Create
220
+ # an anonymous namespace if +name+ is nil.
221
+ def in_namespace(name)
222
+ name ||= generate_name
223
+ @scope = Scope.new(name, @scope)
224
+ ns = NameSpace.new(self, @scope)
225
+ yield(ns)
226
+ ns
227
+ ensure
228
+ @scope = @scope.tail
229
+ end
230
+
231
+ private
232
+
233
+ # Add a location to the locations field of the given task.
234
+ def add_location(task)
235
+ loc = find_location
236
+ task.locations << loc if loc
237
+ task
238
+ end
239
+
240
+ # Find the location that called into the dsl layer.
241
+ def find_location
242
+ locations = caller
243
+ i = 0
244
+ while locations[i]
245
+ return locations[i + 1] if locations[i] =~ /rake\/dsl_definition.rb/
246
+ i += 1
247
+ end
248
+ nil
249
+ end
250
+
251
+ # Generate an anonymous namespace name.
252
+ def generate_name
253
+ @seed ||= 0
254
+ @seed += 1
255
+ "_anon_#{@seed}"
256
+ end
257
+
258
+ def trace_rule(level, message) # :nodoc:
259
+ options.trace_output.puts "#{" " * level}#{message}" if
260
+ Rake.application.options.trace_rules
261
+ end
262
+
263
+ # Attempt to create a rule given the list of prerequisites.
264
+ def attempt_rule(task_name, task_pattern, args, extensions, block, level)
265
+ sources = make_sources(task_name, task_pattern, extensions)
266
+ prereqs = sources.map { |source|
267
+ trace_rule level, "Attempting Rule #{task_name} => #{source}"
268
+ if File.exist?(source) || Rake::Task.task_defined?(source)
269
+ trace_rule level, "(#{task_name} => #{source} ... EXIST)"
270
+ source
271
+ elsif parent = enhance_with_matching_rule(source, level + 1)
272
+ trace_rule level, "(#{task_name} => #{source} ... ENHANCE)"
273
+ parent.name
274
+ else
275
+ trace_rule level, "(#{task_name} => #{source} ... FAIL)"
276
+ return nil
277
+ end
278
+ }
279
+ task = FileTask.define_task(task_name, { args => prereqs }, &block)
280
+ task.sources = prereqs
281
+ task
282
+ end
283
+
284
+ # Make a list of sources from the list of file name extensions /
285
+ # translation procs.
286
+ def make_sources(task_name, task_pattern, extensions)
287
+ result = extensions.map { |ext|
288
+ case ext
289
+ when /%/
290
+ task_name.pathmap(ext)
291
+ when %r{/}
292
+ ext
293
+ when /^\./
294
+ source = task_name.sub(task_pattern, ext)
295
+ source == ext ? task_name.ext(ext) : source
296
+ when String
297
+ ext
298
+ when Proc, Method
299
+ if ext.arity == 1
300
+ ext.call(task_name)
301
+ else
302
+ ext.call
303
+ end
304
+ else
305
+ fail "Don't know how to handle rule dependent: #{ext.inspect}"
306
+ end
307
+ }
308
+ result.flatten
309
+ end
310
+
311
+ # Return the current description, clearing it in the process.
312
+ def get_description(task)
313
+ desc = @last_description
314
+ @last_description = nil
315
+ desc
316
+ end
317
+
318
+ class << self
319
+ attr_accessor :record_task_metadata # :nodoc:
320
+ TaskManager.record_task_metadata = false
321
+ end
322
+ end
323
+
324
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+ require "rake"
3
+
4
+ module Rake
5
+
6
+ # Base class for Task Libraries.
7
+ class TaskLib
8
+ include Cloneable
9
+ include Rake::DSL
10
+ end
11
+
12
+ end