aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2019-10-08 10:53:07 -0700
committerGanesh Viswanathan <dev@genotrance.com>2019-10-08 10:53:07 -0700
commitc21a334ec1800b20248eb4e32c6234df800e31e0 (patch)
tree459c0964d3ad565ee0e73bb6d1a1adb181b84afd
parent366569f55e177251cb91211e6bd3a785ce7abb49 (diff)
downloadnimterop-c21a334ec1800b20248eb4e32c6234df800e31e0.tar.gz
nimterop-c21a334ec1800b20248eb4e32c6234df800e31e0.zip
Fix #134, time64_t, buildDocs error on Win
-rw-r--r--nimterop/build.nim14
-rw-r--r--nimterop/docs.nim82
-rw-r--r--nimterop/grammar.nim15
-rw-r--r--nimterop/types.nim5
4 files changed, 81 insertions, 35 deletions
diff --git a/nimterop/build.nim b/nimterop/build.nim
index bcbd96a..843db42 100644
--- a/nimterop/build.nim
+++ b/nimterop/build.nim
@@ -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]
diff --git a/nimterop/docs.nim b/nimterop/docs.nim
index 8fd396b..57c806b 100644
--- a/nimterop/docs.nim
+++ b/nimterop/docs.nim
@@ -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 \ No newline at end of file
diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim
index b14a208..57cbbdd 100644
--- a/nimterop/grammar.nim
+++ b/nimterop/grammar.nim
@@ -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
diff --git a/nimterop/types.nim b/nimterop/types.nim
index 8492f00..3dd8f39 100644
--- a/nimterop/types.nim
+++ b/nimterop/types.nim
@@ -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/