Allow Nimble to override the `task` template in nimscript. (#8798)
This commit is contained in:
parent
5cd152bfda
commit
9ad17091cc
1 changed files with 18 additions and 18 deletions
|
|
@ -305,7 +305,6 @@ template withDir*(dir: string; body: untyped): untyped =
|
||||||
finally:
|
finally:
|
||||||
cd(curDir)
|
cd(curDir)
|
||||||
|
|
||||||
template `==?`(a, b: string): bool = cmpIgnoreStyle(a, b) == 0
|
|
||||||
|
|
||||||
proc writeTask(name, desc: string) =
|
proc writeTask(name, desc: string) =
|
||||||
if desc.len > 0:
|
if desc.len > 0:
|
||||||
|
|
@ -313,29 +312,30 @@ proc writeTask(name, desc: string) =
|
||||||
for i in 0 ..< 20 - name.len: spaces.add ' '
|
for i in 0 ..< 20 - name.len: spaces.add ' '
|
||||||
echo name, spaces, desc
|
echo name, spaces, desc
|
||||||
|
|
||||||
template task*(name: untyped; description: string; body: untyped): untyped =
|
|
||||||
## Defines a task. Hidden tasks are supported via an empty description.
|
|
||||||
## Example:
|
|
||||||
##
|
|
||||||
## .. code-block:: nim
|
|
||||||
## task build, "default build is via the C backend":
|
|
||||||
## setCommand "c"
|
|
||||||
proc `name Task`*() = body
|
|
||||||
|
|
||||||
let cmd = getCommand()
|
|
||||||
if cmd.len == 0 or cmd ==? "help":
|
|
||||||
setCommand "help"
|
|
||||||
writeTask(astToStr(name), description)
|
|
||||||
elif cmd ==? astToStr(name):
|
|
||||||
setCommand "nop"
|
|
||||||
`name Task`()
|
|
||||||
|
|
||||||
proc cppDefine*(define: string) =
|
proc cppDefine*(define: string) =
|
||||||
## tell Nim that ``define`` is a C preprocessor ``#define`` and so always
|
## tell Nim that ``define`` is a C preprocessor ``#define`` and so always
|
||||||
## needs to be mangled.
|
## needs to be mangled.
|
||||||
builtin
|
builtin
|
||||||
|
|
||||||
when not defined(nimble):
|
when not defined(nimble):
|
||||||
|
template `==?`(a, b: string): bool = cmpIgnoreStyle(a, b) == 0
|
||||||
|
template task*(name: untyped; description: string; body: untyped): untyped =
|
||||||
|
## Defines a task. Hidden tasks are supported via an empty description.
|
||||||
|
## Example:
|
||||||
|
##
|
||||||
|
## .. code-block:: nim
|
||||||
|
## task build, "default build is via the C backend":
|
||||||
|
## setCommand "c"
|
||||||
|
proc `name Task`*() = body
|
||||||
|
|
||||||
|
let cmd = getCommand()
|
||||||
|
if cmd.len == 0 or cmd ==? "help":
|
||||||
|
setCommand "help"
|
||||||
|
writeTask(astToStr(name), description)
|
||||||
|
elif cmd ==? astToStr(name):
|
||||||
|
setCommand "nop"
|
||||||
|
`name Task`()
|
||||||
|
|
||||||
# nimble has its own implementation for these things.
|
# nimble has its own implementation for these things.
|
||||||
var
|
var
|
||||||
packageName* = "" ## Nimble support: Set this to the package name. It
|
packageName* = "" ## Nimble support: Set this to the package name. It
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue