4.1 Tasks

Tasks are a high-level user interface for performing functionality in a build script. Tasks can create Environments that perform compilation/linking steps. Tasks can also execute arbitrary commands or perform any miscellaneous logic.

Tasks can have dependencies, which are specified as names of other tasks that should be executed before this task executes.

Tasks can have action blocks. When a task is executed, all of its action blocks are called in the order in which they were added.

Example:

proj_env = env do |env|
  env.Program("^/proj.elf", glob("src/**/*.c"))
end

task "flash" do
  sh "nrfjprog", "-f", "NRF52", "--program", proj_env.expand("^/proj.elf")
end

In this example, the flash task would first build the proj.elf target and then flash it to target with the nrfjprog program.

If the task method is called again with the name of an already existing task, the task is not overwritten, but rather modified. Any newly specified dependencies are added to the current dependencies. Any action block is appended to the task's list of action blocks to execute when the task is executed.

For example, with the Rsconscript:

task "a" do
  puts "A"
end

task "b" do
  puts "B"
end

task "c", depends: "a" do
  puts "C1"
end

task "c", depends: "b" do
  puts "C2"
end

The following behavior is observed:

$ ./rscons c
A
B
C1
C2

Note that for a simple project, the build script may not need to define any tasks at all and could just make use of the Rscons built-in default task (see Default Task).