rake 0.8.7 → 0.9.0.beta.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rake might be problematic. Click here for more details.

Files changed (122) hide show
  1. data/.gemtest +0 -0
  2. data/CHANGES +77 -9
  3. data/{README → README.rdoc} +14 -10
  4. data/Rakefile +113 -110
  5. data/TODO +1 -1
  6. data/doc/command_line_usage.rdoc +18 -6
  7. data/doc/glossary.rdoc +2 -2
  8. data/doc/jamis.rb +2 -2
  9. data/doc/proto_rake.rdoc +22 -22
  10. data/doc/rake.1.gz +0 -0
  11. data/doc/rakefile.rdoc +60 -28
  12. data/doc/rational.rdoc +6 -6
  13. data/doc/release_notes/rake-0.4.15.rdoc +1 -1
  14. data/doc/release_notes/rake-0.5.0.rdoc +1 -1
  15. data/doc/release_notes/rake-0.7.0.rdoc +1 -1
  16. data/doc/release_notes/rake-0.7.2.rdoc +3 -3
  17. data/doc/release_notes/rake-0.7.3.rdoc +2 -2
  18. data/doc/release_notes/rake-0.8.0.rdoc +1 -1
  19. data/doc/release_notes/rake-0.8.2.rdoc +3 -3
  20. data/doc/release_notes/rake-0.8.3.rdoc +2 -2
  21. data/doc/release_notes/rake-0.8.4.rdoc +1 -1
  22. data/doc/release_notes/rake-0.8.5.rdoc +1 -1
  23. data/doc/release_notes/rake-0.8.6.rdoc +1 -1
  24. data/doc/release_notes/rake-0.8.7.rdoc +1 -1
  25. data/install.rb +14 -12
  26. data/lib/rake.rb +28 -2470
  27. data/lib/rake/alt_system.rb +7 -6
  28. data/lib/rake/application.rb +585 -0
  29. data/lib/rake/classic_namespace.rb +1 -0
  30. data/lib/rake/clean.rb +14 -14
  31. data/lib/rake/cloneable.rb +25 -0
  32. data/lib/rake/contrib/compositepublisher.rb +2 -5
  33. data/lib/rake/contrib/ftptools.rb +5 -8
  34. data/lib/rake/contrib/publisher.rb +2 -8
  35. data/lib/rake/contrib/rubyforgepublisher.rb +2 -4
  36. data/lib/rake/contrib/sshpublisher.rb +4 -6
  37. data/lib/rake/contrib/sys.rb +7 -25
  38. data/lib/rake/default_loader.rb +10 -0
  39. data/lib/rake/dsl.rb +2 -0
  40. data/lib/rake/dsl_definition.rb +146 -0
  41. data/lib/rake/early_time.rb +18 -0
  42. data/lib/rake/environment.rb +40 -0
  43. data/lib/rake/ext/core.rb +27 -0
  44. data/lib/rake/ext/module.rb +39 -0
  45. data/lib/rake/ext/string.rb +167 -0
  46. data/lib/rake/ext/time.rb +14 -0
  47. data/lib/rake/file_creation_task.rb +24 -0
  48. data/lib/rake/file_list.rb +403 -0
  49. data/lib/rake/file_task.rb +47 -0
  50. data/lib/rake/file_utils.rb +112 -0
  51. data/lib/rake/file_utils_ext.rb +132 -0
  52. data/lib/rake/gempackagetask.rb +6 -90
  53. data/lib/rake/invocation_chain.rb +51 -0
  54. data/lib/rake/invocation_exception_mixin.rb +16 -0
  55. data/lib/rake/loaders/makefile.rb +13 -15
  56. data/lib/rake/multi_task.rb +16 -0
  57. data/lib/rake/name_space.rb +25 -0
  58. data/lib/rake/packagetask.rb +13 -12
  59. data/lib/rake/pathmap.rb +1 -0
  60. data/lib/rake/pseudo_status.rb +24 -0
  61. data/lib/rake/rake_module.rb +25 -0
  62. data/lib/rake/rake_test_loader.rb +10 -2
  63. data/lib/rake/rdoctask.rb +211 -190
  64. data/lib/rake/ruby182_test_unit_fix.rb +9 -7
  65. data/lib/rake/rule_recursion_overflow_error.rb +20 -0
  66. data/lib/rake/runtest.rb +4 -6
  67. data/lib/rake/task.rb +327 -0
  68. data/lib/rake/task_argument_error.rb +7 -0
  69. data/lib/rake/task_arguments.rb +74 -0
  70. data/lib/rake/task_manager.rb +329 -0
  71. data/lib/rake/tasklib.rb +1 -2
  72. data/lib/rake/testtask.rb +51 -26
  73. data/lib/rake/version.rb +12 -0
  74. data/lib/rake/win32.rb +4 -4
  75. data/test/contrib/test_sys.rb +7 -30
  76. data/test/data/comments/Rakefile +18 -0
  77. data/test/data/default/Rakefile +1 -1
  78. data/test/data/dryrun/Rakefile +1 -1
  79. data/test/data/file_creation_task/Rakefile +1 -1
  80. data/test/data/namespace/Rakefile +9 -0
  81. data/test/data/rakelib/test1.rb +4 -2
  82. data/test/data/verbose/Rakefile +34 -0
  83. data/test/functional/functional_test.rb +25 -0
  84. data/test/{session_functional.rb → functional/session_based_tests.rb} +134 -23
  85. data/test/in_environment.rb +6 -4
  86. data/test/{test_application.rb → lib/application_test.rb} +277 -136
  87. data/test/{test_clean.rb → lib/clean_test.rb} +1 -0
  88. data/test/{test_definitions.rb → lib/definitions_test.rb} +2 -2
  89. data/test/lib/dsl_test.rb +52 -0
  90. data/test/{test_earlytime.rb → lib/earlytime_test.rb} +1 -2
  91. data/test/lib/environment_test.rb +18 -0
  92. data/test/{test_extension.rb → lib/extension_test.rb} +2 -2
  93. data/test/{test_file_creation_task.rb → lib/file_creation_task_test.rb} +0 -0
  94. data/test/{test_file_task.rb → lib/file_task_test.rb} +3 -3
  95. data/test/{test_filelist.rb → lib/filelist_test.rb} +28 -24
  96. data/test/{test_fileutils.rb → lib/fileutils_test.rb} +26 -21
  97. data/test/{test_ftp.rb → lib/ftp_test.rb} +0 -0
  98. data/test/{test_invocation_chain.rb → lib/invocation_chain_test.rb} +0 -0
  99. data/test/{test_makefile_loader.rb → lib/makefile_loader_test.rb} +0 -0
  100. data/test/{test_multitask.rb → lib/multitask_test.rb} +14 -6
  101. data/test/{test_namespace.rb → lib/namespace_test.rb} +0 -0
  102. data/test/lib/package_task_test.rb +82 -0
  103. data/test/{test_pathmap.rb → lib/pathmap_test.rb} +3 -2
  104. data/test/{test_pseudo_status.rb → lib/pseudo_status_test.rb} +0 -0
  105. data/test/{test_rake.rb → lib/rake_test.rb} +1 -1
  106. data/test/{test_rdoc_task.rb → lib/rdoc_task_test.rb} +19 -23
  107. data/test/{test_require.rb → lib/require_test.rb} +8 -2
  108. data/test/{test_rules.rb → lib/rules_test.rb} +1 -2
  109. data/test/{test_task_arguments.rb → lib/task_arguments_test.rb} +5 -5
  110. data/test/{test_task_manager.rb → lib/task_manager_test.rb} +5 -5
  111. data/test/{test_tasks.rb → lib/task_test.rb} +69 -4
  112. data/test/{test_tasklib.rb → lib/tasklib_test.rb} +0 -0
  113. data/test/{test_test_task.rb → lib/test_task_test.rb} +3 -3
  114. data/test/lib/testtask_test.rb +49 -0
  115. data/test/{test_top_level_functions.rb → lib/top_level_functions_test.rb} +3 -3
  116. data/test/{test_win32.rb → lib/win32_test.rb} +19 -0
  117. data/test/rake_test_setup.rb +4 -9
  118. data/test/ruby_version_test.rb +3 -0
  119. data/test/test_helper.rb +12 -0
  120. metadata +100 -44
  121. data/test/functional.rb +0 -15
  122. data/test/test_package_task.rb +0 -118
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Copyright (c) 2008 James M. Lawrence
3
- #
3
+ #
4
4
  # Permission is hereby granted, free of charge, to any person
5
5
  # obtaining a copy of this software and associated documentation files
6
6
  # (the "Software"), to deal in the Software without restriction,
@@ -8,10 +8,10 @@
8
8
  # publish, distribute, sublicense, and/or sell copies of the Software,
9
9
  # and to permit persons to whom the Software is furnished to do so,
10
10
  # subject to the following conditions:
11
- #
11
+ #
12
12
  # The above copyright notice and this permission notice shall be
13
13
  # included in all copies or substantial portions of the Software.
14
- #
14
+ #
15
15
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
16
  # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
17
  # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -27,9 +27,10 @@ require 'rbconfig'
27
27
  #
28
28
  # Alternate implementations of system() and backticks `` on Windows
29
29
  # for ruby-1.8 and earlier.
30
- #
30
+ #
31
31
  module Rake::AltSystem
32
- WINDOWS = Config::CONFIG["host_os"] =~ %r!(msdos|mswin|djgpp|mingw)!
32
+ WINDOWS = RbConfig::CONFIG["host_os"] =~
33
+ %r!(msdos|mswin|djgpp|mingw|[Ww]indows)!
33
34
 
34
35
  class << self
35
36
  def define_module_function(name, &block)
@@ -37,7 +38,7 @@ module Rake::AltSystem
37
38
  module_function(name)
38
39
  end
39
40
  end
40
-
41
+
41
42
  if WINDOWS and RUBY_VERSION < "1.9.0"
42
43
  RUNNABLE_EXTS = %w[com exe bat cmd]
43
44
  RUNNABLE_PATTERN = %r!\.(#{RUNNABLE_EXTS.join('|')})\Z!i
@@ -0,0 +1,585 @@
1
+ require 'shellwords'
2
+ require 'optparse'
3
+
4
+ require 'rake/task_manager'
5
+ require 'rake/win32'
6
+
7
+ module Rake
8
+
9
+ ######################################################################
10
+ # Rake main application object. When invoking +rake+ from the
11
+ # command line, a Rake::Application object is created and run.
12
+ #
13
+ class Application
14
+ include TaskManager
15
+
16
+ # The name of the application (typically 'rake')
17
+ attr_reader :name
18
+
19
+ # The original directory where rake was invoked.
20
+ attr_reader :original_dir
21
+
22
+ # Name of the actual rakefile used.
23
+ attr_reader :rakefile
24
+
25
+ # List of the top level task names (task names from the command line).
26
+ attr_reader :top_level_tasks
27
+
28
+ DEFAULT_RAKEFILES = ['rakefile', 'Rakefile', 'rakefile.rb', 'Rakefile.rb'].freeze
29
+
30
+ # Initialize a Rake::Application object.
31
+ def initialize
32
+ super
33
+ @name = 'rake'
34
+ @rakefiles = DEFAULT_RAKEFILES.dup
35
+ @rakefile = nil
36
+ @pending_imports = []
37
+ @imported = []
38
+ @loaders = {}
39
+ @default_loader = Rake::DefaultLoader.new
40
+ @original_dir = Dir.pwd
41
+ @top_level_tasks = []
42
+ add_loader('rb', DefaultLoader.new)
43
+ add_loader('rf', DefaultLoader.new)
44
+ add_loader('rake', DefaultLoader.new)
45
+ @tty_output = STDOUT.tty?
46
+ end
47
+
48
+ # Run the Rake application. The run method performs the following
49
+ # three steps:
50
+ #
51
+ # * Initialize the command line options (+init+).
52
+ # * Define the tasks (+load_rakefile+).
53
+ # * Run the top level tasks (+run_tasks+).
54
+ #
55
+ # If you wish to build a custom rake command, you should call
56
+ # +init+ on your application. Then define any tasks. Finally,
57
+ # call +top_level+ to run your top level tasks.
58
+ def run
59
+ standard_exception_handling do
60
+ init
61
+ load_rakefile
62
+ top_level
63
+ end
64
+ end
65
+
66
+ # Initialize the command line parameters and app name.
67
+ def init(app_name='rake')
68
+ standard_exception_handling do
69
+ @name = app_name
70
+ handle_options
71
+ collect_tasks
72
+ end
73
+ end
74
+
75
+ # Find the rakefile and then load it and any pending imports.
76
+ def load_rakefile
77
+ standard_exception_handling do
78
+ raw_load_rakefile
79
+ end
80
+ end
81
+
82
+ # Run the top level tasks of a Rake application.
83
+ def top_level
84
+ standard_exception_handling do
85
+ if options.show_tasks
86
+ display_tasks_and_comments
87
+ elsif options.show_prereqs
88
+ display_prerequisites
89
+ else
90
+ top_level_tasks.each { |task_name| invoke_task(task_name) }
91
+ end
92
+ end
93
+ end
94
+
95
+ # Add a loader to handle imported files ending in the extension
96
+ # +ext+.
97
+ def add_loader(ext, loader)
98
+ ext = ".#{ext}" unless ext =~ /^\./
99
+ @loaders[ext] = loader
100
+ end
101
+
102
+ # Application options from the command line
103
+ def options
104
+ @options ||= OpenStruct.new
105
+ end
106
+
107
+ # private ----------------------------------------------------------------
108
+
109
+ def invoke_task(task_string)
110
+ name, args = parse_task_string(task_string)
111
+ t = self[name]
112
+ t.invoke(*args)
113
+ end
114
+
115
+ def parse_task_string(string)
116
+ if string =~ /^([^\[]+)(\[(.*)\])$/
117
+ name = $1
118
+ args = $3.split(/\s*,\s*/)
119
+ else
120
+ name = string
121
+ args = []
122
+ end
123
+ [name, args]
124
+ end
125
+
126
+ # Provide standard exception handling for the given block.
127
+ def standard_exception_handling
128
+ begin
129
+ yield
130
+ rescue SystemExit => ex
131
+ # Exit silently with current status
132
+ raise
133
+ rescue OptionParser::InvalidOption => ex
134
+ $stderr.puts ex.message
135
+ exit(false)
136
+ rescue Exception => ex
137
+ # Exit with error message
138
+ display_error_message(ex)
139
+ exit(false)
140
+ end
141
+ end
142
+
143
+ # Display the error message that caused the exception.
144
+ def display_error_message(ex)
145
+ $stderr.puts "#{name} aborted!"
146
+ $stderr.puts ex.message
147
+ if options.trace
148
+ $stderr.puts ex.backtrace.join("\n")
149
+ else
150
+ $stderr.puts rakefile_location(ex.backtrace)
151
+ end
152
+ $stderr.puts "Tasks: #{ex.chain}" if has_chain?(ex)
153
+ $stderr.puts "(See full trace by running task with --trace)" unless options.trace
154
+ end
155
+
156
+ # Does the exception have a task invocation chain?
157
+ def has_chain?(exception)
158
+ exception.respond_to?(:chain) && exception.chain
159
+ end
160
+ private :has_chain?
161
+
162
+ # True if one of the files in RAKEFILES is in the current directory.
163
+ # If a match is found, it is copied into @rakefile.
164
+ def have_rakefile
165
+ @rakefiles.each do |fn|
166
+ if File.exist?(fn)
167
+ others = Dir.glob(fn, File::FNM_CASEFOLD)
168
+ return others.size == 1 ? others.first : fn
169
+ elsif fn == ''
170
+ return fn
171
+ end
172
+ end
173
+ return nil
174
+ end
175
+
176
+ # True if we are outputting to TTY, false otherwise
177
+ def tty_output?
178
+ @tty_output
179
+ end
180
+
181
+ # Override the detected TTY output state (mostly for testing)
182
+ def tty_output=( tty_output_state )
183
+ @tty_output = tty_output_state
184
+ end
185
+
186
+ # We will truncate output if we are outputting to a TTY or if we've been
187
+ # given an explicit column width to honor
188
+ def truncate_output?
189
+ tty_output? || ENV['RAKE_COLUMNS']
190
+ end
191
+
192
+ # Display the tasks and comments.
193
+ def display_tasks_and_comments
194
+ displayable_tasks = tasks.select { |t|
195
+ t.comment && t.name =~ options.show_task_pattern
196
+ }
197
+ case options.show_tasks
198
+ when :tasks
199
+ width = displayable_tasks.collect { |t| t.name_with_args.length }.max || 10
200
+ max_column = truncate_output? ? terminal_width - name.size - width - 7 : nil
201
+ displayable_tasks.each do |t|
202
+ printf "#{name} %-#{width}s # %s\n",
203
+ t.name_with_args, max_column ? truncate(t.comment, max_column) : t.comment
204
+ end
205
+ when :describe
206
+ displayable_tasks.each do |t|
207
+ puts "#{name} #{t.name_with_args}"
208
+ t.full_comment.split("\n").each do |line|
209
+ puts " #{line}"
210
+ end
211
+ puts
212
+ end
213
+ when :lines
214
+ displayable_tasks.each do |t|
215
+ t.locations.each do |loc|
216
+ printf "#{name} %-30s %s\n",t.name_with_args, loc
217
+ end
218
+ end
219
+ else
220
+ fail "Unknown show task mode: '#{options.show_tasks}'"
221
+ end
222
+ end
223
+
224
+ def terminal_width
225
+ if ENV['RAKE_COLUMNS']
226
+ result = ENV['RAKE_COLUMNS'].to_i
227
+ else
228
+ result = unix? ? dynamic_width : 80
229
+ end
230
+ (result < 10) ? 80 : result
231
+ rescue
232
+ 80
233
+ end
234
+
235
+ # Calculate the dynamic width of the
236
+ def dynamic_width
237
+ @dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput)
238
+ end
239
+
240
+ def dynamic_width_stty
241
+ %x{stty size 2>/dev/null}.split[1].to_i
242
+ end
243
+
244
+ def dynamic_width_tput
245
+ %x{tput cols 2>/dev/null}.to_i
246
+ end
247
+
248
+ def unix?
249
+ RbConfig::CONFIG['host_os'] =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
250
+ end
251
+
252
+ def windows?
253
+ Win32.windows?
254
+ end
255
+
256
+ def truncate(string, width)
257
+ if string.length <= width
258
+ string
259
+ else
260
+ ( string[0, width-3] || "" ) + "..."
261
+ end
262
+ end
263
+
264
+ # Display the tasks and prerequisites
265
+ def display_prerequisites
266
+ tasks.each do |t|
267
+ puts "#{name} #{t.name}"
268
+ t.prerequisites.each { |pre| puts " #{pre}" }
269
+ end
270
+ end
271
+
272
+ # A list of all the standard options used in rake, suitable for
273
+ # passing to OptionParser.
274
+ def standard_rake_options
275
+ [
276
+ ['--classic-namespace', '-C', "Put Task and FileTask in the top level namespace",
277
+ lambda { |value|
278
+ require 'rake/classic_namespace'
279
+ options.classic_namespace = true
280
+ }
281
+ ],
282
+ ['--describe', '-D [PATTERN]', "Describe the tasks (matching optional PATTERN), then exit.",
283
+ lambda { |value|
284
+ options.show_tasks = :describe
285
+ options.show_task_pattern = Regexp.new(value || '')
286
+ TaskManager.record_task_metadata = true
287
+ }
288
+ ],
289
+ ['--dry-run', '-n', "Do a dry run without executing actions.",
290
+ lambda { |value|
291
+ Rake.verbose(true)
292
+ Rake.nowrite(true)
293
+ options.dryrun = true
294
+ options.trace = true
295
+ }
296
+ ],
297
+ ['--execute', '-e CODE', "Execute some Ruby code and exit.",
298
+ lambda { |value|
299
+ eval(value)
300
+ exit
301
+ }
302
+ ],
303
+ ['--execute-print', '-p CODE', "Execute some Ruby code, print the result, then exit.",
304
+ lambda { |value|
305
+ puts eval(value)
306
+ exit
307
+ }
308
+ ],
309
+ ['--execute-continue', '-E CODE',
310
+ "Execute some Ruby code, then continue with normal task processing.",
311
+ lambda { |value| eval(value) }
312
+ ],
313
+ ['--libdir', '-I LIBDIR', "Include LIBDIR in the search path for required modules.",
314
+ lambda { |value| $:.push(value) }
315
+ ],
316
+ ['--no-search', '--nosearch', '-N', "Do not search parent directories for the Rakefile.",
317
+ lambda { |value| options.nosearch = true }
318
+ ],
319
+ ['--prereqs', '-P', "Display the tasks and dependencies, then exit.",
320
+ lambda { |value| options.show_prereqs = true }
321
+ ],
322
+ ['--quiet', '-q', "Do not log messages to standard output.",
323
+ lambda { |value| Rake.verbose(false) }
324
+ ],
325
+ ['--rakefile', '-f [FILE]', "Use FILE as the rakefile.",
326
+ lambda { |value|
327
+ value ||= ''
328
+ @rakefiles.clear
329
+ @rakefiles << value
330
+ }
331
+ ],
332
+ ['--rakelibdir', '--rakelib', '-R RAKELIBDIR',
333
+ "Auto-import any .rake files in RAKELIBDIR. (default is 'rakelib')",
334
+ lambda { |value| options.rakelib = value.split(':') }
335
+ ],
336
+ ['--require', '-r MODULE', "Require MODULE before executing rakefile.",
337
+ lambda { |value|
338
+ begin
339
+ require value
340
+ rescue LoadError => ex
341
+ begin
342
+ rake_require value
343
+ rescue LoadError
344
+ raise ex
345
+ end
346
+ end
347
+ }
348
+ ],
349
+ ['--rules', "Trace the rules resolution.",
350
+ lambda { |value| options.trace_rules = true }
351
+ ],
352
+ ['--silent', '-s', "Like --quiet, but also suppresses the 'in directory' announcement.",
353
+ lambda { |value|
354
+ Rake.verbose(false)
355
+ options.silent = true
356
+ }
357
+ ],
358
+ ['--system', '-g',
359
+ "Using system wide (global) rakefiles (usually '~/.rake/*.rake').",
360
+ lambda { |value| options.load_system = true }
361
+ ],
362
+ ['--no-system', '--nosystem', '-G',
363
+ "Use standard project Rakefile search paths, ignore system wide rakefiles.",
364
+ lambda { |value| options.ignore_system = true }
365
+ ],
366
+ ['--tasks', '-T [PATTERN]', "Display the tasks (matching optional PATTERN) with descriptions, then exit.",
367
+ lambda { |value|
368
+ options.show_tasks = :tasks
369
+ options.show_task_pattern = Regexp.new(value || '')
370
+ Rake::TaskManager.record_task_metadata = true
371
+ }
372
+ ],
373
+ ['--no-top-level-dsl', '-X', "Do not put Rake DSL commands in the top level scope.",
374
+ lambda { |value|
375
+ options.top_level_dsl = ! value
376
+ }
377
+ ],
378
+ ['--top-level-dsl', "Put Rake DSL commands in the top level scope (default).",
379
+ lambda { |value|
380
+ options.top_level_dsl = value
381
+ }
382
+ ],
383
+ ['--trace', '-t', "Turn on invoke/execute tracing, enable full backtrace.",
384
+ lambda { |value|
385
+ options.trace = true
386
+ Rake.verbose(true)
387
+ }
388
+ ],
389
+ ['--verbose', '-v', "Log message to standard output.",
390
+ lambda { |value| Rake.verbose(true) }
391
+ ],
392
+ ['--version', '-V', "Display the program version.",
393
+ lambda { |value|
394
+ puts "rake, version #{RAKEVERSION}"
395
+ exit
396
+ }
397
+ ],
398
+ ['--where', '-W [PATTERN]', "Describe the tasks (matching optional PATTERN), then exit.",
399
+ lambda { |value|
400
+ options.show_tasks = :lines
401
+ options.show_task_pattern = Regexp.new(value || '')
402
+ Rake::TaskManager.record_task_metadata = true
403
+ }
404
+ ],
405
+ ]
406
+ end
407
+
408
+ # Read and handle the command line options.
409
+ def handle_options
410
+ options.rakelib = ['rakelib']
411
+ options.top_level_dsl = true
412
+
413
+ OptionParser.new do |opts|
414
+ opts.banner = "rake [-f rakefile] {options} targets..."
415
+ opts.separator ""
416
+ opts.separator "Options are ..."
417
+
418
+ opts.on_tail("-h", "--help", "-H", "Display this help message.") do
419
+ puts opts
420
+ exit
421
+ end
422
+
423
+ standard_rake_options.each { |args| opts.on(*args) }
424
+ opts.environment('RAKEOPT')
425
+ end.parse!
426
+
427
+ Rake::DSL.include_in_top_scope if options.top_level_dsl
428
+
429
+ # If class namespaces are requested, set the global options
430
+ # according to the values in the options structure.
431
+ if options.classic_namespace
432
+ $show_tasks = options.show_tasks
433
+ $show_prereqs = options.show_prereqs
434
+ $trace = options.trace
435
+ $dryrun = options.dryrun
436
+ $silent = options.silent
437
+ end
438
+ end
439
+
440
+ # Similar to the regular Ruby +require+ command, but will check
441
+ # for *.rake files in addition to *.rb files.
442
+ def rake_require(file_name, paths=$LOAD_PATH, loaded=$")
443
+ fn = file_name + ".rake"
444
+ return false if loaded.include?(fn)
445
+ paths.each do |path|
446
+ full_path = File.join(path, fn)
447
+ if File.exist?(full_path)
448
+ Rake::Environment.load_rakefile(full_path)
449
+ loaded << fn
450
+ return true
451
+ end
452
+ end
453
+ fail LoadError, "Can't find #{file_name}"
454
+ end
455
+
456
+ def find_rakefile_location
457
+ here = Dir.pwd
458
+ while ! (fn = have_rakefile)
459
+ Dir.chdir("..")
460
+ if Dir.pwd == here || options.nosearch
461
+ return nil
462
+ end
463
+ here = Dir.pwd
464
+ end
465
+ [fn, here]
466
+ ensure
467
+ Dir.chdir(Rake.original_dir)
468
+ end
469
+
470
+ def print_rakefile_directory(location)
471
+ $stderr.puts "(in #{Dir.pwd})" unless
472
+ options.silent or original_dir == location
473
+ end
474
+
475
+ def raw_load_rakefile # :nodoc:
476
+ rakefile, location = find_rakefile_location
477
+ if (! options.ignore_system) &&
478
+ (options.load_system || rakefile.nil?) &&
479
+ system_dir && File.directory?(system_dir)
480
+ print_rakefile_directory(location)
481
+ glob("#{system_dir}/*.rake") do |name|
482
+ add_import name
483
+ end
484
+ else
485
+ fail "No Rakefile found (looking for: #{@rakefiles.join(', ')})" if
486
+ rakefile.nil?
487
+ @rakefile = rakefile
488
+ Dir.chdir(location)
489
+ print_rakefile_directory(location)
490
+ $rakefile = @rakefile if options.classic_namespace
491
+ Rake::Environment.load_rakefile(File.expand_path(@rakefile)) if @rakefile && @rakefile != ''
492
+ options.rakelib.each do |rlib|
493
+ glob("#{rlib}/*.rake") do |name|
494
+ add_import name
495
+ end
496
+ end
497
+ end
498
+ load_imports
499
+ end
500
+
501
+ def glob(path, &block)
502
+ Dir[path.gsub("\\", '/')].each(&block)
503
+ end
504
+ private :glob
505
+
506
+ # The directory path containing the system wide rakefiles.
507
+ def system_dir
508
+ @system_dir ||=
509
+ begin
510
+ if ENV['RAKE_SYSTEM']
511
+ ENV['RAKE_SYSTEM']
512
+ else
513
+ standard_system_dir
514
+ end
515
+ end
516
+ end
517
+
518
+ # The standard directory containing system wide rake files.
519
+ if Win32.windows?
520
+ def standard_system_dir #:nodoc:
521
+ Win32.win32_system_dir
522
+ end
523
+ else
524
+ def standard_system_dir #:nodoc:
525
+ File.join(File.expand_path('~'), '.rake')
526
+ end
527
+ end
528
+ private :standard_system_dir
529
+
530
+ # Collect the list of tasks on the command line. If no tasks are
531
+ # given, return a list containing only the default task.
532
+ # Environmental assignments are processed at this time as well.
533
+ def collect_tasks
534
+ @top_level_tasks = []
535
+ ARGV.each do |arg|
536
+ if arg =~ /^(\w+)=(.*)$/
537
+ ENV[$1] = $2
538
+ else
539
+ @top_level_tasks << arg unless arg =~ /^-/
540
+ end
541
+ end
542
+ @top_level_tasks.push("default") if @top_level_tasks.size == 0
543
+ end
544
+
545
+ # Add a file to the list of files to be imported.
546
+ def add_import(fn)
547
+ @pending_imports << fn
548
+ end
549
+
550
+ # Load the pending list of imported files.
551
+ def load_imports
552
+ while fn = @pending_imports.shift
553
+ next if @imported.member?(fn)
554
+ if fn_task = lookup(fn)
555
+ fn_task.invoke
556
+ end
557
+ ext = File.extname(fn)
558
+ loader = @loaders[ext] || @default_loader
559
+ loader.load(fn)
560
+ @imported << fn
561
+ end
562
+ end
563
+
564
+ # Warn about deprecated use of top level constant names.
565
+ def const_warning(const_name)
566
+ @const_warning ||= false
567
+ if ! @const_warning
568
+ $stderr.puts %{WARNING: Deprecated reference to top-level constant '#{const_name}' } +
569
+ %{found at: #{rakefile_location}} # '
570
+ $stderr.puts %{ Use --classic-namespace on rake command}
571
+ $stderr.puts %{ or 'require "rake/classic_namespace"' in Rakefile}
572
+ end
573
+ @const_warning = true
574
+ end
575
+
576
+ def rakefile_location backtrace = caller
577
+ backtrace.map { |t| t[/([^:]+):/,1] }
578
+
579
+ re = /^#{@rakefile}$/
580
+ re = /#{re.source}/i if windows?
581
+
582
+ backtrace.find { |str| str =~ re } || ''
583
+ end
584
+ end
585
+ end