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:

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

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

In this example, the flash task depends on the build task. So if the project had not yet been built, and the user executes ./rscons flash, the project would first be built and then flashed to the target.

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.

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).