diff --git a/nimterop/ast.nim b/nimterop/ast.nim index f858043..240d5fd 100644 --- a/nimterop/ast.nim +++ b/nimterop/ast.nim @@ -1,8 +1,8 @@ -import os, sequtils, sets, strformat, strutils, tables, times +import os, sets, strformat, strutils, tables, times import regex -import "."/[getters, globals, grammar, treesitter/api] +import "."/[getters, globals, treesitter/api] proc saveNodeData(node: TSNode, nimState: NimState): bool = let name = $node.tsNodeType() diff --git a/nimterop/cimport.nim b/nimterop/cimport.nim index 8c3d6c7..506f18f 100644 --- a/nimterop/cimport.nim +++ b/nimterop/cimport.nim @@ -614,7 +614,7 @@ macro c2nImport*(filename: static string, recurse: static bool = false, dynlib: let (c2nimout, ret) = gorgeEx(cmd, cache=getCacheValue(hpath)) - doAssert ret == 0, "Command failed:\n " & cmd + doAssert ret == 0, "Command failed:\n " & cmd & "\n\n" & c2nimout var nimout = &"const {header} = \"{fullpath}\"\n\n" & readFile(npath) diff --git a/nimterop/git.nim b/nimterop/git.nim index 6566c0e..443f9a5 100644 --- a/nimterop/git.nim +++ b/nimterop/git.nim @@ -1,6 +1,6 @@ -import macros, os, osproc, regex, strformat, strutils +import os, osproc, strformat, strutils -import "."/[paths, compat] +import "."/[compat] proc execAction*(cmd: string, nostderr=false): string = ## Execute an external command - supported at compile time @@ -24,6 +24,21 @@ proc execAction*(cmd: string, nostderr=false): string = (result, ret) = execCmdEx(ccmd, opt) doAssert ret == 0, "Command failed: " & $(ret, nostderr) & "\nccmd: " & ccmd & "\nresult:\n" & result +proc findExe*(exe: string): string = + ## Find the specified executable using the which/where command - supported + ## at compile time + var + cmd = + when defined(windows): + "where " & exe + else: + "which " & exe + + (oup, code) = gorgeEx(cmd) + + if code == 0: + return oup.strip() + proc mkDir*(dir: string) = ## Create a directory at cmopile time ## @@ -70,8 +85,7 @@ proc extractZip*(zipfile, outdir: string) = discard execAction(&"cd {outdir.quoteShell} && {cmd % zipfile}") proc downloadUrl*(url, outdir: string) = - ## Download a file using powershell on Windows and curl on other - ## systems to the specified output directory + ## Download a file using curl or wget (or powershell on Windows) to the specified directory ## ## If a zip file, it is automatically extracted after download. let @@ -81,10 +95,17 @@ proc downloadUrl*(url, outdir: string) = if not (ext == ".zip" and fileExists(outdir/file)): echo "# Downloading " & file mkDir(outdir) - var cmd = if defined(Windows): - "powershell [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; wget $# -OutFile $#" + var cmd = findExe("curl") + if cmd.len != 0: + cmd &= " -L $# -o $#" else: - "curl -L $# -o $#" + cmd = findExe("wget") + if cmd.len != 0: + cmd &= " $# -o $#" + elif defined(Windows): + cmd = "powershell [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; wget $# -OutFile $#" + else: + doAssert false, "No download tool available - curl, wget" discard execAction(cmd % [url, (outdir/file).quoteShell]) if ext == ".zip": @@ -176,7 +197,7 @@ proc configure*(path, check: string, flags = "") = discard execAction(&"cd {path.quoteShell} && bash autogen.sh") if fileExists(path / "configure"): - echo "# Running configure" + echo "# Running configure " & flags var cmd = &"cd {path.quoteShell} && bash configure" @@ -202,7 +223,8 @@ proc cmake*(path, check, flags: string) = if (path / check).fileExists(): return - echo "# Running cmake " & path + echo "# Running cmake " & flags + echo "# Path: " & path mkDir(path) @@ -219,13 +241,25 @@ proc make*(path, check: string, flags = "") = ## is relative to the `path` and should not be an absolute path. ## ## `flags` are any flags that should be passed to the `make` command. + ## + ## If make.exe is missing and mingw32-make.exe is available, it will + ## be copied over to make.exe in the same location. if (path / check).fileExists(): return - echo "# Running make " & path + echo "# Running make " & flags + echo "# Path: " & path var - cmd = &"cd {path.quoteShell} && make" + cmd = findExe("make") + + if cmd.len == 0: + cmd = findExe("mingw32-make") + if cmd.len != 0: + cpFile(cmd, cmd.replace("mingw32-make", "make")) + doAssert cmd.len != 0, "Make not found" + + cmd = &"cd {path.quoteShell} && make" if flags.len != 0: cmd &= &" {flags}" diff --git a/nimterop/grammar.nim b/nimterop/grammar.nim index e40a4dc..a66442f 100644 --- a/nimterop/grammar.nim +++ b/nimterop/grammar.nim @@ -1,4 +1,4 @@ -import macros, sets, strformat, strutils, tables +import macros, strformat, strutils, tables import regex diff --git a/nimterop/lisp.nim b/nimterop/lisp.nim index 8a256be..5c7a02a 100644 --- a/nimterop/lisp.nim +++ b/nimterop/lisp.nim @@ -1,6 +1,3 @@ -import strutils -import strformat - import "."/[getters, globals] var