[b]参考教程[/b]
[list]
[*][url]http://jasonseifer.com/2010/04/06/rake-tutorial[/url]
[/list]
[b]hello rake[/b]
[b]namespace[/b]
[b]task description[/b]
[b]redefined task[/b]
[b]invoking other task[/b]
[b]task dependencies[/b]
[b]task arguments[/b]
[b]multitask[/b]
Declare a task that performs its prerequisites in parallel. Multitasks does not guarantee that its prerequisites will execute in any given order (which is obvious when you think about it)
[b]mkdir task[/b]
[b]rule task[/b]
[list]
[*][url]http://jasonseifer.com/2010/04/06/rake-tutorial[/url]
[/list]
[b]hello rake[/b]
#rakefile.rb
task :default => [:hello]
task :hello do
puts 'hello rake'
end
#$ rake
#$ rake hello
#$ rake rakefile.rb
[b]namespace[/b]
task :default => "morning:turn_of_alarm"
namespace :morning do
task :turn_of_alarm do
puts 'ding...'
end
end
#$rake moring:turn_of_alarm
[b]task description[/b]
desc "description of task "
task :hello do
end
#$ rake -T
#=>
# rake hello # description of task
[b]redefined task[/b]
task :default => 'morning:turn_of_alarm'
namespace :morning do
desc "turn of alarm"
task :turn_of_alarm do
puts 'hello'
end
end
namespace :morning do
task :turn_of_alarm do
puts 'world'
end
end
#$ rake
#=>
# hello
# world
[b]invoking other task[/b]
task :default => 'task:world'
namespace :task do
desc "hello world"
task :hello do
puts 'hello'
end
end
namespace :task do
task :world do
puts '...'
Rake::Task['task:hello'].invoke
puts 'world'
end
end
#Rake::Task['task:hello'].invoke(args.args_name)
[b]task dependencies[/b]
task :default => 'task:world'
namespace :task do
task :hello do
puts 'hello'
end
end
namespace :task do
task :world => :hello do
puts 'world'
end
end
[b]task arguments[/b]
task :say, [:name,:gender] do |t, args|
args.with_defaults(:name=>'john',:gender=>'boy')
puts "hello #{args.name} #{args.gender}"
end
#rake say[Lucy,girl]
[b]multitask[/b]
Declare a task that performs its prerequisites in parallel. Multitasks does not guarantee that its prerequisites will execute in any given order (which is obvious when you think about it)
multitask :deploy => [:deploy_gem, :deploy_rdoc]
[b]mkdir task[/b]
directory "tmp/abc"
#rake tmp/abc
#mkdir -p tmp/abc
#执行前会先建立tmp/abc
task :task_a => "tmp/abc" do
end
[b]rule task[/b]
rule '.o' => ['.c'] do |t|
sh "cp #{t.source} #{t.name}"
end
#touch a.c
#rake a.o
#cp a.c a.o
#t.source指a.c, t.name是a.o