podoy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +35 -0
  4. data/Rakefile +4 -0
  5. data/lib/podoy/version.rb +5 -0
  6. data/lib/podoy.rb +8 -0
  7. data/sig/podoy.rbs +4 -0
  8. data/vendor/bundle/ruby/3.3.0+0/bin/rake +29 -0
  9. data/vendor/bundle/ruby/3.3.0+0/cache/rake-13.1.0.gem +0 -0
  10. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/History.rdoc +2403 -0
  11. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/MIT-LICENSE +21 -0
  12. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/README.rdoc +155 -0
  13. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/command_line_usage.rdoc +158 -0
  14. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/example/Rakefile1 +38 -0
  15. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/example/Rakefile2 +35 -0
  16. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/example/a.c +6 -0
  17. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/example/b.c +6 -0
  18. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/example/main.c +11 -0
  19. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/glossary.rdoc +42 -0
  20. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/jamis.rb +592 -0
  21. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/proto_rake.rdoc +127 -0
  22. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/rake.1 +156 -0
  23. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/rakefile.rdoc +622 -0
  24. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/doc/rational.rdoc +151 -0
  25. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/exe/rake +27 -0
  26. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/application.rb +855 -0
  27. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/backtrace.rb +24 -0
  28. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/clean.rb +78 -0
  29. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/cloneable.rb +17 -0
  30. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/cpu_counter.rb +107 -0
  31. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/default_loader.rb +15 -0
  32. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/dsl_definition.rb +195 -0
  33. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/early_time.rb +22 -0
  34. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/ext/core.rb +26 -0
  35. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/ext/string.rb +176 -0
  36. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/file_creation_task.rb +25 -0
  37. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/file_list.rb +435 -0
  38. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/file_task.rb +58 -0
  39. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/file_utils.rb +132 -0
  40. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/file_utils_ext.rb +134 -0
  41. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/invocation_chain.rb +57 -0
  42. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/invocation_exception_mixin.rb +17 -0
  43. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/late_time.rb +18 -0
  44. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/linked_list.rb +112 -0
  45. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/loaders/makefile.rb +54 -0
  46. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/multi_task.rb +14 -0
  47. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/name_space.rb +38 -0
  48. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/packagetask.rb +222 -0
  49. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/phony.rb +16 -0
  50. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/private_reader.rb +21 -0
  51. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/promise.rb +100 -0
  52. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/pseudo_status.rb +30 -0
  53. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/rake_module.rb +67 -0
  54. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/rake_test_loader.rb +27 -0
  55. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/rule_recursion_overflow_error.rb +20 -0
  56. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/scope.rb +43 -0
  57. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/task.rb +434 -0
  58. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/task_argument_error.rb +8 -0
  59. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/task_arguments.rb +109 -0
  60. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/task_manager.rb +331 -0
  61. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/tasklib.rb +12 -0
  62. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/testtask.rb +189 -0
  63. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/thread_history_display.rb +49 -0
  64. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/thread_pool.rb +163 -0
  65. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/trace_output.rb +23 -0
  66. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/version.rb +10 -0
  67. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake/win32.rb +51 -0
  68. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/lib/rake.rb +71 -0
  69. data/vendor/bundle/ruby/3.3.0+0/gems/rake-13.1.0/rake.gemspec +101 -0
  70. data/vendor/bundle/ruby/3.3.0+0/specifications/rake-13.1.0.gemspec +26 -0
  71. metadata +117 -0
@@ -0,0 +1,855 @@
1
+ # frozen_string_literal: true
2
+ require "optparse"
3
+
4
+ require "rake/task_manager"
5
+ require "rake/file_list"
6
+ require "rake/thread_pool"
7
+ require "rake/thread_history_display"
8
+ require "rake/trace_output"
9
+ require "rake/win32"
10
+
11
+ module Rake
12
+
13
+ CommandLineOptionError = Class.new(StandardError)
14
+
15
+ ##
16
+ # Rake main application object. When invoking +rake+ from the
17
+ # command line, a Rake::Application object is created and run.
18
+
19
+ class Application
20
+ include TaskManager
21
+ include TraceOutput
22
+
23
+ # The name of the application (typically 'rake')
24
+ attr_reader :name
25
+
26
+ # The original directory where rake was invoked.
27
+ attr_reader :original_dir
28
+
29
+ # Name of the actual rakefile used.
30
+ attr_reader :rakefile
31
+
32
+ # Number of columns on the terminal
33
+ attr_accessor :terminal_columns
34
+
35
+ # List of the top level task names (task names from the command line).
36
+ attr_reader :top_level_tasks
37
+
38
+ # Override the detected TTY output state (mostly for testing)
39
+ attr_writer :tty_output
40
+
41
+ DEFAULT_RAKEFILES = [
42
+ "rakefile",
43
+ "Rakefile",
44
+ "rakefile.rb",
45
+ "Rakefile.rb"
46
+ ].freeze
47
+
48
+ # Initialize a Rake::Application object.
49
+ def initialize
50
+ super
51
+ @name = "rake"
52
+ @rakefiles = DEFAULT_RAKEFILES.dup
53
+ @rakefile = nil
54
+ @pending_imports = []
55
+ @imported = []
56
+ @loaders = {}
57
+ @default_loader = Rake::DefaultLoader.new
58
+ @original_dir = Dir.pwd
59
+ @top_level_tasks = []
60
+ add_loader("rb", DefaultLoader.new)
61
+ add_loader("rf", DefaultLoader.new)
62
+ add_loader("rake", DefaultLoader.new)
63
+ @tty_output = STDOUT.tty?
64
+ @terminal_columns = ENV["RAKE_COLUMNS"].to_i
65
+
66
+ set_default_options
67
+ end
68
+
69
+ # Run the Rake application. The run method performs the following
70
+ # three steps:
71
+ #
72
+ # * Initialize the command line options (+init+).
73
+ # * Define the tasks (+load_rakefile+).
74
+ # * Run the top level tasks (+top_level+).
75
+ #
76
+ # If you wish to build a custom rake command, you should call
77
+ # +init+ on your application. Then define any tasks. Finally,
78
+ # call +top_level+ to run your top level tasks.
79
+ def run(argv = ARGV)
80
+ standard_exception_handling do
81
+ init "rake", argv
82
+ load_rakefile
83
+ top_level
84
+ end
85
+ end
86
+
87
+ # Initialize the command line parameters and app name.
88
+ def init(app_name="rake", argv = ARGV)
89
+ standard_exception_handling do
90
+ @name = app_name
91
+ begin
92
+ args = handle_options argv
93
+ rescue ArgumentError
94
+ # Backward compatibility for capistrano
95
+ args = handle_options
96
+ end
97
+ load_debug_at_stop_feature
98
+ collect_command_line_tasks(args)
99
+ end
100
+ end
101
+
102
+ def load_debug_at_stop_feature
103
+ return unless ENV["RAKE_DEBUG"]
104
+ require "debug/session"
105
+ DEBUGGER__::start no_sigint_hook: true, nonstop: true
106
+ Rake::Task.prepend Module.new {
107
+ def execute(*)
108
+ exception = DEBUGGER__::SESSION.capture_exception_frames(/(exe|bin|lib)\/rake/) do
109
+ super
110
+ end
111
+
112
+ if exception
113
+ STDERR.puts exception.message
114
+ DEBUGGER__::SESSION.enter_postmortem_session exception
115
+ raise exception
116
+ end
117
+ end
118
+ }
119
+ rescue LoadError
120
+ end
121
+ private :load_debug_at_stop_feature
122
+
123
+ # Find the rakefile and then load it and any pending imports.
124
+ def load_rakefile
125
+ standard_exception_handling do
126
+ raw_load_rakefile
127
+ end
128
+ end
129
+
130
+ # Run the top level tasks of a Rake application.
131
+ def top_level
132
+ run_with_threads do
133
+ if options.show_tasks
134
+ display_tasks_and_comments
135
+ elsif options.show_prereqs
136
+ display_prerequisites
137
+ else
138
+ top_level_tasks.each { |task_name| invoke_task(task_name) }
139
+ end
140
+ end
141
+ end
142
+
143
+ # Run the given block with the thread startup and shutdown.
144
+ def run_with_threads
145
+ thread_pool.gather_history if options.job_stats == :history
146
+
147
+ yield
148
+
149
+ thread_pool.join if defined?(@thread_pool)
150
+ if options.job_stats
151
+ stats = thread_pool.statistics
152
+ puts "Maximum active threads: #{stats[:max_active_threads]} + main"
153
+ puts "Total threads in play: #{stats[:total_threads_in_play]} + main"
154
+ end
155
+ ThreadHistoryDisplay.new(thread_pool.history).show if
156
+ options.job_stats == :history
157
+ end
158
+
159
+ # Add a loader to handle imported files ending in the extension
160
+ # +ext+.
161
+ def add_loader(ext, loader)
162
+ ext = ".#{ext}" unless ext =~ /^\./
163
+ @loaders[ext] = loader
164
+ end
165
+
166
+ # Application options from the command line
167
+ def options
168
+ @options ||= OpenStruct.new
169
+ end
170
+
171
+ # Return the thread pool used for multithreaded processing.
172
+ def thread_pool # :nodoc:
173
+ @thread_pool ||= ThreadPool.new(options.thread_pool_size || Rake.suggested_thread_count-1)
174
+ end
175
+
176
+ # internal ----------------------------------------------------------------
177
+
178
+ # Invokes a task with arguments that are extracted from +task_string+
179
+ def invoke_task(task_string) # :nodoc:
180
+ name, args = parse_task_string(task_string)
181
+ t = self[name]
182
+ t.invoke(*args)
183
+ end
184
+
185
+ def parse_task_string(string) # :nodoc:
186
+ /^([^\[]+)(?:\[(.*)\])$/ =~ string.to_s
187
+
188
+ name = $1
189
+ remaining_args = $2
190
+
191
+ return string, [] unless name
192
+ return name, [] if remaining_args.empty?
193
+
194
+ args = []
195
+
196
+ begin
197
+ /\s*((?:[^\\,]|\\.)*?)\s*(?:,\s*(.*))?$/ =~ remaining_args
198
+
199
+ remaining_args = $2
200
+ args << $1.gsub(/\\(.)/, '\1')
201
+ end while remaining_args
202
+
203
+ return name, args
204
+ end
205
+
206
+ # Provide standard exception handling for the given block.
207
+ def standard_exception_handling # :nodoc:
208
+ yield
209
+ rescue SystemExit
210
+ # Exit silently with current status
211
+ raise
212
+ rescue OptionParser::InvalidOption => ex
213
+ $stderr.puts ex.message
214
+ exit(false)
215
+ rescue Exception => ex
216
+ # Exit with error message
217
+ display_error_message(ex)
218
+ exit_because_of_exception(ex)
219
+ end
220
+
221
+ # Exit the program because of an unhandled exception.
222
+ # (may be overridden by subclasses)
223
+ def exit_because_of_exception(ex) # :nodoc:
224
+ exit(false)
225
+ end
226
+
227
+ # Display the error message that caused the exception.
228
+ def display_error_message(ex) # :nodoc:
229
+ trace "#{name} aborted!"
230
+ display_exception_details(ex)
231
+ trace "Tasks: #{ex.chain}" if has_chain?(ex)
232
+ trace "(See full trace by running task with --trace)" unless
233
+ options.backtrace
234
+ end
235
+
236
+ def display_exception_details(ex) # :nodoc:
237
+ display_exception_details_seen << ex
238
+
239
+ display_exception_message_details(ex)
240
+ display_exception_backtrace(ex)
241
+ display_cause_details(ex.cause) if has_cause?(ex)
242
+ end
243
+
244
+ def display_cause_details(ex) # :nodoc:
245
+ return if display_exception_details_seen.include? ex
246
+
247
+ trace "\nCaused by:"
248
+ display_exception_details(ex)
249
+ end
250
+
251
+ def display_exception_details_seen # :nodoc:
252
+ Thread.current[:rake_display_exception_details_seen] ||= []
253
+ end
254
+
255
+ def has_cause?(ex) # :nodoc:
256
+ ex.respond_to?(:cause) && ex.cause
257
+ end
258
+
259
+ def display_exception_message_details(ex) # :nodoc:
260
+ if ex.instance_of?(RuntimeError)
261
+ trace ex.message
262
+ elsif ex.respond_to?(:detailed_message)
263
+ trace "#{ex.class.name}: #{ex.detailed_message(highlight: false)}"
264
+ else
265
+ trace "#{ex.class.name}: #{ex.message}"
266
+ end
267
+ end
268
+
269
+ def display_exception_backtrace(ex) # :nodoc:
270
+ if options.backtrace
271
+ trace ex.backtrace.join("\n")
272
+ else
273
+ trace Backtrace.collapse(ex.backtrace).join("\n")
274
+ end
275
+ end
276
+
277
+ # Warn about deprecated usage.
278
+ #
279
+ # Example:
280
+ # Rake.application.deprecate("import", "Rake.import", caller.first)
281
+ #
282
+ def deprecate(old_usage, new_usage, call_site) # :nodoc:
283
+ unless options.ignore_deprecate
284
+ $stderr.puts "WARNING: '#{old_usage}' is deprecated. " +
285
+ "Please use '#{new_usage}' instead.\n" +
286
+ " at #{call_site}"
287
+ end
288
+ end
289
+
290
+ # Does the exception have a task invocation chain?
291
+ def has_chain?(exception) # :nodoc:
292
+ exception.respond_to?(:chain) && exception.chain
293
+ end
294
+ private :has_chain?
295
+
296
+ # True if one of the files in RAKEFILES is in the current directory.
297
+ # If a match is found, it is copied into @rakefile.
298
+ def have_rakefile # :nodoc:
299
+ @rakefiles.each do |fn|
300
+ if File.exist?(fn)
301
+ others = FileList.glob(fn, File::FNM_CASEFOLD)
302
+ return others.size == 1 ? others.first : fn
303
+ elsif fn == ""
304
+ return fn
305
+ end
306
+ end
307
+ return nil
308
+ end
309
+
310
+ # True if we are outputting to TTY, false otherwise
311
+ def tty_output? # :nodoc:
312
+ @tty_output
313
+ end
314
+
315
+ # We will truncate output if we are outputting to a TTY or if we've been
316
+ # given an explicit column width to honor
317
+ def truncate_output? # :nodoc:
318
+ tty_output? || @terminal_columns.nonzero?
319
+ end
320
+
321
+ # Display the tasks and comments.
322
+ def display_tasks_and_comments # :nodoc:
323
+ displayable_tasks = tasks.select { |t|
324
+ (options.show_all_tasks || t.comment) &&
325
+ t.name =~ options.show_task_pattern
326
+ }
327
+ case options.show_tasks
328
+ when :tasks
329
+ width = displayable_tasks.map { |t| t.name_with_args.length }.max || 10
330
+ if truncate_output?
331
+ max_column = terminal_width - name.size - width - 7
332
+ else
333
+ max_column = nil
334
+ end
335
+
336
+ displayable_tasks.each do |t|
337
+ printf("#{name} %-#{width}s # %s\n",
338
+ t.name_with_args,
339
+ max_column ? truncate(t.comment, max_column) : t.comment)
340
+ end
341
+ when :describe
342
+ displayable_tasks.each do |t|
343
+ puts "#{name} #{t.name_with_args}"
344
+ comment = t.full_comment || ""
345
+ comment.split("\n").each do |line|
346
+ puts " #{line}"
347
+ end
348
+ puts
349
+ end
350
+ when :lines
351
+ displayable_tasks.each do |t|
352
+ t.locations.each do |loc|
353
+ printf "#{name} %-30s %s\n", t.name_with_args, loc
354
+ end
355
+ end
356
+ else
357
+ fail "Unknown show task mode: '#{options.show_tasks}'"
358
+ end
359
+ end
360
+
361
+ def terminal_width # :nodoc:
362
+ if @terminal_columns.nonzero?
363
+ result = @terminal_columns
364
+ else
365
+ result = unix? ? dynamic_width : 80
366
+ end
367
+ (result < 10) ? 80 : result
368
+ rescue
369
+ 80
370
+ end
371
+
372
+ # Calculate the dynamic width of the
373
+ def dynamic_width # :nodoc:
374
+ @dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput)
375
+ end
376
+
377
+ def dynamic_width_stty # :nodoc:
378
+ %x{stty size 2>/dev/null}.split[1].to_i
379
+ end
380
+
381
+ def dynamic_width_tput # :nodoc:
382
+ %x{tput cols 2>/dev/null}.to_i
383
+ end
384
+
385
+ def unix? # :nodoc:
386
+ RbConfig::CONFIG["host_os"] =~
387
+ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
388
+ end
389
+
390
+ def windows? # :nodoc:
391
+ Win32.windows?
392
+ end
393
+
394
+ def truncate(string, width) # :nodoc:
395
+ if string.nil?
396
+ ""
397
+ elsif string.length <= width
398
+ string
399
+ else
400
+ (string[0, width - 3] || "") + "..."
401
+ end
402
+ end
403
+
404
+ # Display the tasks and prerequisites
405
+ def display_prerequisites # :nodoc:
406
+ tasks.each do |t|
407
+ puts "#{name} #{t.name}"
408
+ t.prerequisites.each { |pre| puts " #{pre}" }
409
+ end
410
+ end
411
+
412
+ def trace(*strings) # :nodoc:
413
+ options.trace_output ||= $stderr
414
+ trace_on(options.trace_output, *strings)
415
+ end
416
+
417
+ def sort_options(options) # :nodoc:
418
+ options.sort_by { |opt|
419
+ opt.select { |o| o.is_a?(String) && o =~ /^-/ }.map(&:downcase).sort.reverse
420
+ }
421
+ end
422
+ private :sort_options
423
+
424
+ # A list of all the standard options used in rake, suitable for
425
+ # passing to OptionParser.
426
+ def standard_rake_options # :nodoc:
427
+ sort_options(
428
+ [
429
+ ["--all", "-A",
430
+ "Show all tasks, even uncommented ones (in combination with -T or -D)",
431
+ lambda { |value|
432
+ options.show_all_tasks = value
433
+ }
434
+ ],
435
+ ["--backtrace=[OUT]",
436
+ "Enable full backtrace. OUT can be stderr (default) or stdout.",
437
+ lambda { |value|
438
+ options.backtrace = true
439
+ select_trace_output(options, "backtrace", value)
440
+ }
441
+ ],
442
+ ["--build-all", "-B",
443
+ "Build all prerequisites, including those which are up-to-date.",
444
+ lambda { |value|
445
+ options.build_all = true
446
+ }
447
+ ],
448
+ ["--comments",
449
+ "Show commented tasks only",
450
+ lambda { |value|
451
+ options.show_all_tasks = !value
452
+ }
453
+ ],
454
+ ["--describe", "-D [PATTERN]",
455
+ "Describe the tasks (matching optional PATTERN), then exit.",
456
+ lambda { |value|
457
+ select_tasks_to_show(options, :describe, value)
458
+ }
459
+ ],
460
+ ["--directory", "-C [DIRECTORY]",
461
+ "Change to DIRECTORY before doing anything.",
462
+ lambda { |value|
463
+ Dir.chdir value
464
+ @original_dir = Dir.pwd
465
+ }
466
+ ],
467
+ ["--dry-run", "-n",
468
+ "Do a dry run without executing actions.",
469
+ lambda { |value|
470
+ Rake.verbose(true)
471
+ Rake.nowrite(true)
472
+ options.dryrun = true
473
+ options.trace = true
474
+ }
475
+ ],
476
+ ["--execute", "-e CODE",
477
+ "Execute some Ruby code and exit.",
478
+ lambda { |value|
479
+ eval(value)
480
+ exit
481
+ }
482
+ ],
483
+ ["--execute-print", "-p CODE",
484
+ "Execute some Ruby code, print the result, then exit.",
485
+ lambda { |value|
486
+ puts eval(value)
487
+ exit
488
+ }
489
+ ],
490
+ ["--execute-continue", "-E CODE",
491
+ "Execute some Ruby code, " +
492
+ "then continue with normal task processing.",
493
+ lambda { |value| eval(value) }
494
+ ],
495
+ ["--jobs", "-j [NUMBER]",
496
+ "Specifies the maximum number of tasks to execute in parallel. " +
497
+ "(default is number of CPU cores + 4)",
498
+ lambda { |value|
499
+ if value.nil? || value == ""
500
+ value = Float::INFINITY
501
+ elsif value =~ /^\d+$/
502
+ value = value.to_i
503
+ else
504
+ value = Rake.suggested_thread_count
505
+ end
506
+ value = 1 if value < 1
507
+ options.thread_pool_size = value - 1
508
+ }
509
+ ],
510
+ ["--job-stats [LEVEL]",
511
+ "Display job statistics. " +
512
+ "LEVEL=history displays a complete job list",
513
+ lambda { |value|
514
+ if value =~ /^history/i
515
+ options.job_stats = :history
516
+ else
517
+ options.job_stats = true
518
+ end
519
+ }
520
+ ],
521
+ ["--libdir", "-I LIBDIR",
522
+ "Include LIBDIR in the search path for required modules.",
523
+ lambda { |value| $:.push(value) }
524
+ ],
525
+ ["--multitask", "-m",
526
+ "Treat all tasks as multitasks.",
527
+ lambda { |value| options.always_multitask = true }
528
+ ],
529
+ ["--no-search", "--nosearch",
530
+ "-N", "Do not search parent directories for the Rakefile.",
531
+ lambda { |value| options.nosearch = true }
532
+ ],
533
+ ["--prereqs", "-P",
534
+ "Display the tasks and dependencies, then exit.",
535
+ lambda { |value| options.show_prereqs = true }
536
+ ],
537
+ ["--quiet", "-q",
538
+ "Do not log messages to standard output.",
539
+ lambda { |value| Rake.verbose(false) }
540
+ ],
541
+ ["--rakefile", "-f [FILENAME]",
542
+ "Use FILENAME as the rakefile to search for.",
543
+ lambda { |value|
544
+ value ||= ""
545
+ @rakefiles.clear
546
+ @rakefiles << value
547
+ }
548
+ ],
549
+ ["--rakelibdir", "--rakelib", "-R RAKELIBDIR",
550
+ "Auto-import any .rake files in RAKELIBDIR. " +
551
+ "(default is 'rakelib')",
552
+ lambda { |value|
553
+ options.rakelib = value.split(File::PATH_SEPARATOR)
554
+ }
555
+ ],
556
+ ["--require", "-r MODULE",
557
+ "Require MODULE before executing rakefile.",
558
+ lambda { |value|
559
+ begin
560
+ require value
561
+ rescue LoadError => ex
562
+ begin
563
+ rake_require value
564
+ rescue LoadError
565
+ raise ex
566
+ end
567
+ end
568
+ }
569
+ ],
570
+ ["--rules",
571
+ "Trace the rules resolution.",
572
+ lambda { |value| options.trace_rules = true }
573
+ ],
574
+ ["--silent", "-s",
575
+ "Like --quiet, but also suppresses the " +
576
+ "'in directory' announcement.",
577
+ lambda { |value|
578
+ Rake.verbose(false)
579
+ options.silent = true
580
+ }
581
+ ],
582
+ ["--suppress-backtrace PATTERN",
583
+ "Suppress backtrace lines matching regexp PATTERN. " +
584
+ "Ignored if --trace is on.",
585
+ lambda { |value|
586
+ options.suppress_backtrace_pattern = Regexp.new(value)
587
+ }
588
+ ],
589
+ ["--system", "-g",
590
+ "Using system wide (global) rakefiles " +
591
+ "(usually '~/.rake/*.rake').",
592
+ lambda { |value| options.load_system = true }
593
+ ],
594
+ ["--no-system", "--nosystem", "-G",
595
+ "Use standard project Rakefile search paths, " +
596
+ "ignore system wide rakefiles.",
597
+ lambda { |value| options.ignore_system = true }
598
+ ],
599
+ ["--tasks", "-T [PATTERN]",
600
+ "Display the tasks (matching optional PATTERN) " +
601
+ "with descriptions, then exit. " +
602
+ "-AT combination displays all the tasks, including those without descriptions.",
603
+ lambda { |value|
604
+ select_tasks_to_show(options, :tasks, value)
605
+ }
606
+ ],
607
+ ["--trace=[OUT]", "-t",
608
+ "Turn on invoke/execute tracing, enable full backtrace. " +
609
+ "OUT can be stderr (default) or stdout.",
610
+ lambda { |value|
611
+ options.trace = true
612
+ options.backtrace = true
613
+ select_trace_output(options, "trace", value)
614
+ Rake.verbose(true)
615
+ }
616
+ ],
617
+ ["--verbose", "-v",
618
+ "Log message to standard output.",
619
+ lambda { |value| Rake.verbose(true) }
620
+ ],
621
+ ["--version", "-V",
622
+ "Display the program version.",
623
+ lambda { |value|
624
+ puts "rake, version #{Rake::VERSION}"
625
+ exit
626
+ }
627
+ ],
628
+ ["--where", "-W [PATTERN]",
629
+ "Describe the tasks (matching optional PATTERN), then exit.",
630
+ lambda { |value|
631
+ select_tasks_to_show(options, :lines, value)
632
+ options.show_all_tasks = true
633
+ }
634
+ ],
635
+ ["--no-deprecation-warnings", "-X",
636
+ "Disable the deprecation warnings.",
637
+ lambda { |value|
638
+ options.ignore_deprecate = true
639
+ }
640
+ ],
641
+ ])
642
+ end
643
+
644
+ def select_tasks_to_show(options, show_tasks, value) # :nodoc:
645
+ options.show_tasks = show_tasks
646
+ options.show_task_pattern = Regexp.new(value || "")
647
+ Rake::TaskManager.record_task_metadata = true
648
+ end
649
+ private :select_tasks_to_show
650
+
651
+ def select_trace_output(options, trace_option, value) # :nodoc:
652
+ value = value.strip unless value.nil?
653
+ case value
654
+ when "stdout"
655
+ options.trace_output = $stdout
656
+ when "stderr", nil
657
+ options.trace_output = $stderr
658
+ else
659
+ fail CommandLineOptionError,
660
+ "Unrecognized --#{trace_option} option '#{value}'"
661
+ end
662
+ end
663
+ private :select_trace_output
664
+
665
+ # Read and handle the command line options. Returns the command line
666
+ # arguments that we didn't understand, which should (in theory) be just
667
+ # task names and env vars.
668
+ def handle_options(argv) # :nodoc:
669
+ set_default_options
670
+
671
+ OptionParser.new do |opts|
672
+ opts.banner = "#{Rake.application.name} [-f rakefile] {options} targets..."
673
+ opts.separator ""
674
+ opts.separator "Options are ..."
675
+
676
+ opts.on_tail("-h", "--help", "-H", "Display this help message.") do
677
+ puts opts
678
+ exit
679
+ end
680
+
681
+ standard_rake_options.each { |args| opts.on(*args) }
682
+ opts.environment("RAKEOPT")
683
+ end.parse(argv)
684
+ end
685
+
686
+ # Similar to the regular Ruby +require+ command, but will check
687
+ # for *.rake files in addition to *.rb files.
688
+ def rake_require(file_name, paths=$LOAD_PATH, loaded=$") # :nodoc:
689
+ fn = file_name + ".rake"
690
+ return false if loaded.include?(fn)
691
+ paths.each do |path|
692
+ full_path = File.join(path, fn)
693
+ if File.exist?(full_path)
694
+ Rake.load_rakefile(full_path)
695
+ loaded << fn
696
+ return true
697
+ end
698
+ end
699
+ fail LoadError, "Can't find #{file_name}"
700
+ end
701
+
702
+ def find_rakefile_location # :nodoc:
703
+ here = Dir.pwd
704
+ until (fn = have_rakefile)
705
+ Dir.chdir("..")
706
+ return nil if Dir.pwd == here || options.nosearch
707
+ here = Dir.pwd
708
+ end
709
+ [fn, here]
710
+ ensure
711
+ Dir.chdir(Rake.original_dir)
712
+ end
713
+
714
+ def print_rakefile_directory(location) # :nodoc:
715
+ $stderr.puts "(in #{Dir.pwd})" unless
716
+ options.silent or original_dir == location
717
+ end
718
+
719
+ def raw_load_rakefile # :nodoc:
720
+ rakefile, location = find_rakefile_location
721
+ if (!options.ignore_system) &&
722
+ (options.load_system || rakefile.nil?) &&
723
+ system_dir && File.directory?(system_dir)
724
+ print_rakefile_directory(location)
725
+ glob("#{system_dir}/*.rake") do |name|
726
+ add_import name
727
+ end
728
+ else
729
+ fail "No Rakefile found (looking for: #{@rakefiles.join(', ')})" if
730
+ rakefile.nil?
731
+ @rakefile = rakefile
732
+ Dir.chdir(location)
733
+ print_rakefile_directory(location)
734
+ Rake.load_rakefile(File.expand_path(@rakefile)) if
735
+ @rakefile && @rakefile != ""
736
+ options.rakelib.each do |rlib|
737
+ glob("#{rlib}/*.rake") do |name|
738
+ add_import name
739
+ end
740
+ end
741
+ end
742
+ load_imports
743
+ end
744
+
745
+ def glob(path, &block) # :nodoc:
746
+ FileList.glob(path.tr("\\", "/")).each(&block)
747
+ end
748
+ private :glob
749
+
750
+ # The directory path containing the system wide rakefiles.
751
+ def system_dir # :nodoc:
752
+ @system_dir ||=
753
+ begin
754
+ if ENV["RAKE_SYSTEM"]
755
+ ENV["RAKE_SYSTEM"]
756
+ else
757
+ standard_system_dir
758
+ end
759
+ end
760
+ end
761
+
762
+ # The standard directory containing system wide rake files.
763
+ if Win32.windows?
764
+ def standard_system_dir #:nodoc:
765
+ Win32.win32_system_dir
766
+ end
767
+ else
768
+ def standard_system_dir #:nodoc:
769
+ File.join(File.expand_path("~"), ".rake")
770
+ end
771
+ end
772
+ private :standard_system_dir
773
+
774
+ # Collect the list of tasks on the command line. If no tasks are
775
+ # given, return a list containing only the default task.
776
+ # Environmental assignments are processed at this time as well.
777
+ #
778
+ # `args` is the list of arguments to peruse to get the list of tasks.
779
+ # It should be the command line that was given to rake, less any
780
+ # recognised command-line options, which OptionParser.parse will
781
+ # have taken care of already.
782
+ def collect_command_line_tasks(args) # :nodoc:
783
+ @top_level_tasks = []
784
+ args.each do |arg|
785
+ if arg =~ /^(\w+)=(.*)$/m
786
+ ENV[$1] = $2
787
+ else
788
+ @top_level_tasks << arg unless arg =~ /^-/
789
+ end
790
+ end
791
+ @top_level_tasks.push(default_task_name) if @top_level_tasks.empty?
792
+ end
793
+
794
+ # Default task name ("default").
795
+ # (May be overridden by subclasses)
796
+ def default_task_name # :nodoc:
797
+ "default"
798
+ end
799
+
800
+ # Add a file to the list of files to be imported.
801
+ def add_import(fn) # :nodoc:
802
+ @pending_imports << fn
803
+ end
804
+
805
+ # Load the pending list of imported files.
806
+ def load_imports # :nodoc:
807
+ while fn = @pending_imports.shift
808
+ next if @imported.member?(fn)
809
+ fn_task = lookup(fn) and fn_task.invoke
810
+ ext = File.extname(fn)
811
+ loader = @loaders[ext] || @default_loader
812
+ loader.load(fn)
813
+ if fn_task = lookup(fn) and fn_task.needed?
814
+ fn_task.reenable
815
+ fn_task.invoke
816
+ loader.load(fn)
817
+ end
818
+ @imported << fn
819
+ end
820
+ end
821
+
822
+ def rakefile_location(backtrace=caller) # :nodoc:
823
+ backtrace.map { |t| t[/([^:]+):/, 1] }
824
+
825
+ re = /^#{@rakefile}$/
826
+ re = /#{re.source}/i if windows?
827
+
828
+ backtrace.find { |str| str =~ re } || ""
829
+ end
830
+
831
+ def set_default_options # :nodoc:
832
+ options.always_multitask = false
833
+ options.backtrace = false
834
+ options.build_all = false
835
+ options.dryrun = false
836
+ options.ignore_deprecate = false
837
+ options.ignore_system = false
838
+ options.job_stats = false
839
+ options.load_system = false
840
+ options.nosearch = false
841
+ options.rakelib = %w[rakelib]
842
+ options.show_all_tasks = false
843
+ options.show_prereqs = false
844
+ options.show_task_pattern = nil
845
+ options.show_tasks = nil
846
+ options.silent = false
847
+ options.suppress_backtrace_pattern = nil
848
+ options.thread_pool_size = Rake.suggested_thread_count
849
+ options.trace = false
850
+ options.trace_output = $stderr
851
+ options.trace_rules = false
852
+ end
853
+
854
+ end
855
+ end