2
require 'rake/file_utils_ext'
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.
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.
19
private(*FileUtils.instance_methods(false))
20
private(*FileUtilsExt.instance_methods(false))
24
# Declare a basic task.
27
# task :clobber => [:clean] do
31
def task(*args, &block)
32
Rake::Task.define_task(*args, &block)
36
# Declare a file task.
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
49
def file(*args, &block)
50
Rake::FileTask.define_task(*args, &block)
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)
59
# Declare a set of files tasks to create the given directories on
63
# directory "testdata/doc"
66
Rake.each_dir_parent(dir) do |d|
68
mkdir_p t.name if ! File.exist?(t.name)
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
79
# multitask :deploy => [:deploy_gem, :deploy_rdoc]
81
def multitask(args, &block)
82
Rake::MultiTask.define_task(args, &block)
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.
91
# ns = namespace "nested" do
94
# task_run = ns[:run] # find :run in the given namespace.
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"
102
Rake.application.in_namespace(name, &block)
105
# Declare a rule for auto-tasks.
108
# rule '.o' => '.c' do |t|
109
# sh %{cc -o #{t.name} #{t.source}}
112
def rule(*args, &block)
113
Rake::Task.create_rule(*args, &block)
116
# Describe the next rake task.
119
# desc "Run the Unit Tests"
120
# task :test => [:build]
124
def desc(description)
125
Rake.application.last_description = description
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
134
# A common use of the import statement is to include files
135
# containing dependency declarations.
137
# See also the --rakelibdir command line option.
140
# import ".depend", "my_rules"
144
Rake.application.add_import(fn)
150
DeprecatedCommands = Object.new.extend(DSL)
152
module DeprecatedObjectDSL # :nodoc:
153
DSL.private_instance_methods(false).each do |name|
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
163
$stderr.puts "WARNING: DSL method \#{self.class}##{name} called at \#{caller.first}"
165
Rake::DeprecatedCommands.send(:#{name}, *args, &block)
175
self.extend Rake::DSL
176
include Rake::DeprecatedObjectDSL