Rahul Sharma (Editor)

Rake (software)

Updated on
Edit
Like
Comment
Share on FacebookTweet on TwitterShare on LinkedInShare on Reddit
Developer(s)
  
Jim Weirich

Written in
  
Ruby

Repository
  
github.com/ruby/rake

Operating system
  
Cross-platform

Stable release
  
11.1.2 / March 27, 2016; 11 months ago (2016-03-27)

Type
  
Software development tools

Rake is a software task management and build automation tool. It allows the user to specify tasks and describe dependencies as well as to group tasks in a namespace.

Contents

It is similar to SCons and Make, but it has a number of differences. The tool is written in the Ruby programming language and the Rakefiles (equivalent of Makefiles in Make) use Ruby syntax. It was originated by Jim Weirich.

Rake uses Ruby's anonymous function blocks to define various tasks, allowing the use of Ruby syntax. It has a library of common tasks: for example, functions to do common file-manipulation tasks and a library to remove compiled files (the "clean" task). Like Make, Rake can also synthesize tasks based on patterns: for example, automatically building a file compilation task based on filename patterns. Rake is now part of the standard library from Ruby version 1.9 onward.

Example

Below is an example of a simple Rake script to build a C Hello World program.

For further examples, see the Rakefile format documentation.

Rules

When a file is named as a prerequisite but it does not have a file task defined for it, Rake will attempt to synthesize a task by looking at a list of rules supplied in the Rakefile. For example, suppose we were trying to invoke task "mycode.o" with no tasks defined for it. If the Rakefile has a rule that looks like this:

This rule will synthesize any task that ends in ".o". It has as a prerequisite that a source file with an extension of ".c" must exist. If Rake is able to find a file named "mycode.c", it will automatically create a task that builds "mycode.o" from "mycode.c". If the file "mycode.c" does not exist, Rake will attempt to recursively synthesize a rule for it.

When a task is synthesized from a rule, the source attribute of the task is set to the matching source file. This allows users to write rules with actions that reference the source file.

Advanced rules

Any regular expression may be used as the rule pattern. Additionally, a proc may be used to calculate the name of the source file. This allows for complex patterns and sources.

The following rule is equivalent to the example above:

NOTE: Because of a quirk in Ruby syntax, parentheses are required around a rule when the first argument is a regular expression.

The following rule might be used for Java files:

Below is an example of a simple Rake recipe:

References

Rake (software) Wikipedia