Contents |
rake -T List available tasks for a Rakefile rake -n Dry run - do nothing but list actions rake -s Suppress confusing directory messages
task :default => :hello
desc "This task prints out a 'hello world' message"
task :hello do
puts "hello world"
end
Tasks are created using this syntax:
task :doSomething => :prereq1
A more elaborate example, where 't' is a reference to the task, and the closure may call Rake::Task methods on it:
task :doSomething => [:prereq1, :prereq2] do |t|
... # you could call t.name to get 'doSomething'
end
or
How to create some file
file "somefile" do |t| ... t.name end
Example C++ rule
rule '.o' => ['.cpp'] do |t|
sh "g++ #{t.source} -c -o #{t.name}"
end
require 'rake/clean'
CLEAN.include('*.{o,tmp}')
CLOBBER.include('myprogram')
This example includes dependency on a set of files and a directory and removing them when cleaning.
require 'rake/clean'
require 'find'
# clean by removing this dir
CLEAN.include 'testFiles'
# generates an array with 10 'testFiles/tempFile[n]' files
TEMPFILES = (0..9).collect { |x| "testFiles/tempFile#{x}" }
# create this if needed
directory 'testFiles'
task :default => :generate
desc "Generate 10 empty files in testFiles/."
task :generate => ['testFiles'] + TEMPFILES
# How to generate a tempFile
rule( /testFiles\/tempFile.$/ ) do |t|
touch t.name
end
require 'rake/clean'
task :default => [ 'slides.pdf', :clean ]
# DEPENDENCIES ---------------------------------------------------------------
PUBLISH_TARGET="/home/schmid/web/schmid.dk/htdocs/slides.pdf"
FIGURES=FileList['*.svg']
PDF_FIGURES=FIGURES.ext('pdf')
file 'slides.pdf' => ['slides.tex', 'preamble.tex', 'Rakefile'] + PDF_FIGURES
# OPTIONS --------------------------------------------------------------------
LATEX_OPTIONS="--quiet"
# HOUSECLEANING --------------------------------------------------------------
CLEAN.include('*.{aux,snm,toc,nav,out}')
CLOBBER.include('slides.pdf', PDF_FIGURES)
# COMPILING ------------------------------------------------------------------
rule '.pdf' => '.tex' do |t| # rule: object files are made from source files
sh "pdflatex #{LATEX_OPTIONS} #{t.source}"
sh "pdflatex #{LATEX_OPTIONS} #{t.source}"
sh "pdflatex #{LATEX_OPTIONS} #{t.source}"
end
# GRAPHICS CONVERSION --------------------------------------------------------
rule '.pdf' => '.svg' do |t|
sh "convert #{t.source} #{t.name}"
end
rule '.pdf' => '.png' do |t|
sh "convert #{t.source} #{t.name}"
end
require 'socket' case Socket::gethostname when 'host1' ... else ... end
task :default do
sh 'cd largeScale && rake'
sh 'cd smallArea && rake'
end
- see Windows Tools page
wget http://rubyforge.org/frs/download.php/9500/rake-0.7.1.zip unzip -j rake-0.7.1.zip rake-0.7.1/lib/rake.rb rm rake-0.7.1.zip
:set makeprg=rake :mak