rake 10.5.0 → 13.2.1

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.
Files changed (159) hide show
  1. checksums.yaml +5 -5
  2. data/History.rdoc +2032 -288
  3. data/README.rdoc +40 -24
  4. data/doc/jamis.rb +1 -0
  5. data/doc/rake.1 +139 -124
  6. data/doc/rakefile.rdoc +2 -4
  7. data/{bin → exe}/rake +1 -7
  8. data/lib/rake/application.rb +164 -93
  9. data/lib/rake/backtrace.rb +4 -2
  10. data/lib/rake/clean.rb +7 -5
  11. data/lib/rake/cloneable.rb +1 -0
  12. data/lib/rake/cpu_counter.rb +10 -28
  13. data/lib/rake/default_loader.rb +1 -0
  14. data/lib/rake/dsl_definition.rb +8 -13
  15. data/lib/rake/early_time.rb +1 -0
  16. data/lib/rake/ext/core.rb +1 -0
  17. data/lib/rake/ext/string.rb +22 -21
  18. data/lib/rake/file_creation_task.rb +4 -3
  19. data/lib/rake/file_list.rb +34 -27
  20. data/lib/rake/file_task.rb +19 -7
  21. data/lib/rake/file_utils.rb +37 -33
  22. data/lib/rake/file_utils_ext.rb +8 -18
  23. data/lib/rake/invocation_chain.rb +1 -0
  24. data/lib/rake/invocation_exception_mixin.rb +1 -0
  25. data/lib/rake/late_time.rb +2 -1
  26. data/lib/rake/linked_list.rb +24 -15
  27. data/lib/rake/loaders/makefile.rb +5 -4
  28. data/lib/rake/multi_task.rb +2 -1
  29. data/lib/rake/name_space.rb +1 -1
  30. data/lib/rake/packagetask.rb +40 -17
  31. data/lib/rake/phony.rb +2 -1
  32. data/lib/rake/private_reader.rb +1 -0
  33. data/lib/rake/promise.rb +13 -12
  34. data/lib/rake/pseudo_status.rb +1 -0
  35. data/lib/rake/rake_module.rb +30 -1
  36. data/lib/rake/rake_test_loader.rb +9 -4
  37. data/lib/rake/rule_recursion_overflow_error.rb +2 -2
  38. data/lib/rake/scope.rb +3 -2
  39. data/lib/rake/task.rb +82 -31
  40. data/lib/rake/task_argument_error.rb +1 -0
  41. data/lib/rake/task_arguments.rb +15 -4
  42. data/lib/rake/task_manager.rb +56 -32
  43. data/lib/rake/tasklib.rb +2 -14
  44. data/lib/rake/testtask.rb +37 -61
  45. data/lib/rake/thread_history_display.rb +4 -3
  46. data/lib/rake/thread_pool.rb +16 -17
  47. data/lib/rake/trace_output.rb +2 -1
  48. data/lib/rake/version.rb +4 -1
  49. data/lib/rake/win32.rb +10 -15
  50. data/lib/rake.rb +34 -43
  51. data/rake.gemspec +101 -0
  52. metadata +24 -223
  53. data/.autotest +0 -7
  54. data/.rubocop.yml +0 -27
  55. data/.togglerc +0 -7
  56. data/CONTRIBUTING.rdoc +0 -38
  57. data/Manifest.txt +0 -166
  58. data/Rakefile +0 -81
  59. data/doc/release_notes/rake-0.4.14.rdoc +0 -23
  60. data/doc/release_notes/rake-0.4.15.rdoc +0 -35
  61. data/doc/release_notes/rake-0.5.0.rdoc +0 -53
  62. data/doc/release_notes/rake-0.5.3.rdoc +0 -78
  63. data/doc/release_notes/rake-0.5.4.rdoc +0 -46
  64. data/doc/release_notes/rake-0.6.0.rdoc +0 -141
  65. data/doc/release_notes/rake-0.7.0.rdoc +0 -119
  66. data/doc/release_notes/rake-0.7.1.rdoc +0 -59
  67. data/doc/release_notes/rake-0.7.2.rdoc +0 -121
  68. data/doc/release_notes/rake-0.7.3.rdoc +0 -47
  69. data/doc/release_notes/rake-0.8.0.rdoc +0 -114
  70. data/doc/release_notes/rake-0.8.2.rdoc +0 -165
  71. data/doc/release_notes/rake-0.8.3.rdoc +0 -112
  72. data/doc/release_notes/rake-0.8.4.rdoc +0 -147
  73. data/doc/release_notes/rake-0.8.5.rdoc +0 -53
  74. data/doc/release_notes/rake-0.8.6.rdoc +0 -37
  75. data/doc/release_notes/rake-0.8.7.rdoc +0 -55
  76. data/doc/release_notes/rake-0.9.0.rdoc +0 -112
  77. data/doc/release_notes/rake-0.9.1.rdoc +0 -52
  78. data/doc/release_notes/rake-0.9.2.2.rdoc +0 -55
  79. data/doc/release_notes/rake-0.9.2.rdoc +0 -49
  80. data/doc/release_notes/rake-0.9.3.rdoc +0 -102
  81. data/doc/release_notes/rake-0.9.4.rdoc +0 -60
  82. data/doc/release_notes/rake-0.9.5.rdoc +0 -55
  83. data/doc/release_notes/rake-0.9.6.rdoc +0 -64
  84. data/doc/release_notes/rake-10.0.0.rdoc +0 -178
  85. data/doc/release_notes/rake-10.0.1.rdoc +0 -58
  86. data/doc/release_notes/rake-10.0.2.rdoc +0 -53
  87. data/doc/release_notes/rake-10.0.3.rdoc +0 -191
  88. data/doc/release_notes/rake-10.1.0.rdoc +0 -61
  89. data/lib/rake/alt_system.rb +0 -110
  90. data/lib/rake/contrib/.document +0 -1
  91. data/lib/rake/contrib/compositepublisher.rb +0 -21
  92. data/lib/rake/contrib/ftptools.rb +0 -137
  93. data/lib/rake/contrib/publisher.rb +0 -81
  94. data/lib/rake/contrib/rubyforgepublisher.rb +0 -18
  95. data/lib/rake/contrib/sshpublisher.rb +0 -61
  96. data/lib/rake/contrib/sys.rb +0 -4
  97. data/lib/rake/ext/module.rb +0 -2
  98. data/lib/rake/ext/pathname.rb +0 -25
  99. data/lib/rake/ext/time.rb +0 -18
  100. data/lib/rake/gempackagetask.rb +0 -4
  101. data/lib/rake/pathmap.rb +0 -3
  102. data/lib/rake/rdoctask.rb +0 -4
  103. data/lib/rake/ruby182_test_unit_fix.rb +0 -29
  104. data/lib/rake/runtest.rb +0 -27
  105. data/rakelib/publish.rake +0 -20
  106. data/rakelib/test_times.rake +0 -25
  107. data/test/file_creation.rb +0 -34
  108. data/test/helper.rb +0 -129
  109. data/test/support/rakefile_definitions.rb +0 -478
  110. data/test/support/ruby_runner.rb +0 -34
  111. data/test/test_private_reader.rb +0 -42
  112. data/test/test_rake.rb +0 -40
  113. data/test/test_rake_application.rb +0 -643
  114. data/test/test_rake_application_options.rb +0 -468
  115. data/test/test_rake_backtrace.rb +0 -119
  116. data/test/test_rake_clean.rb +0 -61
  117. data/test/test_rake_cpu_counter.rb +0 -68
  118. data/test/test_rake_definitions.rb +0 -84
  119. data/test/test_rake_directory_task.rb +0 -76
  120. data/test/test_rake_dsl.rb +0 -40
  121. data/test/test_rake_early_time.rb +0 -31
  122. data/test/test_rake_extension.rb +0 -59
  123. data/test/test_rake_file_creation_task.rb +0 -56
  124. data/test/test_rake_file_list.rb +0 -670
  125. data/test/test_rake_file_list_path_map.rb +0 -8
  126. data/test/test_rake_file_task.rb +0 -197
  127. data/test/test_rake_file_utils.rb +0 -314
  128. data/test/test_rake_ftp_file.rb +0 -74
  129. data/test/test_rake_functional.rb +0 -482
  130. data/test/test_rake_invocation_chain.rb +0 -64
  131. data/test/test_rake_late_time.rb +0 -18
  132. data/test/test_rake_linked_list.rb +0 -84
  133. data/test/test_rake_makefile_loader.rb +0 -46
  134. data/test/test_rake_multi_task.rb +0 -64
  135. data/test/test_rake_name_space.rb +0 -57
  136. data/test/test_rake_package_task.rb +0 -79
  137. data/test/test_rake_path_map.rb +0 -168
  138. data/test/test_rake_path_map_explode.rb +0 -34
  139. data/test/test_rake_path_map_partial.rb +0 -18
  140. data/test/test_rake_pathname_extensions.rb +0 -15
  141. data/test/test_rake_pseudo_status.rb +0 -21
  142. data/test/test_rake_rake_test_loader.rb +0 -20
  143. data/test/test_rake_reduce_compat.rb +0 -26
  144. data/test/test_rake_require.rb +0 -40
  145. data/test/test_rake_rules.rb +0 -388
  146. data/test/test_rake_scope.rb +0 -44
  147. data/test/test_rake_task.rb +0 -393
  148. data/test/test_rake_task_argument_parsing.rb +0 -119
  149. data/test/test_rake_task_arguments.rb +0 -127
  150. data/test/test_rake_task_lib.rb +0 -9
  151. data/test/test_rake_task_manager.rb +0 -178
  152. data/test/test_rake_task_manager_argument_resolution.rb +0 -19
  153. data/test/test_rake_task_with_arguments.rb +0 -172
  154. data/test/test_rake_test_task.rb +0 -146
  155. data/test/test_rake_thread_pool.rb +0 -145
  156. data/test/test_rake_top_level_functions.rb +0 -71
  157. data/test/test_rake_win32.rb +0 -72
  158. data/test/test_thread_history_display.rb +0 -101
  159. data/test/test_trace_output.rb +0 -52
data/lib/rake/task.rb CHANGED
@@ -1,4 +1,5 @@
1
- require 'rake/invocation_exception_mixin'
1
+ # frozen_string_literal: true
2
+ require "rake/invocation_exception_mixin"
2
3
 
3
4
  module Rake
4
5
 
@@ -14,6 +15,10 @@ module Rake
14
15
  class Task
15
16
  # List of prerequisites for a task.
16
17
  attr_reader :prerequisites
18
+ alias prereqs prerequisites
19
+
20
+ # List of order only prerequisites for a task.
21
+ attr_reader :order_only_prerequisites
17
22
 
18
23
  # List of actions attached to a task.
19
24
  attr_reader :actions
@@ -29,6 +34,10 @@ module Rake
29
34
  # location option set).
30
35
  attr_reader :locations
31
36
 
37
+ # Has this task already been invoked? Already invoked tasks
38
+ # will be skipped unless you reenable them.
39
+ attr_reader :already_invoked
40
+
32
41
  # Return task name
33
42
  def to_s
34
43
  name
@@ -50,11 +59,15 @@ module Rake
50
59
 
51
60
  # List of prerequisite tasks
52
61
  def prerequisite_tasks
53
- prerequisites.map { |pre| lookup_prerequisite(pre) }
62
+ (prerequisites + order_only_prerequisites).map { |pre| lookup_prerequisite(pre) }
54
63
  end
55
64
 
56
65
  def lookup_prerequisite(prerequisite_name) # :nodoc:
57
- application[prerequisite_name, @scope]
66
+ scoped_prerequisite_task = application[prerequisite_name, @scope]
67
+ if scoped_prerequisite_task == self
68
+ unscoped_prerequisite_task = application[prerequisite_name]
69
+ end
70
+ unscoped_prerequisite_task || scoped_prerequisite_task
58
71
  end
59
72
  private :lookup_prerequisite
60
73
 
@@ -94,6 +107,8 @@ module Rake
94
107
  @scope = app.current_scope
95
108
  @arg_names = nil
96
109
  @locations = []
110
+ @invocation_exception = nil
111
+ @order_only_prerequisites = []
97
112
  end
98
113
 
99
114
  # Enhance a task with prerequisites or actions. Returns self.
@@ -131,13 +146,15 @@ module Rake
131
146
  # is invoked again.
132
147
  def reenable
133
148
  @already_invoked = false
149
+ @invocation_exception = nil
134
150
  end
135
151
 
136
- # Clear the existing prerequisites and actions of a rake task.
152
+ # Clear the existing prerequisites, actions, comments, and arguments of a rake task.
137
153
  def clear
138
154
  clear_prerequisites
139
155
  clear_actions
140
156
  clear_comments
157
+ clear_args
141
158
  self
142
159
  end
143
160
 
@@ -159,6 +176,12 @@ module Rake
159
176
  self
160
177
  end
161
178
 
179
+ # Clear the existing arguments on a rake task.
180
+ def clear_args
181
+ @arg_names = nil
182
+ self
183
+ end
184
+
162
185
  # Invoke the task if it is needed. Prerequisites are invoked first.
163
186
  def invoke(*args)
164
187
  task_args = TaskArguments.new(arg_names, args)
@@ -167,20 +190,39 @@ module Rake
167
190
 
168
191
  # Same as invoke, but explicitly pass a call chain to detect
169
192
  # circular dependencies.
170
- def invoke_with_call_chain(task_args, invocation_chain) # :nodoc:
171
- new_chain = InvocationChain.append(self, invocation_chain)
193
+ #
194
+ # If multiple tasks depend on this
195
+ # one in parallel, they will all fail if the first execution of
196
+ # this task fails.
197
+ def invoke_with_call_chain(task_args, invocation_chain)
198
+ new_chain = Rake::InvocationChain.append(self, invocation_chain)
172
199
  @lock.synchronize do
173
- if application.options.trace
174
- application.trace "** Invoke #{name} #{format_trace_flags}"
200
+ begin
201
+ if application.options.trace
202
+ application.trace "** Invoke #{name} #{format_trace_flags}"
203
+ end
204
+
205
+ if @already_invoked
206
+ if @invocation_exception
207
+ if application.options.trace
208
+ application.trace "** Previous invocation of #{name} failed #{format_trace_flags}"
209
+ end
210
+ raise @invocation_exception
211
+ else
212
+ return
213
+ end
214
+ end
215
+
216
+ @already_invoked = true
217
+
218
+ invoke_prerequisites(task_args, new_chain)
219
+ execute(task_args) if needed?
220
+ rescue Exception => ex
221
+ add_chain_to(ex, new_chain)
222
+ @invocation_exception = ex
223
+ raise ex
175
224
  end
176
- return if @already_invoked
177
- @already_invoked = true
178
- invoke_prerequisites(task_args, new_chain)
179
- execute(task_args) if needed?
180
225
  end
181
- rescue Exception => ex
182
- add_chain_to(ex, new_chain)
183
- raise ex
184
226
  end
185
227
  protected :invoke_with_call_chain
186
228
 
@@ -211,7 +253,8 @@ module Rake
211
253
  r.invoke_with_call_chain(prereq_args, invocation_chain)
212
254
  end
213
255
  end
214
- futures.each { |f| f.value }
256
+ # Iterate in reverse to improve performance related to thread waiting and switching
257
+ futures.reverse_each(&:value)
215
258
  end
216
259
 
217
260
  # Format the trace flags for display.
@@ -232,13 +275,10 @@ module Rake
232
275
  end
233
276
  application.trace "** Execute #{name}" if application.options.trace
234
277
  application.enhance_with_matching_rule(name) if @actions.empty?
235
- @actions.each do |act|
236
- case act.arity
237
- when 1
238
- act.call(self)
239
- else
240
- act.call(self, args)
241
- end
278
+ if opts = Hash.try_convert(args) and !opts.empty?
279
+ @actions.each { |act| act.call(self, args, **opts) }
280
+ else
281
+ @actions.each { |act| act.call(self, args) }
242
282
  end
243
283
  end
244
284
 
@@ -258,7 +298,7 @@ module Rake
258
298
  def add_description(description)
259
299
  return unless description
260
300
  comment = description.strip
261
- add_comment(comment) if comment && ! comment.empty?
301
+ add_comment(comment) if comment && !comment.empty?
262
302
  end
263
303
 
264
304
  def comment=(comment) # :nodoc:
@@ -296,23 +336,23 @@ module Rake
296
336
  private :transform_comments
297
337
 
298
338
  # Get the first sentence in a string. The sentence is terminated
299
- # by the first period or the end of the line. Decimal points do
300
- # not count as periods.
339
+ # by the first period, exclamation mark, or the end of the line.
340
+ # Decimal points do not count as periods.
301
341
  def first_sentence(string)
302
- string.split(/\.[ \t]|\.$|\n/).first
342
+ string.split(/(?<=\w)(\.|!)[ \t]|(\.$|!)|\n/).first
303
343
  end
304
344
  private :first_sentence
305
345
 
306
346
  # Set the names of the arguments for this task. +args+ should be
307
347
  # an array of symbols, one for each argument name.
308
348
  def set_arg_names(args)
309
- @arg_names = args.map { |a| a.to_sym }
349
+ @arg_names = args.map(&:to_sym)
310
350
  end
311
351
 
312
352
  # Return a string describing the internal state of a task. Useful for
313
353
  # debugging.
314
354
  def investigation
315
- result = "------------------------------\n"
355
+ result = "------------------------------\n".dup
316
356
  result << "Investigating #{name}\n"
317
357
  result << "class: #{self.class}\n"
318
358
  result << "task needed: #{needed?}\n"
@@ -323,12 +363,24 @@ module Rake
323
363
  prereqs.each do |p|
324
364
  result << "--#{p.name} (#{p.timestamp})\n"
325
365
  end
326
- latest_prereq = prerequisite_tasks.map { |pre| pre.timestamp }.max
366
+ latest_prereq = prerequisite_tasks.map(&:timestamp).max
327
367
  result << "latest-prerequisite time: #{latest_prereq}\n"
328
368
  result << "................................\n\n"
329
369
  return result
330
370
  end
331
371
 
372
+ # Format dependencies parameter to pass to task.
373
+ def self.format_deps(deps)
374
+ deps = [deps] unless deps.respond_to?(:to_ary)
375
+ deps.map { |d| Rake.from_pathname(d).to_s }
376
+ end
377
+
378
+ # Add order only dependencies.
379
+ def |(deps)
380
+ @order_only_prerequisites |= Task.format_deps(deps) - @prerequisites
381
+ self
382
+ end
383
+
332
384
  # ----------------------------------------------------------------
333
385
  # Rake Module Methods
334
386
  #
@@ -374,7 +426,6 @@ module Rake
374
426
  # this kind of task. Generic tasks will accept the scope as
375
427
  # part of the name.
376
428
  def scope_name(scope, task_name)
377
- # (scope + [task_name]).join(':')
378
429
  scope.path_with_task_name(task_name)
379
430
  end
380
431
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Rake
2
3
 
3
4
  # Error indicating an ill-formed task declaration.
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Rake
2
3
 
3
4
  ##
@@ -17,7 +18,8 @@ module Rake
17
18
  @hash = {}
18
19
  @values = values
19
20
  names.each_with_index { |name, i|
20
- @hash[name.to_sym] = values[i] unless values[i].nil?
21
+ next if values[i].nil? || values[i] == ""
22
+ @hash[name.to_sym] = values[i]
21
23
  }
22
24
  end
23
25
 
@@ -67,21 +69,30 @@ module Rake
67
69
 
68
70
  # Returns a Hash of arguments and their values
69
71
  def to_hash
70
- @hash
72
+ @hash.dup
71
73
  end
72
74
 
73
75
  def to_s # :nodoc:
74
- @hash.inspect
76
+ inspect
75
77
  end
76
78
 
77
79
  def inspect # :nodoc:
78
- to_s
80
+ inspection = @hash.map do |k,v|
81
+ "#{k.to_s}: #{v.to_s}"
82
+ end.join(", ")
83
+
84
+ "#<#{self.class} #{inspection}>"
79
85
  end
80
86
 
81
87
  # Returns true if +key+ is one of the arguments
82
88
  def has_key?(key)
83
89
  @hash.has_key?(key)
84
90
  end
91
+ alias key? has_key?
92
+
93
+ def fetch(*args, &block)
94
+ @hash.fetch(*args, &block)
95
+ end
85
96
 
86
97
  protected
87
98
 
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Rake
2
3
 
3
4
  # The TaskManager module is a mixin for managing tasks.
@@ -5,10 +6,6 @@ module Rake
5
6
  # Track the last comment made in the Rakefile.
6
7
  attr_accessor :last_description
7
8
 
8
- # TODO: Remove in Rake 11
9
-
10
- alias :last_comment :last_description # :nodoc: Backwards compatibility
11
-
12
9
  def initialize # :nodoc:
13
10
  super
14
11
  @tasks = Hash.new
@@ -18,31 +15,31 @@ module Rake
18
15
  end
19
16
 
20
17
  def create_rule(*args, &block) # :nodoc:
21
- pattern, args, deps = resolve_args(args)
22
- pattern = Regexp.new(Regexp.quote(pattern) + '$') if String === pattern
23
- @rules << [pattern, args, deps, block]
18
+ pattern, args, deps, order_only = resolve_args(args)
19
+ pattern = Regexp.new(Regexp.quote(pattern) + "$") if String === pattern
20
+ @rules << [pattern, args, deps, order_only, block]
24
21
  end
25
22
 
26
23
  def define_task(task_class, *args, &block) # :nodoc:
27
- task_name, arg_names, deps = resolve_args(args)
24
+ task_name, arg_names, deps, order_only = resolve_args(args)
28
25
 
29
26
  original_scope = @scope
30
27
  if String === task_name and
31
- not task_class.ancestors.include? Rake::FileTask then
28
+ not task_class.ancestors.include? Rake::FileTask
32
29
  task_name, *definition_scope = *(task_name.split(":").reverse)
33
30
  @scope = Scope.make(*(definition_scope + @scope.to_a))
34
31
  end
35
32
 
36
33
  task_name = task_class.scope_name(@scope, task_name)
37
- deps = [deps] unless deps.respond_to?(:to_ary)
38
- deps = deps.map { |d| Rake.from_pathname(d).to_s }
39
34
  task = intern(task_class, task_name)
40
35
  task.set_arg_names(arg_names) unless arg_names.empty?
41
36
  if Rake::TaskManager.record_task_metadata
42
37
  add_location(task)
43
38
  task.add_description(get_description(task))
44
39
  end
45
- task.enhance(deps, &block)
40
+ task.enhance(Task.format_deps(deps), &block)
41
+ task | order_only unless order_only.nil?
42
+ task
46
43
  ensure
47
44
  @scope = original_scope
48
45
  end
@@ -59,7 +56,26 @@ module Rake
59
56
  self.lookup(task_name, scopes) or
60
57
  enhance_with_matching_rule(task_name) or
61
58
  synthesize_file_task(task_name) or
62
- fail "Don't know how to build task '#{task_name}' (see --tasks)"
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
63
79
  end
64
80
 
65
81
  def synthesize_file_task(task_name) # :nodoc:
@@ -67,8 +83,8 @@ module Rake
67
83
  define_task(Rake::FileTask, task_name)
68
84
  end
69
85
 
70
- # Resolve the arguments for a task/rule. Returns a triplet of
71
- # [task_name, arg_name_list, prerequisites].
86
+ # Resolve the arguments for a task/rule. Returns a tuple of
87
+ # [task_name, arg_name_list, prerequisites, order_only_prerequisites].
72
88
  def resolve_args(args)
73
89
  if args.last.is_a?(Hash)
74
90
  deps = args.pop
@@ -93,7 +109,7 @@ module Rake
93
109
  else
94
110
  arg_names = args
95
111
  end
96
- [task_name, arg_names, []]
112
+ [task_name, arg_names, [], nil]
97
113
  end
98
114
  private :resolve_args_without_dependencies
99
115
 
@@ -102,11 +118,17 @@ module Rake
102
118
  #
103
119
  # The patterns recognized by this argument resolving function are:
104
120
  #
121
+ # task :t, order_only: [:e]
105
122
  # task :t => [:d]
123
+ # task :t => [:d], order_only: [:e]
106
124
  # task :t, [a] => [:d]
125
+ # task :t, [a] => [:d], order_only: [:e]
107
126
  #
108
127
  def resolve_args_with_dependencies(args, hash) # :nodoc:
109
- fail "Task Argument Error" if hash.size != 1
128
+ fail "Task Argument Error" if
129
+ hash.size != 1 &&
130
+ (hash.size != 2 || !hash.key?(:order_only))
131
+ order_only = hash.delete(:order_only)
110
132
  key, value = hash.map { |k, v| [k, v] }.first
111
133
  if args.empty?
112
134
  task_name = key
@@ -114,11 +136,11 @@ module Rake
114
136
  deps = value || []
115
137
  else
116
138
  task_name = args.shift
117
- arg_names = key
118
- deps = value
139
+ arg_names = key || args.shift|| []
140
+ deps = value || []
119
141
  end
120
142
  deps = [deps] unless deps.respond_to?(:to_ary)
121
- [task_name, arg_names, deps]
143
+ [task_name, arg_names, deps, order_only]
122
144
  end
123
145
  private :resolve_args_with_dependencies
124
146
 
@@ -129,9 +151,10 @@ module Rake
129
151
  def enhance_with_matching_rule(task_name, level=0)
130
152
  fail Rake::RuleRecursionOverflowError,
131
153
  "Rule Recursion Too Deep" if level >= 16
132
- @rules.each do |pattern, args, extensions, block|
133
- if pattern.match(task_name)
134
- task = attempt_rule(task_name, args, extensions, block, level)
154
+ @rules.each do |pattern, args, extensions, order_only, block|
155
+ if pattern && pattern.match(task_name)
156
+ task = attempt_rule(task_name, pattern, args, extensions, block, level)
157
+ task | order_only unless order_only.nil?
135
158
  return task if task
136
159
  end
137
160
  end
@@ -171,10 +194,10 @@ module Rake
171
194
  task_name = task_name.to_s
172
195
  if task_name =~ /^rake:/
173
196
  scopes = Scope.make
174
- task_name = task_name.sub(/^rake:/, '')
197
+ task_name = task_name.sub(/^rake:/, "")
175
198
  elsif task_name =~ /^(\^+)/
176
199
  scopes = initial_scope.trim($1.size)
177
- task_name = task_name.sub(/^(\^+)/, '')
200
+ task_name = task_name.sub(/^(\^+)/, "")
178
201
  else
179
202
  scopes = initial_scope
180
203
  end
@@ -245,8 +268,8 @@ module Rake
245
268
  end
246
269
 
247
270
  # Attempt to create a rule given the list of prerequisites.
248
- def attempt_rule(task_name, args, extensions, block, level)
249
- sources = make_sources(task_name, extensions)
271
+ def attempt_rule(task_name, task_pattern, args, extensions, block, level)
272
+ sources = make_sources(task_name, task_pattern, extensions)
250
273
  prereqs = sources.map { |source|
251
274
  trace_rule level, "Attempting Rule #{task_name} => #{source}"
252
275
  if File.exist?(source) || Rake::Task.task_defined?(source)
@@ -260,14 +283,14 @@ module Rake
260
283
  return nil
261
284
  end
262
285
  }
263
- task = FileTask.define_task(task_name, {args => prereqs}, &block)
286
+ task = FileTask.define_task(task_name, { args => prereqs }, &block)
264
287
  task.sources = prereqs
265
288
  task
266
289
  end
267
290
 
268
291
  # Make a list of sources from the list of file name extensions /
269
292
  # translation procs.
270
- def make_sources(task_name, extensions)
293
+ def make_sources(task_name, task_pattern, extensions)
271
294
  result = extensions.map { |ext|
272
295
  case ext
273
296
  when /%/
@@ -275,9 +298,10 @@ module Rake
275
298
  when %r{/}
276
299
  ext
277
300
  when /^\./
278
- task_name.ext(ext)
279
- when String
280
- ext
301
+ source = task_name.sub(task_pattern, ext)
302
+ source == ext ? task_name.ext(ext) : source
303
+ when String, Symbol
304
+ ext.to_s
281
305
  when Proc, Method
282
306
  if ext.arity == 1
283
307
  ext.call(task_name)
data/lib/rake/tasklib.rb CHANGED
@@ -1,4 +1,5 @@
1
- require 'rake'
1
+ # frozen_string_literal: true
2
+ require "rake"
2
3
 
3
4
  module Rake
4
5
 
@@ -6,19 +7,6 @@ module Rake
6
7
  class TaskLib
7
8
  include Cloneable
8
9
  include Rake::DSL
9
-
10
- # Make a symbol by pasting two strings together.
11
- #
12
- # NOTE: DEPRECATED! This method is kinda stupid. I don't know why
13
- # I didn't just use string interpolation. But now other task
14
- # libraries depend on this so I can't remove it without breaking
15
- # other people's code. So for now it stays for backwards
16
- # compatibility. BUT DON'T USE IT.
17
- #--
18
- # TODO: Remove in Rake 11
19
- def paste(a, b) # :nodoc:
20
- (a.to_s + b.to_s).intern
21
- end
22
10
  end
23
11
 
24
12
  end
data/lib/rake/testtask.rb CHANGED
@@ -1,5 +1,6 @@
1
- require 'rake'
2
- require 'rake/tasklib'
1
+ # frozen_string_literal: true
2
+ require "rake"
3
+ require "rake/tasklib"
3
4
 
4
5
  module Rake
5
6
 
@@ -50,6 +51,7 @@ module Rake
50
51
 
51
52
  # Request that the tests be run with the warning flag set.
52
53
  # E.g. warning=true implies "ruby -w" used to run the tests.
54
+ # (default is true)
53
55
  attr_accessor :warning
54
56
 
55
57
  # Glob pattern to match test files. (default is 'test/test*.rb')
@@ -69,6 +71,9 @@ module Rake
69
71
  # Description of the test task. (default is 'Run tests')
70
72
  attr_accessor :description
71
73
 
74
+ # Task prerequisites.
75
+ attr_accessor :deps
76
+
72
77
  # Explicitly define the list of test files to be included in a
73
78
  # test. +list+ is expected to be an array of file names (a
74
79
  # FileList is acceptable). If both +pattern+ and +test_files+ are
@@ -85,20 +90,27 @@ module Rake
85
90
  @options = nil
86
91
  @test_files = nil
87
92
  @verbose = false
88
- @warning = false
93
+ @warning = true
89
94
  @loader = :rake
90
95
  @ruby_opts = []
91
96
  @description = "Run tests" + (@name == :test ? "" : " for #{@name}")
97
+ @deps = []
98
+ if @name.is_a?(Hash)
99
+ @deps = @name.values.first
100
+ @name = @name.keys.first
101
+ end
92
102
  yield self if block_given?
93
- @pattern = 'test/test*.rb' if @pattern.nil? && @test_files.nil?
103
+ @pattern = "test/test*.rb" if @pattern.nil? && @test_files.nil?
94
104
  define
95
105
  end
96
106
 
97
107
  # Create the tasks defined by this task lib.
98
108
  def define
99
109
  desc @description
100
- task @name do
110
+ task @name => Array(deps) do
101
111
  FileUtilsExt.verbose(@verbose) do
112
+ puts "Use TESTOPTS=\"--verbose\" to pass --verbose" \
113
+ ", etc. to runners." if ARGV.include? "--verbose"
102
114
  args =
103
115
  "#{ruby_opts_string} #{run_code} " +
104
116
  "#{file_list_string} #{option_list}"
@@ -106,8 +118,16 @@ module Rake
106
118
  if !ok && status.respond_to?(:signaled?) && status.signaled?
107
119
  raise SignalException.new(status.termsig)
108
120
  elsif !ok
109
- fail "Command failed with status (#{status.exitstatus}): " +
110
- "[ruby #{args}]"
121
+ status = "Command failed with status (#{status.exitstatus})"
122
+ details = ": [ruby #{args}]"
123
+ message =
124
+ if Rake.application.options.trace or @verbose
125
+ status + details
126
+ else
127
+ status
128
+ end
129
+
130
+ fail message
111
131
  end
112
132
  end
113
133
  end
@@ -116,10 +136,10 @@ module Rake
116
136
  end
117
137
 
118
138
  def option_list # :nodoc:
119
- (ENV['TESTOPTS'] ||
120
- ENV['TESTOPT'] ||
121
- ENV['TEST_OPTS'] ||
122
- ENV['TEST_OPT'] ||
139
+ (ENV["TESTOPTS"] ||
140
+ ENV["TESTOPT"] ||
141
+ ENV["TEST_OPTS"] ||
142
+ ENV["TEST_OPT"] ||
123
143
  @options ||
124
144
  "")
125
145
  end
@@ -136,29 +156,20 @@ module Rake
136
156
  end
137
157
 
138
158
  def file_list_string # :nodoc:
139
- file_list.map { |fn| "\"#{fn}\"" }.join(' ')
159
+ file_list.map { |fn| "\"#{fn}\"" }.join(" ")
140
160
  end
141
161
 
142
162
  def file_list # :nodoc:
143
- if ENV['TEST']
144
- FileList[ENV['TEST']]
163
+ if ENV["TEST"]
164
+ FileList[ENV["TEST"]]
145
165
  else
146
166
  result = []
147
167
  result += @test_files.to_a if @test_files
148
- result << @pattern if @pattern
168
+ result += FileList[@pattern].to_a if @pattern
149
169
  result
150
170
  end
151
171
  end
152
172
 
153
- def fix # :nodoc:
154
- case ruby_version
155
- when '1.8.2'
156
- "\"#{find_file 'rake/ruby182_test_unit_fix'}\""
157
- else
158
- nil
159
- end || ''
160
- end
161
-
162
173
  def ruby_version # :nodoc:
163
174
  RUBY_VERSION
164
175
  end
@@ -168,45 +179,10 @@ module Rake
168
179
  when :direct
169
180
  "-e \"ARGV.each{|f| require f}\""
170
181
  when :testrb
171
- "-S testrb #{fix}"
182
+ "-S testrb"
172
183
  when :rake
173
- "#{rake_include_arg} \"#{rake_loader}\""
174
- end
175
- end
176
-
177
- def rake_loader # :nodoc:
178
- find_file('rake/rake_test_loader') or
179
- fail "unable to find rake test loader"
180
- end
181
-
182
- def find_file(fn) # :nodoc:
183
- $LOAD_PATH.each do |path|
184
- file_path = File.join(path, "#{fn}.rb")
185
- return file_path if File.exist? file_path
186
- end
187
- nil
188
- end
189
-
190
- def rake_include_arg # :nodoc:
191
- spec = Gem.loaded_specs['rake']
192
- if spec.respond_to?(:default_gem?) && spec.default_gem?
193
- ""
194
- else
195
- "-I\"#{rake_lib_dir}\""
196
- end
197
- end
198
-
199
- def rake_lib_dir # :nodoc:
200
- find_dir('rake') or
201
- fail "unable to find rake lib"
202
- end
203
-
204
- def find_dir(fn) # :nodoc:
205
- $LOAD_PATH.each do |path|
206
- file_path = File.join(path, "#{fn}.rb")
207
- return path if File.exist? file_path
184
+ "#{__dir__}/rake_test_loader.rb"
208
185
  end
209
- nil
210
186
  end
211
187
 
212
188
  end