Fix #134, time64_t, buildDocs error on Win

This commit is contained in:
Ganesh Viswanathan 2019-10-07 14:46:26 -07:00
commit 42a96bd4bf
4 changed files with 76 additions and 37 deletions

View file

@ -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,10 +278,9 @@ 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: let
let dir = if not regex: dir / file.parentDir() else: dir
dir = dir / file.parentDir() file = if not regex: file.extractFilename else: file
file = file.extractFilename
cmd = cmd % [recursive, (".*[\\\\/]" & file & "$").quoteShell, dir.sanitizePath] cmd = cmd % [recursive, (".*[\\\\/]" & file & "$").quoteShell, dir.sanitizePath]

View file

@ -1,7 +1,7 @@
import macros, strformat import macros, regex, 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,43 +15,69 @@ 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.
let ##
baseDir = ## NOTE: `buildDocs()` only works correctly on Windows with Nim 1.0+ since
if baseDir == "/": ## https://github.com/nim-lang/Nim/pull/11814 is required.
getCurrentDir() & "/" when defined(windows) and (NimMajor, NimMinor, NimPatch) < (1, 0, 0):
else: echo "buildDocs() unsupported on Windows for Nim < 1.0 - requires PR #11814"
baseDir else:
path = baseDir & path let
defStr = block: baseDir =
var defStr = "" if baseDir == $DirSep:
for def in defines: getCurrentDir() & $DirSep
defStr &= " -d:" & def else:
defStr baseDir
nim = getCurrentCompilerExe() path = baseDir & path.replace(re"[/\\]", $DirSep)
for file in files: defStr = block:
echo gorge(&"{nim} doc {defStr} -o:{path} --project --index:on {baseDir & file}") 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}") 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

View file

@ -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

View file

@ -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/