Rake (software)

Last updated
Rake
Developer(s) Jim Weirich
Stable release
13.2.1 [1] / April 5, 2024;2 months ago (2024-04-05)
Repository
Written in Ruby
Operating system Cross-platform
Type Software development tools
License MIT License
Website ruby.github.io/rake/

Rake is a software task management and a build automation tool created by Jim Weirich. It allows the user to specify tasks and to describe dependencies as well as to group tasks into namespaces. It is similar to SCons and Make. Rake was written in Ruby and has been part of the standard library of Ruby since version 1.9. [2] [3]

Contents

Examples

The tasks that should be executed need to be defined in a configuration file called Rakefile. A Rakefile has no special syntax and contains executable Ruby code. [4]

Tasks

The basic unit in Rake is the task. A task has a name and an action block, that defines its functionality. The following code defines a task called greet that will output the text "Hello, Rake!" to the console. [5]

task:greetdoputs"Hello, Rake!"end

When defining a task, you can optionally add dependencies, that is one task can depend on the successful completion of another task. Calling the "seed" task from the following example will first execute the "migrate" task and only then proceed with the execution of the "seed" task. [5]

task:seed=>:migratedo# This task will run after the :migrate taskend

Tasks can also be made more versatile by accepting arguments. For example, the "generate_report" task will take a date as argument. If no argument is supplied the current date is used. [5]

task:generate_report,[:date]do|t,args|report_date=args[:date]||Date.today# Generate the report based on the specified dateend

A special type of task is the file task, which can be used to specify file creation tasks. The following task, for example, is given two object files, i.e. "a.o" and "b.o", to create an executable program. [6]

file"prog"=>["a.o","b.o"]do|t|sh"cc -o #{t.name}#{t.prerequisites.join(' ')}"end

Another useful tool is the directory convenience method, that can be used to create directories upon demand. [7]

directory"testdata/examples/doc"

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:

rule'.o'=>'.c'do|t|sh"cc #{t.source} -c -o #{t.name}"end

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. [8]

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:

rule(/\.o$/=>->(t_name){t_name.sub/\.o$/,'.c'})do|t|sh"cc #{t.source} -c -o #{t.name}"end

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: [9]

rule'.class'=>->(t_name){t_name.sub(/\.class$/,'.java').sub(/^classes\//,'src/')}do|t|java_compile(t.source,t.name)end

Namespaces

To better organize big Rakefiles, tasks can be grouped into namespaces. [10] Below is an example of a simple Rake recipe:

namespace:cakedodesc'make pancakes'task:pancake=>[:flour,:milk,:egg,:baking_powder]doputs"sizzle"endtask:butterdoputs"cut 3 tablespoons of butter into tiny squares"endtask:flour=>:butterdoputs"use hands to knead butter squares into 1 1/2 cup flour"endtask:milkdoputs"add 1 1/4 cup milk"endtask:eggdoputs"add 1 egg"endtask:baking_powderdoputs"add 3 1/2 teaspoons baking powder"endend

See also

Related Research Articles

The Comprehensive Perl Archive Network (CPAN) is a repository of over 250,000 software modules and accompanying documentation for 39,000 distributions, written in the Perl programming language by over 12,000 contributors. CPAN can denote either the archive network or the Perl program that acts as an interface to the network and as an automated software installer. Most software on CPAN is free and open source software.

<span class="mw-page-title-main">Quine (computing)</span> Self-replicating program

A quine is a computer program that takes no input and produces a copy of its own source code as its only output. The standard terms for these programs in the computability theory and computer science literature are "self-replicating programs", "self-reproducing programs", and "self-copying programs".

In software development, Make is a command-line interface (CLI) software tool that performs actions ordered by configured dependencies as defined in a configuration file called a makefile. It is commonly used for build automation to build executable code from source code. But, not limited to building, Make can perform any operation available via the operating system shell.

<span class="mw-page-title-main">D (programming language)</span> Multi-paradigm system programming language

D, also known as dlang, is a multi-paradigm system programming language created by Walter Bright at Digital Mars and released in 2001. Andrei Alexandrescu joined the design and development effort in 2007. Though it originated as a re-engineering of C++, D is now a very different language drawing inspiration from other high-level programming languages, notably Java, Python, Ruby, C#, and Eiffel.

Cairo (graphics) Vector graphics-based software library

Cairo is an open-source graphics library that provides a vector graphics-based, device-independent API for software developers. It provides primitives for two-dimensional drawing across a number of different backends. Cairo uses hardware acceleration when available.

In computer programming, an entry point is the place in a program where the execution of a program begins, and where the program has access to command line arguments.

Windows Presentation Foundation (WPF) is a free and open-source user interface framework for Windows-based desktop applications. WPF applications are based in .NET, and are primarily developed using C# and XAML.

<span class="mw-page-title-main">Capistrano (software)</span>

Capistrano is an open-source tool for running scripts on multiple servers; its main use is deploying web applications. It automates the process of making a new version of an application available on one or more web servers, including supporting tasks such as changing databases.

<span class="mw-page-title-main">Markdown</span> Plain text markup language

Markdown is a lightweight markup language for creating formatted text using a plain-text editor. John Gruber created Markdown in 2004, in collaboration with Aaron Swartz, as a markup language that is intended to be easy to read in its source code form. Markdown is widely used for blogging and instant messaging, and also used elsewhere in online forums, collaborative software, documentation pages, and readme files.

RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries, a tool designed to easily manage the installation of gems, and a server for distributing them. It was created by Chad Fowler, Jim Weirich, David Alan Black, Paul Brannan and Richard Kilmer during RubyConf 2004.

FluidSynth, formerly named iiwusynth, is a free open source software synthesizer which converts MIDI note data into an audio signal using SoundFont technology without need for a SoundFont-compatible soundcard. FluidSynth can act as a virtual MIDI device, able to receive MIDI data from any program and transform it into audio on-the-fly. It can also read in SMF (.mid) files directly. On the output side, it can send audio data directly to an audio device for playback, or to a Raw or Wave file. It can also convert a SMF file directly to an audio file in faster-than-real-time. The combination of these features gives FluidSynth the following major use cases:

<span class="mw-page-title-main">Cosmos (operating system)</span> Toolkit for building GUI and command-line based operating systems

C# Open Source Managed Operating System (Cosmos) is a toolkit for building GUI and command-line based operating systems, written mostly in the programming language C# and small amounts of a high-level assembly language named X#. Cosmos is a backronym, in that the acronym was chosen before the meaning. It is open-source software released under a BSD license.

Protocol Buffers (Protobuf) is a free and open-source cross-platform data format used to serialize structured data. It is useful in developing programs that communicate with each other over a network or for storing data. The method involves an interface description language that describes the structure of some data and a program that generates source code from that description for generating or parsing a stream of bytes that represents the structured data.

<span class="mw-page-title-main">Apache Avro</span> Open-source remote procedure call framework

Avro is a row-oriented remote procedure call and data serialization framework developed within Apache's Hadoop project. It uses JSON for defining data types and protocols, and serializes data in a compact binary format. Its primary use is in Apache Hadoop, where it can provide both a serialization format for persistent data, and a wire format for communication between Hadoop nodes, and from client programs to the Hadoop services. Avro uses a schema to structure the data that is being encoded. It has two different types of schema languages: one for human editing and another which is more machine-readable based on JSON.

Cucumber is a software tool that supports behavior-driven development (BDD). Central to the Cucumber BDD approach is its ordinary language parser called Gherkin. It allows expected software behaviors to be specified in a logical language that customers can understand. As such, Cucumber allows the execution of feature documentation written in business-facing text. It is often used for testing other software. It runs automated acceptance tests written in a behavior-driven development (BDD) style.

Elixir is a functional, concurrent, high-level general-purpose programming language that runs on the BEAM virtual machine, which is also used to implement the Erlang programming language. Elixir builds on top of Erlang and shares the same abstractions for building distributed, fault-tolerant applications. Elixir also provides tooling and an extensible design. The latter is supported by compile-time metaprogramming with macros and polymorphism via protocols.

<span class="mw-page-title-main">Nim (programming language)</span> Programming language

Nim is a general-purpose, multi-paradigm, statically typed, compiled high-level systems programming language, designed and developed by a team around Andreas Rumpf. Nim is designed to be "efficient, expressive, and elegant", supporting metaprogramming, functional, message passing, procedural, and object-oriented programming styles by providing several features such as compile time code generation, algebraic data types, a foreign function interface (FFI) with C, C++, Objective-C, and JavaScript, and supporting compiling to those same languages as intermediate representations.

gulp is an open-source JavaScript toolkit, used as a streaming build system in front-end web development.

FlatBuffers is a free software library implementing a serialization format similar to Protocol Buffers, Thrift, Apache Avro, SBE, and Cap'n Proto, primarily written by Wouter van Oortmerssen and open-sourced by Google. It supports “zero-copy” deserialization, so that accessing the serialized data does not require first copying it into a separate part of memory. This makes accessing data in these formats much faster than data in formats requiring more extensive processing, such as JSON, CSV, and in many cases Protocol Buffers. Compared to other serialization formats however, the handling of FlatBuffers requires usually more code, and some operations are not possible.

References

  1. "Release v13.2.1 · ruby/rake · GitHub". GitHub. April 5, 2024. Retrieved June 21, 2024.
  2. "Rake -- Ruby Make". n.d. Retrieved February 28, 2024.
  3. "NEWS". n.d. Archived from the original on March 4, 2016. Retrieved February 29, 2024.
  4. "Rakefile Format". GitHub. Retrieved 2024-06-21.
  5. 1 2 3 "Ruby on Rails Tutorial: Understanding Rake and Task Automation". 2019-06-10. Retrieved 2024-06-21.
  6. "Rakefile Format # File Tasks". GitHub. Retrieved 2024-06-21.
  7. "Rakefile Format # Direcpory Tasks". GitHub. Retrieved 2024-06-21.
  8. "Rakefile Format # Rules". GitHub. Retrieved 2024-06-21.
  9. "Rakefile Format # Advanced Rules". GitHub. Retrieved 2024-06-21.
  10. "Rakefile Format # Namespaces". GitHub. Retrieved 2024-06-21.