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

« back to all changes in this revision

Viewing changes to lib/rake/dsl_definition.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Rake DSL functions.
 
2
require 'rake/file_utils_ext'
 
3
 
 
4
module Rake
 
5
 
 
6
  ##
 
7
  # DSL is a module that provides #task, #desc, #namespace, etc.  Use this
 
8
  # when you'd like to use rake outside the top level scope.
 
9
 
 
10
  module DSL
 
11
 
 
12
    #--
 
13
    # Include the FileUtils file manipulation functions in the top
 
14
    # level module, but mark them private so that they don't
 
15
    # unintentionally define methods on other objects.
 
16
    #++
 
17
 
 
18
    include FileUtilsExt
 
19
    private(*FileUtils.instance_methods(false))
 
20
    private(*FileUtilsExt.instance_methods(false))
 
21
 
 
22
    private
 
23
 
 
24
    # Declare a basic task.
 
25
    #
 
26
    # Example:
 
27
    #   task :clobber => [:clean] do
 
28
    #     rm_rf "html"
 
29
    #   end
 
30
    #
 
31
    def task(*args, &block)
 
32
      Rake::Task.define_task(*args, &block)
 
33
    end
 
34
 
 
35
 
 
36
    # Declare a file task.
 
37
    #
 
38
    # Example:
 
39
    #   file "config.cfg" => ["config.template"] do
 
40
    #     open("config.cfg", "w") do |outfile|
 
41
    #       open("config.template") do |infile|
 
42
    #         while line = infile.gets
 
43
    #           outfile.puts line
 
44
    #         end
 
45
    #       end
 
46
    #     end
 
47
    #  end
 
48
    #
 
49
    def file(*args, &block)
 
50
      Rake::FileTask.define_task(*args, &block)
 
51
    end
 
52
 
 
53
    # Declare a file creation task.
 
54
    # (Mainly used for the directory command).
 
55
    def file_create(args, &block)
 
56
      Rake::FileCreationTask.define_task(args, &block)
 
57
    end
 
58
 
 
59
    # Declare a set of files tasks to create the given directories on
 
60
    # demand.
 
61
    #
 
62
    # Example:
 
63
    #   directory "testdata/doc"
 
64
    #
 
65
    def directory(dir)
 
66
      Rake.each_dir_parent(dir) do |d|
 
67
        file_create d do |t|
 
68
          mkdir_p t.name if ! File.exist?(t.name)
 
69
        end
 
70
      end
 
71
    end
 
72
 
 
73
    # Declare a task that performs its prerequisites in
 
74
    # parallel. Multitasks does *not* guarantee that its prerequisites
 
75
    # will execute in any given order (which is obvious when you think
 
76
    # about it)
 
77
    #
 
78
    # Example:
 
79
    #   multitask :deploy => [:deploy_gem, :deploy_rdoc]
 
80
    #
 
81
    def multitask(args, &block)
 
82
      Rake::MultiTask.define_task(args, &block)
 
83
    end
 
84
 
 
85
    # Create a new rake namespace and use it for evaluating the given
 
86
    # block.  Returns a NameSpace object that can be used to lookup
 
87
    # tasks defined in the namespace.
 
88
    #
 
89
    # E.g.
 
90
    #
 
91
    #   ns = namespace "nested" do
 
92
    #     task :run
 
93
    #   end
 
94
    #   task_run = ns[:run] # find :run in the given namespace.
 
95
    #
 
96
    def namespace(name=nil, &block)
 
97
      name = name.to_s if name.kind_of?(Symbol)
 
98
      name = name.to_str if name.respond_to?(:to_str)
 
99
      unless name.kind_of?(String) || name.nil?
 
100
        raise ArgumentError, "Expected a String or Symbol for a namespace name"
 
101
      end
 
102
      Rake.application.in_namespace(name, &block)
 
103
    end
 
104
 
 
105
    # Declare a rule for auto-tasks.
 
106
    #
 
107
    # Example:
 
108
    #  rule '.o' => '.c' do |t|
 
109
    #    sh %{cc -o #{t.name} #{t.source}}
 
110
    #  end
 
111
    #
 
112
    def rule(*args, &block)
 
113
      Rake::Task.create_rule(*args, &block)
 
114
    end
 
115
 
 
116
    # Describe the next rake task.
 
117
    #
 
118
    # Example:
 
119
    #   desc "Run the Unit Tests"
 
120
    #   task :test => [:build]
 
121
    #     runtests
 
122
    #   end
 
123
    #
 
124
    def desc(description)
 
125
      Rake.application.last_description = description
 
126
    end
 
127
 
 
128
    # Import the partial Rakefiles +fn+.  Imported files are loaded
 
129
    # _after_ the current file is completely loaded.  This allows the
 
130
    # import statement to appear anywhere in the importing file, and yet
 
131
    # allowing the imported files to depend on objects defined in the
 
132
    # importing file.
 
133
    #
 
134
    # A common use of the import statement is to include files
 
135
    # containing dependency declarations.
 
136
    #
 
137
    # See also the --rakelibdir command line option.
 
138
    #
 
139
    # Example:
 
140
    #   import ".depend", "my_rules"
 
141
    #
 
142
    def import(*fns)
 
143
      fns.each do |fn|
 
144
        Rake.application.add_import(fn)
 
145
      end
 
146
    end
 
147
 
 
148
  end
 
149
 
 
150
  DeprecatedCommands = Object.new.extend(DSL)
 
151
 
 
152
  module DeprecatedObjectDSL # :nodoc:
 
153
    DSL.private_instance_methods(false).each do |name|
 
154
      line = __LINE__+1
 
155
      class_eval %{
 
156
        def #{name}(*args, &block)
 
157
          unless Rake.application.options.ignore_deprecate
 
158
            unless @rake_dsl_warning
 
159
              $stderr.puts "WARNING: Global access to Rake DSL methods is deprecated.  Please include"
 
160
              $stderr.puts "    ...  Rake::DSL into classes and modules which use the Rake DSL methods."
 
161
              @rake_dsl_warning = true
 
162
            end
 
163
            $stderr.puts "WARNING: DSL method \#{self.class}##{name} called at \#{caller.first}"
 
164
          end
 
165
          Rake::DeprecatedCommands.send(:#{name}, *args, &block)
 
166
        end
 
167
        private :#{name}
 
168
      }, __FILE__, line
 
169
    end
 
170
  end
 
171
 
 
172
  extend FileUtilsExt
 
173
end
 
174
 
 
175
self.extend Rake::DSL
 
176
include Rake::DeprecatedObjectDSL