~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to lib/rake.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2010-07-31 17:08:39 UTC
  • mfrom: (1.1.4 upstream) (8.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100731170839-j034dmpdqt1cc4p6
Tags: 1.9.2~svn28788-1
* New release based on upstream snapshot from the 1.9.2 branch,
  after 1.9.2 RC2. That branch is (supposed to be) binary-compatible
  with the 1.9.1 branch.
  + Builds fine on i386. Closes: #580852.
* Upgrade to Standards-Version: 3.9.1. No changes needed.
* Updated generated incs.
* Patches that still need work:
  + Unclear status, need more investigation:
   090729_fix_Makefile_deps.dpatch
   090803_exclude_rdoc.dpatch
   203_adjust_base_of_search_path.dpatch
   902_define_YAML_in_yaml_stringio.rb.dpatch
   919_common.mk_tweaks.dpatch
   931_libruby_suffix.dpatch
   940_test_thread_mutex_sync_shorter.dpatch
  + Maybe not needed anymore, keeping but not applying.
   102_skip_test_copy_stream.dpatch (test doesn't block anymore?)
   104_skip_btest_io.dpatch (test doesn't block anymore?)
   201_gem_prelude.dpatch (we don't use that rubygems anyway?)
   202_gem_default_dir.dpatch (we don't use that rubygems anyway?)
   940_test_file_exhaustive_fails_as_root.dpatch
   940_test_priority_fails.dpatch
   100518_load_libc_libm.dpatch
* Add disable-tests.diff: disable some tests that cause failures on FreeBSD.
  Closes: #590002, #543805, #542927.
* However, many new failures on FreeBSD. Since that version is still an
  improvement, add the check that makes test suite failures non-fatal on
  FreeBSD again. That still needs to be investigated.
* Re-add 903_skip_base_ruby_check.dpatch
* Add build-dependency on ruby1.8 and drop all pre-generated files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env ruby
2
 
 
3
1
#--
4
2
 
5
 
# Copyright (c) 2003, 2004, 2005, 2006, 2007  Jim Weirich
 
3
# Copyright 2003, 2004, 2005, 2006, 2007, 2008 by Jim Weirich (jim@weirichhouse.org)
6
4
#
7
5
# Permission is hereby granted, free of charge, to any person obtaining a copy
8
6
# of this software and associated documentation files (the "Software"), to
29
27
# as a library via a require statement, but it can be distributed
30
28
# independently as an application.
31
29
 
32
 
RAKEVERSION = '0.8.3'
 
30
RAKEVERSION = '0.8.7'
33
31
 
34
32
require 'rbconfig'
35
33
require 'fileutils'
40
38
 
41
39
require 'rake/win32'
42
40
 
 
41
$trace = false
 
42
 
43
43
######################################################################
44
44
# Rake extensions to Module.
45
45
#
74
74
#
75
75
class String
76
76
  rake_extension("ext") do
77
 
    # Replace the file extension with +newext+.  If there is no extenson on
 
77
    # Replace the file extension with +newext+.  If there is no extension on
78
78
    # the string, append the new extension to the end.  If the new extension
79
79
    # is not given, or is the empty string, remove any existing extension.
80
80
    #
115
115
      File.join(partial_dirs)
116
116
    end
117
117
    protected :pathmap_partial
118
 
      
 
118
 
119
119
    # Preform the pathmap replacement operations on the given path. The
120
120
    # patterns take the form 'pat1,rep1;pat2,rep2...'.
121
121
    def pathmap_replace(patterns, &block)
203
203
        when '%f'
204
204
          result << File.basename(self)
205
205
        when '%n'
206
 
          result << File.basename(self, '.*')
 
206
          result << File.basename(self).ext
207
207
        when '%d'
208
208
          result << File.dirname(self)
209
209
        when '%x'
280
280
 
281
281
  end
282
282
 
283
 
  # ##########################################################################
 
283
  ####################################################################
284
284
  # Mixin for creating easily cloned objects.
285
285
  #
286
286
  module Cloneable
305
305
  end
306
306
 
307
307
  ####################################################################
 
308
  # Exit status class for times the system just gives us a nil.
 
309
  class PseudoStatus
 
310
    attr_reader :exitstatus
 
311
    def initialize(code=0)
 
312
      @exitstatus = code
 
313
    end
 
314
    def to_i
 
315
      @exitstatus << 8
 
316
    end
 
317
    def >>(n)
 
318
      to_i >> n
 
319
    end
 
320
    def stopped?
 
321
      false
 
322
    end
 
323
    def exited?
 
324
      true
 
325
    end
 
326
  end
 
327
 
 
328
  ####################################################################
308
329
  # TaskAguments manage the arguments passed to a task.
309
330
  #
310
331
  class TaskArguments
362
383
    def inspect
363
384
      to_s
364
385
    end
365
 
    
 
386
 
366
387
    protected
367
 
    
 
388
 
368
389
    def lookup(name)
369
390
      if @hash.has_key?(name)
370
391
        @hash[name]
434
455
 
435
456
module Rake
436
457
 
437
 
  # #########################################################################
 
458
  ###########################################################################
438
459
  # A Task is the basic unit of work in a Rakefile.  Tasks have associated
439
460
  # actions (possibly more than one) and a list of prerequisites.  When
440
461
  # invoked, a task will first ensure that all of its prerequisites have an
734
755
  end # class Rake::Task
735
756
 
736
757
 
737
 
  # #########################################################################
 
758
  ###########################################################################
738
759
  # A FileTask is a task that includes time based dependencies.  If any of a
739
760
  # FileTask's prerequisites have a timestamp that is later than the file
740
761
  # represented by this task, then the file must be rebuilt (using the
745
766
    # Is this file task needed?  Yes if it doesn't exist, or if its time stamp
746
767
    # is out of date.
747
768
    def needed?
748
 
      return true unless File.exist?(name)
749
 
      return true if out_of_date?(timestamp)
750
 
      false
 
769
      ! File.exist?(name) || out_of_date?(timestamp)
751
770
    end
752
771
 
753
772
    # Time stamp for file task.
778
797
    end
779
798
  end # class Rake::FileTask
780
799
 
781
 
  # #########################################################################
 
800
  ###########################################################################
782
801
  # A FileCreationTask is a file task that when used as a dependency will be
783
802
  # needed if and only if the file has not been created.  Once created, it is
784
803
  # not re-triggered if any of its dependencies are newer, nor does trigger
797
816
    end
798
817
  end
799
818
 
800
 
  # #########################################################################
 
819
  ###########################################################################
801
820
  # Same as a regular task, but the immediate prerequisites are done in
802
821
  # parallel using Ruby threads.
803
822
  #
812
831
  end
813
832
end # module Rake
814
833
 
815
 
# ###########################################################################
 
834
## ###########################################################################
816
835
# Task Definition Functions ...
817
836
 
818
837
# Declare a basic task.
931
950
  end
932
951
end
933
952
 
934
 
# ###########################################################################
 
953
#############################################################################
935
954
# This a FileUtils extension that defines several additional commands to be
936
955
# added to the FileUtils utility functions.
937
956
#
938
957
module FileUtils
939
 
  RUBY = File.join(Config::CONFIG['bindir'], Config::CONFIG['ruby_install_name']).
 
958
  RUBY_EXT = ((RbConfig::CONFIG['ruby_install_name'] =~ /\.(com|cmd|exe|bat|rb|sh)$/) ?
 
959
    "" :
 
960
    RbConfig::CONFIG['EXEEXT'])
 
961
 
 
962
  RUBY = File.join(
 
963
    RbConfig::CONFIG['bindir'],
 
964
    RbConfig::CONFIG['ruby_install_name'] + RUBY_EXT).
940
965
    sub(/.*\s.*/m, '"\&"')
941
966
 
942
967
  OPT_TABLE['sh']  = %w(noop verbose)
962
987
    options = (Hash === cmd.last) ? cmd.pop : {}
963
988
    unless block_given?
964
989
      show_command = cmd.join(" ")
965
 
      show_command = show_command[0,42] + "..."
 
990
      show_command = show_command[0,42] + "..." unless $trace
966
991
      # TODO code application logic heref show_command.length > 45
967
992
      block = lambda { |ok, status|
968
993
        ok or fail "Command failed with status (#{status.exitstatus}): [#{show_command}]"
969
994
      }
970
995
    end
971
996
    if RakeFileUtils.verbose_flag == :default
972
 
      options[:verbose] = false
 
997
      options[:verbose] = true
973
998
    else
974
999
      options[:verbose] ||= RakeFileUtils.verbose_flag
975
1000
    end
978
1003
    rake_output_message cmd.join(" ") if options[:verbose]
979
1004
    unless options[:noop]
980
1005
      res = rake_system(*cmd)
981
 
      block.call(res, $?)
 
1006
      status = $?
 
1007
      status = PseudoStatus.new(1) if !res && status.nil?
 
1008
      block.call(res, status)
982
1009
    end
983
1010
  end
984
1011
 
1031
1058
  end
1032
1059
end
1033
1060
 
1034
 
# ###########################################################################
 
1061
#############################################################################
1035
1062
# RakeFileUtils provides a custom version of the FileUtils methods that
1036
1063
# respond to the <tt>verbose</tt> and <tt>nowrite</tt> commands.
1037
1064
#
1162
1189
  extend self
1163
1190
end
1164
1191
 
1165
 
# ###########################################################################
 
1192
#############################################################################
1166
1193
# Include the FileUtils file manipulation functions in the top level module,
1167
1194
# but mark them private so that they don't unintentionally define methods on
1168
1195
# other objects.
1174
1201
######################################################################
1175
1202
module Rake
1176
1203
 
1177
 
  # #########################################################################
 
1204
  ###########################################################################
1178
1205
  # A FileList is essentially an array with a few helper methods defined to
1179
1206
  # make file manipulation a bit easier.
1180
1207
  #
1210
1237
 
1211
1238
    # List of array methods (that are not in +Object+) that need to be
1212
1239
    # delegated.
1213
 
    ARRAY_METHODS = (Array.instance_methods - Object.instance_methods).map { |n| n.to_s }
 
1240
    ARRAY_METHODS = (Array.instance_methods - (Object.instance_methods - [:<=>])).map { |n| n.to_s }
1214
1241
 
1215
1242
    # List of additional methods that must be delegated.
1216
1243
    MUST_DEFINE = %w[to_a inspect]
1232
1259
    # Now do the delegation.
1233
1260
    DELEGATING_METHODS.each_with_index do |sym, i|
1234
1261
      if SPECIAL_RETURN.include?(sym)
1235
 
        ln = __LINE__+1
1236
 
        class_eval %{
1237
 
          def #{sym}(*args, &block)
1238
 
            resolve
1239
 
            result = @items.send(:#{sym}, *args, &block)
1240
 
            FileList.new.import(result)
1241
 
          end
1242
 
        }, __FILE__, ln
 
1262
        define_method(sym) do |*args, &block|
 
1263
          resolve
 
1264
          result = @items.send(sym, *args, &block)
 
1265
          FileList.new.import(result)
 
1266
        end
1243
1267
      else
1244
 
        ln = __LINE__+1
1245
 
        class_eval %{
1246
 
          def #{sym}(*args, &block)
1247
 
            resolve
1248
 
            result = @items.send(:#{sym}, *args, &block)
1249
 
            result.object_id == @items.object_id ? self : result
1250
 
          end
1251
 
        }, __FILE__, ln
 
1268
        define_method(sym) do |*args, &block|
 
1269
          resolve
 
1270
          result = @items.send(sym, *args, &block)
 
1271
          result.object_id == @items.object_id ? self : result
 
1272
        end
1252
1273
      end
1253
1274
    end
1254
1275
 
1456
1477
      collect { |fn| fn.pathmap(spec) }
1457
1478
    end
1458
1479
 
1459
 
    # Return a new array with <tt>String#ext</tt> method applied to each
1460
 
    # member of the array.
 
1480
    # Return a new FileList with <tt>String#ext</tt> method applied
 
1481
    # to each member of the array.
1461
1482
    #
1462
1483
    # This method is a shortcut for:
1463
1484
    #
1474
1495
    # name, line number, and the matching line of text.  If no block is given,
1475
1496
    # a standard emac style file:linenumber:line message will be printed to
1476
1497
    # standard out.
1477
 
    def egrep(pattern, *opt)
 
1498
    def egrep(pattern, *options)
1478
1499
      each do |fn|
1479
 
        open(fn, "rb", *opt) do |inf|
 
1500
        open(fn, "rb", *options) do |inf|
1480
1501
          count = 0
1481
1502
          inf.each do |line|
1482
1503
            count += 1
1582
1603
# Alias FileList to be available at the top level.
1583
1604
FileList = Rake::FileList
1584
1605
 
1585
 
# ###########################################################################
 
1606
#############################################################################
1586
1607
module Rake
1587
1608
 
1588
1609
  # Default Rakefile loader used by +import+.
1609
1630
  EARLY = EarlyTime.instance
1610
1631
end # module Rake
1611
1632
 
1612
 
# ###########################################################################
 
1633
#############################################################################
1613
1634
# Extensions to time to allow comparisons with an early time class.
1614
1635
#
1615
1636
class Time
1643
1664
      @task_manager.lookup(name, @scope)
1644
1665
    end
1645
1666
 
1646
 
    # Return the list of tasks defined in this namespace.
 
1667
    # Return the list of tasks defined in this and nested namespaces.
1647
1668
    def tasks
1648
 
      @task_manager.tasks
 
1669
      @task_manager.tasks_in_scope(@scope)
1649
1670
    end
1650
1671
  end # NameSpace
1651
1672
 
1734
1755
      [task_name, arg_names, []]
1735
1756
    end
1736
1757
    private :resolve_args_without_dependencies
1737
 
    
 
1758
 
1738
1759
    # Resolve task arguments for a task or rule when there are
1739
1760
    # dependencies declared.
1740
1761
    #
1765
1786
      [task_name, arg_names, deps]
1766
1787
    end
1767
1788
    private :resolve_args_with_dependencies
1768
 
    
 
1789
 
1769
1790
    # If a rule can be found that matches the task name, enhance the
1770
1791
    # task with the prerequisites and actions from the rule.  Set the
1771
1792
    # source attribute of the task appropriately for the rule.  Return
1790
1811
      @tasks.values.sort_by { |t| t.name }
1791
1812
    end
1792
1813
 
 
1814
    # List of all the tasks defined in the given scope (and its
 
1815
    # sub-scopes).
 
1816
    def tasks_in_scope(scope)
 
1817
      prefix = scope.join(":")
 
1818
      tasks.select { |t|
 
1819
        /^#{prefix}:/ =~ t.name
 
1820
      }
 
1821
    end
 
1822
 
1793
1823
    # Clear all tasks in this application.
1794
1824
    def clear
1795
1825
      @tasks.clear
1957
1987
    # application.  The define any tasks.  Finally, call +top_level+ to run your top
1958
1988
    # level tasks.
1959
1989
    def run
1960
 
      standard_exception_handling do
1961
 
        init
1962
 
        load_rakefile
1963
 
        top_level
1964
 
      end
 
1990
      init
 
1991
      load_rakefile
 
1992
      top_level
1965
1993
    end
1966
1994
 
1967
1995
    # Initialize the command line parameters and app name.
1968
1996
    def init(app_name='rake')
1969
1997
      standard_exception_handling do
1970
1998
        @name = app_name
1971
 
        collect_tasks handle_options
 
1999
        handle_options
 
2000
        collect_tasks
1972
2001
      end
1973
2002
    end
1974
2003
 
2035
2064
        exit(false)
2036
2065
      rescue Exception => ex
2037
2066
        # Exit with error message
2038
 
        $stderr.puts "rake aborted!"
 
2067
        $stderr.puts "#{name} aborted!"
2039
2068
        $stderr.puts ex.message
2040
 
        if options.trace
 
2069
        if options.trace or true
2041
2070
          $stderr.puts ex.backtrace.join("\n")
2042
2071
        else
2043
2072
          $stderr.puts ex.backtrace.find {|str| str =~ /#{@rakefile}/ } || ""
2051
2080
    # If a match is found, it is copied into @rakefile.
2052
2081
    def have_rakefile
2053
2082
      @rakefiles.each do |fn|
2054
 
        if File.exist?(fn) || fn == ''
 
2083
        if File.exist?(fn)
 
2084
          others = Dir.glob(fn, File::FNM_CASEFOLD)
 
2085
          return others.size == 1 ? others.first : fn
 
2086
        elsif fn == ''
2055
2087
          return fn
2056
2088
        end
2057
2089
      end
2074
2106
      tty_output? || ENV['RAKE_COLUMNS']
2075
2107
    end
2076
2108
 
2077
 
    # Display the tasks and dependencies.
 
2109
    # Display the tasks and comments.
2078
2110
    def display_tasks_and_comments
2079
2111
      displayable_tasks = tasks.select { |t|
2080
2112
        t.comment && t.name =~ options.show_task_pattern
2081
2113
      }
2082
2114
      if options.full_description
2083
2115
        displayable_tasks.each do |t|
2084
 
          puts "rake #{t.name_with_args}"
 
2116
          puts "#{name} #{t.name_with_args}"
2085
2117
          t.full_comment.split("\n").each do |line|
2086
2118
            puts "    #{line}"
2087
2119
          end
2108
2140
      80
2109
2141
    end
2110
2142
 
2111
 
    # Calculate the dynamic width of the 
 
2143
    # Calculate the dynamic width of the
2112
2144
    def dynamic_width
2113
2145
      @dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput)
2114
2146
    end
2124
2156
    def unix?
2125
2157
      RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
2126
2158
    end
2127
 
    
 
2159
 
2128
2160
    def windows?
2129
2161
      Win32.windows?
2130
2162
    end
2140
2172
    # Display the tasks and prerequisites
2141
2173
    def display_prerequisites
2142
2174
      tasks.each do |t|
2143
 
        puts "rake #{t.name}"
 
2175
        puts "#{name} #{t.name}"
2144
2176
        t.prerequisites.each { |pre| puts "    #{pre}" }
2145
2177
      end
2146
2178
    end
2184
2216
        ],
2185
2217
        ['--execute-continue',  '-E CODE',
2186
2218
          "Execute some Ruby code, then continue with normal task processing.",
2187
 
          lambda { |value| eval(value) }            
 
2219
          lambda { |value| eval(value) }
2188
2220
        ],
2189
2221
        ['--libdir', '-I LIBDIR', "Include LIBDIR in the search path for required modules.",
2190
2222
          lambda { |value| $:.push(value) }
2196
2228
          lambda { |value| verbose(false) }
2197
2229
        ],
2198
2230
        ['--rakefile', '-f [FILE]', "Use FILE as the rakefile.",
2199
 
          lambda { |value| 
 
2231
          lambda { |value|
2200
2232
            value ||= ''
2201
 
            @rakefiles.clear 
 
2233
            @rakefiles.clear
2202
2234
            @rakefiles << value
2203
2235
          }
2204
2236
        ],
2252
2284
            verbose(true)
2253
2285
          }
2254
2286
        ],
2255
 
        ['--verbose', '-v', "Log message to standard output (default).",
 
2287
        ['--verbose', '-v', "Log message to standard output.",
2256
2288
          lambda { |value| verbose(true) }
2257
2289
        ],
2258
2290
        ['--version', '-V', "Display the program version.",
2268
2300
    def handle_options
2269
2301
      options.rakelib = ['rakelib']
2270
2302
 
2271
 
      opts = OptionParser.new
2272
 
      opts.banner = "rake [-f rakefile] {options} targets..."
2273
 
      opts.separator ""
2274
 
      opts.separator "Options are ..."
2275
 
      
2276
 
      opts.on_tail("-h", "--help", "-H", "Display this help message.") do
2277
 
        puts opts
2278
 
        exit
2279
 
      end
2280
 
      
2281
 
      standard_rake_options.each { |args| opts.on(*args) }
2282
 
      parsed_argv = opts.parse(ARGV)
 
2303
      OptionParser.new do |opts|
 
2304
        opts.banner = "rake [-f rakefile] {options} targets..."
 
2305
        opts.separator ""
 
2306
        opts.separator "Options are ..."
 
2307
 
 
2308
        opts.on_tail("-h", "--help", "-H", "Display this help message.") do
 
2309
          puts opts
 
2310
          exit
 
2311
        end
 
2312
 
 
2313
        standard_rake_options.each { |args| opts.on(*args) }
 
2314
      end.parse!
2283
2315
 
2284
2316
      # If class namespaces are requested, set the global options
2285
2317
      # according to the values in the options structure.
2290
2322
        $dryrun = options.dryrun
2291
2323
        $silent = options.silent
2292
2324
      end
2293
 
      parsed_argv
2294
2325
    end
2295
2326
 
2296
2327
    # Similar to the regular Ruby +require+ command, but will check
2356
2387
 
2357
2388
    # The directory path containing the system wide rakefiles.
2358
2389
    def system_dir
2359
 
      @system_dir ||=
2360
 
        begin
2361
 
          if ENV['RAKE_SYSTEM']
2362
 
            ENV['RAKE_SYSTEM']
2363
 
          else
2364
 
            standard_system_dir
2365
 
          end
2366
 
        end
 
2390
      @system_dir ||= ENV['RAKE_SYSTEM'] || standard_system_dir
2367
2391
    end
2368
 
    
 
2392
 
2369
2393
    # The standard directory containing system wide rake files.
2370
 
    if Win32.windows?
2371
 
      def standard_system_dir #:nodoc:
2372
 
        Win32.win32_system_dir
2373
 
      end
2374
 
    else
2375
 
      def standard_system_dir #:nodoc:
2376
 
        File.expand_path('.rake', '~')
 
2394
    unless method_defined?(:standard_system_dir)
 
2395
      def standard_system_dir #:nodoc:
 
2396
        File.expand_path('~/.rake')
2377
2397
      end
2378
2398
    end
2379
2399
    private :standard_system_dir
2381
2401
    # Collect the list of tasks on the command line.  If no tasks are
2382
2402
    # given, return a list containing only the default task.
2383
2403
    # Environmental assignments are processed at this time as well.
2384
 
    def collect_tasks(argv)
 
2404
    def collect_tasks
2385
2405
      @top_level_tasks = []
2386
 
      argv.each do |arg|
 
2406
      ARGV.each do |arg|
2387
2407
        if arg =~ /^(\w+)=(.*)$/
2388
2408
          ENV[$1] = $2
2389
2409
        else