Compare commits
3 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6410758117 | ||
|
|
d9350cf47e | ||
|
|
42a96bd4bf |
4 changed files with 81 additions and 35 deletions
|
|
@ -45,7 +45,7 @@ proc execAction*(cmd: string, retry = 0, nostderr = false): string =
|
|||
sleep(500)
|
||||
result = execAction(cmd, retry = retry - 1)
|
||||
else:
|
||||
doAssert true, "Command failed: " & $(ret, nostderr) & "\nccmd: " & ccmd & "\nresult:\n" & result
|
||||
doAssert true, "Command failed: " & $(ret, nostderr) & "\ncmd: " & ccmd & "\nresult:\n" & result
|
||||
|
||||
proc findExe*(exe: string): string =
|
||||
## Find the specified executable using the `which`/`where` command - supported
|
||||
|
|
@ -278,10 +278,16 @@ proc findFile*(file: string, dir: string, recurse = true, first = false, regex =
|
|||
when not defined(windows):
|
||||
recursive = "-maxdepth 1"
|
||||
|
||||
if not regex:
|
||||
var
|
||||
dir = dir
|
||||
file = file
|
||||
if not recurse:
|
||||
let
|
||||
dir = dir / file.parentDir()
|
||||
file = file.extractFilename
|
||||
pdir = file.parentDir()
|
||||
if pdir.len != 0:
|
||||
dir = dir / pdir
|
||||
|
||||
file = file.extractFilename
|
||||
|
||||
cmd = cmd % [recursive, (".*[\\\\/]" & file & "$").quoteShell, dir.sanitizePath]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import macros, strformat
|
||||
|
||||
when (NimMajor, NimMinor, NimPatch) >= (0, 19, 9):
|
||||
from os import parentDir, getCurrentCompilerExe
|
||||
from os import parentDir, getCurrentCompilerExe, DirSep
|
||||
proc getNimRootDir(): string =
|
||||
#[
|
||||
hack, but works
|
||||
|
|
@ -15,43 +15,69 @@ else:
|
|||
proc getCurrentCompilerExe*(): string =
|
||||
"nim"
|
||||
|
||||
proc buildDocs*(files: openArray[string], path: string, baseDir = getProjectPath() & "/",
|
||||
const
|
||||
DirSep = when defined(windows): '\\' else: '/'
|
||||
|
||||
proc execAction(cmd: string): string =
|
||||
var
|
||||
ccmd = ""
|
||||
ret = 0
|
||||
when defined(Windows):
|
||||
ccmd = "cmd /c " & cmd
|
||||
elif defined(posix):
|
||||
ccmd = cmd
|
||||
else:
|
||||
doAssert false
|
||||
|
||||
(result, ret) = gorgeEx(ccmd)
|
||||
doAssert ret == 0, "Command failed: " & $ret & "\ncmd: " & ccmd & "\nresult:\n" & result
|
||||
|
||||
proc buildDocs*(files: openArray[string], path: string, baseDir = getProjectPath() & $DirSep,
|
||||
defines: openArray[string] = @[]) =
|
||||
## Generate docs for all specified nim `files` to the specified `path`
|
||||
##
|
||||
## `baseDir` is the project path by default and `files` and `path` are relative
|
||||
## to that directory. Set to "" if using absolute paths.
|
||||
##
|
||||
## `defines` is a list of `-d:xxx` define flags (the `xxx` part) that should be passed
|
||||
## to `nim doc` so that `getHeader()` is invoked correctly.
|
||||
##
|
||||
## Use the `--publish` flag with nimble to publish docs contained in
|
||||
## `path` to Github in the `gh-pages` branch. This requires the ghp-import
|
||||
## package for Python: `pip install ghp-import`
|
||||
##
|
||||
## WARNING: `--publish` will destroy any existing content in this branch.
|
||||
let
|
||||
baseDir =
|
||||
if baseDir == "/":
|
||||
getCurrentDir() & "/"
|
||||
else:
|
||||
baseDir
|
||||
path = baseDir & path
|
||||
defStr = block:
|
||||
var defStr = ""
|
||||
for def in defines:
|
||||
defStr &= " -d:" & def
|
||||
defStr
|
||||
nim = getCurrentCompilerExe()
|
||||
for file in files:
|
||||
echo gorge(&"{nim} doc {defStr} -o:{path} --project --index:on {baseDir & file}")
|
||||
##
|
||||
## NOTE: `buildDocs()` only works correctly on Windows with Nim 1.0+ since
|
||||
## https://github.com/nim-lang/Nim/pull/11814 is required.
|
||||
when defined(windows) and (NimMajor, NimMinor, NimPatch) < (1, 0, 0):
|
||||
echo "buildDocs() unsupported on Windows for Nim < 1.0 - requires PR #11814"
|
||||
else:
|
||||
let
|
||||
baseDir =
|
||||
if baseDir == $DirSep:
|
||||
getCurrentDir() & $DirSep
|
||||
else:
|
||||
baseDir
|
||||
path = baseDir & path
|
||||
defStr = block:
|
||||
var defStr = ""
|
||||
for def in defines:
|
||||
defStr &= " -d:" & def
|
||||
defStr
|
||||
nim = getCurrentCompilerExe()
|
||||
for file in files:
|
||||
echo execAction(&"{nim} doc {defStr} -o:{path} --project --index:on {baseDir & file}")
|
||||
|
||||
echo gorge(&"{nim} buildIndex -o:{path}/theindex.html {path}")
|
||||
when declared(getNimRootDir):
|
||||
#[
|
||||
this enables doc search, works at least locally with:
|
||||
cd {path} && python -m SimpleHTTPServer 9009
|
||||
]#
|
||||
echo gorge(&"{nim} js -o:{path}/dochack.js {getNimRootDir()}/tools/dochack/dochack.nim")
|
||||
echo execAction(&"{nim} buildIndex -o:{path}/theindex.html {path}")
|
||||
when declared(getNimRootDir):
|
||||
#[
|
||||
this enables doc search, works at least locally with:
|
||||
cd {path} && python -m SimpleHTTPServer 9009
|
||||
]#
|
||||
echo execAction(&"{nim} js -o:{path}/dochack.js {getNimRootDir()}/tools/dochack/dochack.nim")
|
||||
|
||||
for i in 0 .. paramCount():
|
||||
if paramStr(i) == "--publish":
|
||||
echo gorge(&"ghp-import --no-jekyll -fp {path}")
|
||||
break
|
||||
for i in 0 .. paramCount():
|
||||
if paramStr(i) == "--publish":
|
||||
echo execAction(&"ghp-import --no-jekyll -fp {path}")
|
||||
break
|
||||
|
|
@ -142,6 +142,7 @@ proc initGrammar(): Grammar =
|
|||
nname = ""
|
||||
tptr = ""
|
||||
aptr = ""
|
||||
pragmas: seq[string] = @[]
|
||||
|
||||
i += 1
|
||||
while i < nimState.data.len and "pointer" in nimState.data[i].name:
|
||||
|
|
@ -158,8 +159,11 @@ proc initGrammar(): Grammar =
|
|||
nname = nimState.getIdentifier(name, nskType)
|
||||
i += 1
|
||||
|
||||
if nimState.gState.dynlib.len == 0:
|
||||
pragmas.add nimState.getImportC(name, nname)
|
||||
|
||||
let
|
||||
pragma = nimState.getPragma(nimState.getImportC(name, nname))
|
||||
pragma = nimState.getPragma(pragmas)
|
||||
|
||||
if nname notin gTypeMap and typ.nBl and nname.nBl and nimState.addNewIdentifer(nname):
|
||||
if i < nimState.data.len and nimState.data[^1].name == "function_declarator":
|
||||
|
|
@ -255,8 +259,15 @@ proc initGrammar(): Grammar =
|
|||
if nimState.data.len == 1:
|
||||
nimState.typeStr &= &"{nimState.getComments()}\n {nname}* {{.bycopy.}} = object{union}"
|
||||
else:
|
||||
var
|
||||
pragmas: seq[string] = @[]
|
||||
if nimState.gState.dynlib.len == 0:
|
||||
pragmas.add nimState.getImportC(prefix & name, nname)
|
||||
pragmas.add "bycopy"
|
||||
|
||||
let
|
||||
pragma = nimState.getPragma(nimState.getImportC(prefix & name, nname), "bycopy")
|
||||
pragma = nimState.getPragma(pragmas)
|
||||
|
||||
nimState.typeStr &= &"{nimState.getComments()}\n {nname}*{pragma} = object{union}"
|
||||
|
||||
var
|
||||
|
|
|
|||
|
|
@ -15,10 +15,13 @@ when (NimMajor, NimMinor, NimPatch) < (0, 19, 9):
|
|||
import posix
|
||||
type
|
||||
time_t* = Time
|
||||
time64_t* = Time
|
||||
wchar_t* {.importc.} = object
|
||||
else:
|
||||
import std/time_t as time_t_temp
|
||||
type time_t* = time_t_temp.Time
|
||||
type
|
||||
time_t* = time_t_temp.Time
|
||||
time64_t* = time_t_temp.Time
|
||||
|
||||
when defined(c) or defined(nimdoc):
|
||||
# http://www.cplusplus.com/reference/cwchar/wchar_t/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue