Squashed merge of #635 by @genotrance.
Squashed commit of the following:
commit e86a376f2faf9d26109405a3a9f73f986185f62d
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Sun Apr 28 15:37:22 2019 -0500
Fix caching issue
commit 640ce3f2e464e52668b5350fdc5a8fe506e79d38
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Thu Apr 25 18:38:48 2019 -0500
Clean up per feedback
commit ae3ef9f7a0cbad574b725d1bc7a83bd6115e19cc
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Thu Apr 25 16:39:26 2019 -0500
Fix for 0.19.4
commit 915d6b2be43e33bc51327585193b1899386ee250
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Thu Apr 25 16:13:42 2019 -0500
Keep nimscript separate, pin devel
commit c278bd6ba09771dc079029a87e3a375998f0b447
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Mon Apr 22 14:57:44 2019 -0500
Hardcode version, json{}, code width 80, isScriptResultCached, no blank paramStr check
commit 64e5489e256d5fc5abbfe3345789f65edf5980b7
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Wed Apr 17 21:07:03 2019 -0500
Remove compiler dependency
commit a031fffd70c118c16eb3e16d3b1ed10472baf5d7
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Wed Apr 17 16:49:09 2019 -0500
Add devel to travis
commit d49916e2a05b6bd7716f45bd8f74253fc8037827
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Wed Apr 17 16:43:14 2019 -0500
Interactive live, json to file
commit 24131deea4693199922f9a5697aa3d072cceaee1
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Wed Apr 17 12:40:27 2019 -0500
Fix empty param, json echo
commit b22fe37d47fd03367d49129ea4d2d56a779a6f26
Merge: 5cf0240 2942f11
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Tue Apr 16 22:23:17 2019 -0500
Merge branch 'nocompiler' of https://github.com/genotrance/nimble into nocompiler
commit 5cf0240b728ab6ff4a39ddf629ba5833eb8985f5
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Tue Apr 16 22:23:06 2019 -0500
No hints, live output
commit 2942f116c7774e0fa91f770cebde32bc431923a5
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Tue Apr 16 21:02:28 2019 -0500
Remove osx, test with stable
commit 85f3865ef195c7b813f0b9e30b5cc8c9b2756518
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Tue Apr 16 18:19:42 2019 -0500
Remove ospaths, fix tests for Windows
commit 74201bcfe4de00bdece5b31715618975f9ce8e6e
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Tue Apr 16 14:00:14 2019 -0500
No success for missing task
commit 8c2e65e223d32366b03004d9711364504c5d7916
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Tue Apr 16 13:44:32 2019 -0500
Fix packageName to name
commit b05d9480281ebae7a0f5fd0331c8627bbf2a77d5
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Tue Apr 16 13:29:37 2019 -0500
Add switch support
commit deecd903102a9baa5d4674cb9871cd9dbb658a04
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Tue Apr 16 12:24:01 2019 -0500
API cleanup, json setCommand fix
commit 1e95fd4104ec3ffb69fe67b9c2fac23f991e163a
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Tue Apr 16 10:45:12 2019 -0500
getParams once, hash nimscriptapi, fix loop in setcommand
commit 51d03b3845cd562796bb32d41d5ad17cd09a91e7
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Tue Apr 16 07:21:32 2019 -0500
getPkgDir impl
commit 7d0a40aa286d114d7557b229852f3c314795dc5d
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Mon Apr 15 14:24:02 2019 -0500
Before/after hook info
commit cbb3af3e970b20322030331d4849436b821f25ca
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Mon Apr 15 13:44:56 2019 -0500
Remove nims from package dir after exec
commit 0ed53d60bcdc8bb11beddb965590ed3ee63349d4
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Sat Apr 13 00:44:26 2019 -0500
Return bool from hooks
commit ab38b81b81e68cfccf3ca84fd854422cd3733c84
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Fri Apr 12 23:20:13 2019 -0500
Initial version
commit b9ef88b9f79b48435e7b4beeff959b4223f4b8ba
Merge: 220ebae c8d79fc
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Tue Mar 26 20:16:21 2019 -0500
Merge remote-tracking branch 'upstream/master' into nocompiler
commit 220ebae355c945963591b002a43b262a70640aa5
Merge: 3d7227c 119be48
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Wed Dec 12 18:02:10 2018 -0600
Merge remote-tracking branch 'upstream/master'
commit 3d7227c8900c205aada488d60565c90e17759639
Merge: cf7263d 66d79bf
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Wed Oct 17 13:39:51 2018 -0500
Merge remote-tracking branch 'upstream/master'
commit cf7263d6caf27ca4930ed54b05d4aa4f36e1dff1
Merge: 2fc3106 ee4c0ae
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Thu Sep 13 23:03:41 2018 -0500
Merge remote-tracking branch 'upstream/master'
commit 2fc310623b9f49ea012fc04fa09713fda140a7a3
Merge: e9a8850 c249f9b
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Thu Apr 26 16:27:31 2018 -0500
Merge remote-tracking branch 'upstream/master'
commit e9a885099b0b97bf3e0cddcde27e8c6b0bd51b10
Merge: 7adfd7b 75b7a21
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Thu Mar 8 14:26:46 2018 -0600
Merge remote-tracking branch 'upstream/master'
commit 7adfd7be2b38a52886640579845de378139ca0cc
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Mon Jan 15 00:35:55 2018 -0600
Updated fix for #398
commit de18319159b76a9da6765f35ea4d2e2c963d688a
Merge: 93ba4a0 3dae264
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Sun Jan 14 22:01:20 2018 -0600
Merge remote-tracking branch 'upstream/master'
commit 93ba4a00820ccb9a5362f0398cf3b5b4782bbefe
Author: Ganesh Viswanathan <dev@genotrance.com>
Date: Sat Jan 13 19:52:34 2018 -0600
Fix for #398
This commit is contained in:
parent
c8d79fc022
commit
6542c1ef16
10 changed files with 389 additions and 56 deletions
155
src/nimblepkg/nimscriptapi.nim
Normal file → Executable file
155
src/nimblepkg/nimscriptapi.nim
Normal file → Executable file
|
|
@ -3,6 +3,9 @@
|
|||
|
||||
## This module is implicitly imported in NimScript .nimble files.
|
||||
|
||||
import system except getCommand, setCommand, switch, `--`
|
||||
import strformat, strutils, tables
|
||||
|
||||
var
|
||||
packageName* = "" ## Set this to the package name. It
|
||||
## is usually not required to do that, nims' filename is
|
||||
|
|
@ -22,30 +25,134 @@ var
|
|||
foreignDeps*: seq[string] = @[] ## The foreign dependencies. Only
|
||||
## exported for 'distros.nim'.
|
||||
|
||||
beforeHooks: seq[string] = @[]
|
||||
afterHooks: seq[string] = @[]
|
||||
commandLineParams: seq[string] = @[]
|
||||
flags: TableRef[string, seq[string]]
|
||||
|
||||
command = "e"
|
||||
project = ""
|
||||
success = false
|
||||
retVal = true
|
||||
projectFile = ""
|
||||
|
||||
proc requires*(deps: varargs[string]) =
|
||||
## Call this to set the list of requirements of your Nimble
|
||||
## package.
|
||||
for d in deps: requiresData.add(d)
|
||||
|
||||
proc getParams() =
|
||||
for i in 2 .. paramCount():
|
||||
let
|
||||
param = paramStr(i)
|
||||
if param.fileExists():
|
||||
projectFile = param
|
||||
elif param[0] != '-':
|
||||
commandLineParams.add paramStr(i).normalize
|
||||
|
||||
proc getCommand*(): string =
|
||||
return command
|
||||
|
||||
proc setCommand*(cmd: string, prj = "") =
|
||||
command = cmd
|
||||
if prj.len != 0:
|
||||
project = prj
|
||||
|
||||
proc switch*(key: string, value="") =
|
||||
if flags.isNil:
|
||||
flags = newTable[string, seq[string]]()
|
||||
|
||||
if flags.hasKey(key):
|
||||
flags[key].add(value)
|
||||
else:
|
||||
flags[key] = @[value]
|
||||
|
||||
template `--`*(key, val: untyped) =
|
||||
switch(astToStr(key), strip astToStr(val))
|
||||
|
||||
template `--`*(key: untyped) =
|
||||
switch(astToStr(key), "")
|
||||
|
||||
template printIfLen(varName) =
|
||||
if varName.len != 0:
|
||||
iniOut &= astToStr(varName) & ": \"" & varName & "\"\n"
|
||||
|
||||
template printSeqIfLen(varName) =
|
||||
if varName.len != 0:
|
||||
iniOut &= astToStr(varName) & ": \"" & varName.join(", ") & "\"\n"
|
||||
|
||||
proc printPkgInfo() =
|
||||
if backend.len == 0:
|
||||
backend = "c"
|
||||
|
||||
var
|
||||
iniOut = "[Package]\n"
|
||||
if packageName.len != 0:
|
||||
iniOut &= "name: \"" & packageName & "\"\n"
|
||||
printIfLen version
|
||||
printIfLen author
|
||||
printIfLen description
|
||||
printIfLen license
|
||||
printIfLen srcdir
|
||||
printIfLen binDir
|
||||
printIfLen backend
|
||||
|
||||
printSeqIfLen skipDirs
|
||||
printSeqIfLen skipFiles
|
||||
printSeqIfLen skipExt
|
||||
printSeqIfLen installDirs
|
||||
printSeqIfLen installFiles
|
||||
printSeqIfLen installExt
|
||||
printSeqIfLen bin
|
||||
printSeqIfLen beforeHooks
|
||||
printSeqIfLen afterHooks
|
||||
|
||||
if requiresData.len != 0:
|
||||
iniOut &= "\n[Deps]\n"
|
||||
iniOut &= &"requires: \"{requiresData.join(\", \")}\"\n"
|
||||
|
||||
echo iniOut
|
||||
|
||||
proc onExit*() =
|
||||
if "printPkgInfo".normalize in commandLineParams:
|
||||
printPkgInfo()
|
||||
else:
|
||||
var
|
||||
output = ""
|
||||
output &= "\"success\": " & $success & ", "
|
||||
output &= "\"command\": \"" & command & "\", "
|
||||
if project.len != 0:
|
||||
output &= "\"project\": \"" & project & "\", "
|
||||
if not flags.isNil and flags.len != 0:
|
||||
output &= "\"flags\": {"
|
||||
for key, val in flags.pairs:
|
||||
output &= "\"" & key & "\": ["
|
||||
for v in val:
|
||||
output &= "\"" & v & "\", "
|
||||
output = output[0 .. ^3] & "], "
|
||||
output = output[0 .. ^3] & "}, "
|
||||
|
||||
output &= "\"retVal\": " & $retVal
|
||||
|
||||
writeFile(projectFile & ".out", "{" & output & "}")
|
||||
|
||||
# TODO: New release of Nim will move this `task` template under a
|
||||
# `when not defined(nimble)`. This will allow us to override it in the future.
|
||||
when not declared(task):
|
||||
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
|
||||
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"
|
||||
echo(astToStr(name), " ", description)
|
||||
elif cmd == astToStr(name):
|
||||
setCommand "nop"
|
||||
`name Task`()
|
||||
if commandLineParams.len == 0 or "help" in commandLineParams:
|
||||
success = true
|
||||
echo(astToStr(name), " ", description)
|
||||
elif astToStr(name).normalize in commandLineParams:
|
||||
success = true
|
||||
`name Task`()
|
||||
|
||||
template before*(action: untyped, body: untyped): untyped =
|
||||
## Defines a block of code which is evaluated before ``action`` is executed.
|
||||
|
|
@ -53,15 +160,27 @@ template before*(action: untyped, body: untyped): untyped =
|
|||
result = true
|
||||
body
|
||||
|
||||
beforeHooks.add astToStr(action)
|
||||
|
||||
if (astToStr(action) & "Before").normalize in commandLineParams:
|
||||
success = true
|
||||
retVal = `action Before`()
|
||||
|
||||
template after*(action: untyped, body: untyped): untyped =
|
||||
## Defines a block of code which is evaluated after ``action`` is executed.
|
||||
proc `action After`*(): bool =
|
||||
result = true
|
||||
body
|
||||
|
||||
template builtin = discard
|
||||
afterHooks.add astToStr(action)
|
||||
|
||||
if (astToStr(action) & "After").normalize in commandLineParams:
|
||||
success = true
|
||||
retVal = `action After`()
|
||||
|
||||
proc getPkgDir*(): string =
|
||||
## Returns the package directory containing the .nimble file currently
|
||||
## being evaluated.
|
||||
builtin
|
||||
result = projectFile.rsplit(seps={'/', '\\', ':'}, maxsplit=1)[0]
|
||||
|
||||
getParams()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue