Module nake

Documentation for the nake module. These are the procs and macros you can use to define and run tasks in your nakefiles.

Types

PTask* = ref object 
  desc*: string
  action*: TTaskFunction
TTaskFunction* = proc ()

Consts

defaultTask* = "default"
String with the name of the default task nake will run if you define it and the user doesn't specify any task.

Procs

proc runTask*(name: string) {.inline.}

Runs the specified task.

You can call this proc to chain other tasks for the current task and avoid repeating code. Example:

import nake, os

...

task "docs", "generates docs for module":
  echo "Generating " & moduleHtml
  direShell "nimrod", "doc", moduleNim

task "install_docs", "copies docs to " & docInstallDir:
  runTask("docs")
  echo "Copying documentation to " & docInstallDir
  copyFile(moduleHtml, docInstallDir / moduleHtml)
proc shell*(cmd: varargs[string, `$`]): bool {.discardable.}

Invokes an external command.

The proc will return false if the command exits with a non zero code.

proc cd*(dir: string) {.inline.}

Changes the current directory.

The change is permanent for the rest of the execution. Use the withDir template if you want to perform a temporary change only.

proc shell*(cmd: varargs[string, `$`]): bool
proc direShell*(cmd: varargs[string, `$`]): bool {.discardable.}
Like shell() but quits if the process does not return 0
proc cd*(dir: string)
proc needsRefresh*(target: string; src: varargs[string]): bool

Returns true if target is missing or src has newer modification date.

This is a convenience proc you can use in your tasks to verify if compilation for a binary should happen. The proc will return true if target doesn't exists or any of the file paths in src have a more recent last modification timestamp. All paths in src must be reachable or else the proc will raise an exception. Example:

import nake, os

let
  src = "prog.nim"
  exe = src.changeFileExt(exeExt)
if exe.needsRefresh(src):
  direShell "nimrod c", src
else:
  echo "All done!"
proc listTasks*()

Lists to stdout the registered tasks.

You can call this proc inside your defaultTask task to tell the user about other options if your default task doesn't have anything to do.

Templates

template task*(name: string; description: string; body: stmt): stmt {.immediate.}

Defines a task for nake.

Pass the name of the task, the description that will be displayed to the user when nake is invoked, and the body of the task. Example:

import nake

task "bin", "compiles all binaries":
  for binName in binaries:
    echo "Generating " & binName
    direShell "nimrod", "c", binName
template withDir*(dir: string; body: stmt): stmt
Changes the current directory temporarily.
withDir "foo":
  # inside foo
#back to last dir