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)
|
sleep(500)
|
||||||
result = execAction(cmd, retry = retry - 1)
|
result = execAction(cmd, retry = retry - 1)
|
||||||
else:
|
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 =
|
proc findExe*(exe: string): string =
|
||||||
## Find the specified executable using the `which`/`where` command - supported
|
## Find the specified executable using the `which`/`where` command - supported
|
||||||
|
|
@ -278,9 +278,15 @@ proc findFile*(file: string, dir: string, recurse = true, first = false, regex =
|
||||||
when not defined(windows):
|
when not defined(windows):
|
||||||
recursive = "-maxdepth 1"
|
recursive = "-maxdepth 1"
|
||||||
|
|
||||||
if not regex:
|
var
|
||||||
|
dir = dir
|
||||||
|
file = file
|
||||||
|
if not recurse:
|
||||||
let
|
let
|
||||||
dir = dir / file.parentDir()
|
pdir = file.parentDir()
|
||||||
|
if pdir.len != 0:
|
||||||
|
dir = dir / pdir
|
||||||
|
|
||||||
file = file.extractFilename
|
file = file.extractFilename
|
||||||
|
|
||||||
cmd = cmd % [recursive, (".*[\\\\/]" & file & "$").quoteShell, dir.sanitizePath]
|
cmd = cmd % [recursive, (".*[\\\\/]" & file & "$").quoteShell, dir.sanitizePath]
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import macros, strformat
|
import macros, strformat
|
||||||
|
|
||||||
when (NimMajor, NimMinor, NimPatch) >= (0, 19, 9):
|
when (NimMajor, NimMinor, NimPatch) >= (0, 19, 9):
|
||||||
from os import parentDir, getCurrentCompilerExe
|
from os import parentDir, getCurrentCompilerExe, DirSep
|
||||||
proc getNimRootDir(): string =
|
proc getNimRootDir(): string =
|
||||||
#[
|
#[
|
||||||
hack, but works
|
hack, but works
|
||||||
|
|
@ -15,22 +15,48 @@ else:
|
||||||
proc getCurrentCompilerExe*(): string =
|
proc getCurrentCompilerExe*(): string =
|
||||||
"nim"
|
"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] = @[]) =
|
defines: openArray[string] = @[]) =
|
||||||
## Generate docs for all specified nim `files` to the specified `path`
|
## Generate docs for all specified nim `files` to the specified `path`
|
||||||
##
|
##
|
||||||
## `baseDir` is the project path by default and `files` and `path` are relative
|
## `baseDir` is the project path by default and `files` and `path` are relative
|
||||||
## to that directory. Set to "" if using absolute paths.
|
## 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
|
## Use the `--publish` flag with nimble to publish docs contained in
|
||||||
## `path` to Github in the `gh-pages` branch. This requires the ghp-import
|
## `path` to Github in the `gh-pages` branch. This requires the ghp-import
|
||||||
## package for Python: `pip install ghp-import`
|
## package for Python: `pip install ghp-import`
|
||||||
##
|
##
|
||||||
## WARNING: `--publish` will destroy any existing content in this branch.
|
## WARNING: `--publish` will destroy any existing content in this branch.
|
||||||
|
##
|
||||||
|
## 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
|
let
|
||||||
baseDir =
|
baseDir =
|
||||||
if baseDir == "/":
|
if baseDir == $DirSep:
|
||||||
getCurrentDir() & "/"
|
getCurrentDir() & $DirSep
|
||||||
else:
|
else:
|
||||||
baseDir
|
baseDir
|
||||||
path = baseDir & path
|
path = baseDir & path
|
||||||
|
|
@ -41,17 +67,17 @@ proc buildDocs*(files: openArray[string], path: string, baseDir = getProjectPath
|
||||||
defStr
|
defStr
|
||||||
nim = getCurrentCompilerExe()
|
nim = getCurrentCompilerExe()
|
||||||
for file in files:
|
for file in files:
|
||||||
echo gorge(&"{nim} doc {defStr} -o:{path} --project --index:on {baseDir & file}")
|
echo execAction(&"{nim} doc {defStr} -o:{path} --project --index:on {baseDir & file}")
|
||||||
|
|
||||||
echo gorge(&"{nim} buildIndex -o:{path}/theindex.html {path}")
|
echo execAction(&"{nim} buildIndex -o:{path}/theindex.html {path}")
|
||||||
when declared(getNimRootDir):
|
when declared(getNimRootDir):
|
||||||
#[
|
#[
|
||||||
this enables doc search, works at least locally with:
|
this enables doc search, works at least locally with:
|
||||||
cd {path} && python -m SimpleHTTPServer 9009
|
cd {path} && python -m SimpleHTTPServer 9009
|
||||||
]#
|
]#
|
||||||
echo gorge(&"{nim} js -o:{path}/dochack.js {getNimRootDir()}/tools/dochack/dochack.nim")
|
echo execAction(&"{nim} js -o:{path}/dochack.js {getNimRootDir()}/tools/dochack/dochack.nim")
|
||||||
|
|
||||||
for i in 0 .. paramCount():
|
for i in 0 .. paramCount():
|
||||||
if paramStr(i) == "--publish":
|
if paramStr(i) == "--publish":
|
||||||
echo gorge(&"ghp-import --no-jekyll -fp {path}")
|
echo execAction(&"ghp-import --no-jekyll -fp {path}")
|
||||||
break
|
break
|
||||||
|
|
@ -142,6 +142,7 @@ proc initGrammar(): Grammar =
|
||||||
nname = ""
|
nname = ""
|
||||||
tptr = ""
|
tptr = ""
|
||||||
aptr = ""
|
aptr = ""
|
||||||
|
pragmas: seq[string] = @[]
|
||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
while i < nimState.data.len and "pointer" in nimState.data[i].name:
|
while i < nimState.data.len and "pointer" in nimState.data[i].name:
|
||||||
|
|
@ -158,8 +159,11 @@ proc initGrammar(): Grammar =
|
||||||
nname = nimState.getIdentifier(name, nskType)
|
nname = nimState.getIdentifier(name, nskType)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
if nimState.gState.dynlib.len == 0:
|
||||||
|
pragmas.add nimState.getImportC(name, nname)
|
||||||
|
|
||||||
let
|
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 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":
|
if i < nimState.data.len and nimState.data[^1].name == "function_declarator":
|
||||||
|
|
@ -255,8 +259,15 @@ proc initGrammar(): Grammar =
|
||||||
if nimState.data.len == 1:
|
if nimState.data.len == 1:
|
||||||
nimState.typeStr &= &"{nimState.getComments()}\n {nname}* {{.bycopy.}} = object{union}"
|
nimState.typeStr &= &"{nimState.getComments()}\n {nname}* {{.bycopy.}} = object{union}"
|
||||||
else:
|
else:
|
||||||
|
var
|
||||||
|
pragmas: seq[string] = @[]
|
||||||
|
if nimState.gState.dynlib.len == 0:
|
||||||
|
pragmas.add nimState.getImportC(prefix & name, nname)
|
||||||
|
pragmas.add "bycopy"
|
||||||
|
|
||||||
let
|
let
|
||||||
pragma = nimState.getPragma(nimState.getImportC(prefix & name, nname), "bycopy")
|
pragma = nimState.getPragma(pragmas)
|
||||||
|
|
||||||
nimState.typeStr &= &"{nimState.getComments()}\n {nname}*{pragma} = object{union}"
|
nimState.typeStr &= &"{nimState.getComments()}\n {nname}*{pragma} = object{union}"
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,13 @@ when (NimMajor, NimMinor, NimPatch) < (0, 19, 9):
|
||||||
import posix
|
import posix
|
||||||
type
|
type
|
||||||
time_t* = Time
|
time_t* = Time
|
||||||
|
time64_t* = Time
|
||||||
wchar_t* {.importc.} = object
|
wchar_t* {.importc.} = object
|
||||||
else:
|
else:
|
||||||
import std/time_t as time_t_temp
|
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):
|
when defined(c) or defined(nimdoc):
|
||||||
# http://www.cplusplus.com/reference/cwchar/wchar_t/
|
# http://www.cplusplus.com/reference/cwchar/wchar_t/
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue