findExe, use curl/wget if avail, mingw32-make, unused imports

This commit is contained in:
Ganesh Viswanathan 2019-08-19 20:25:09 -07:00
commit 86ebf622e1
5 changed files with 49 additions and 18 deletions

View file

@ -1,8 +1,8 @@
import os, sequtils, sets, strformat, strutils, tables, times import os, sets, strformat, strutils, tables, times
import regex import regex
import "."/[getters, globals, grammar, treesitter/api] import "."/[getters, globals, treesitter/api]
proc saveNodeData(node: TSNode, nimState: NimState): bool = proc saveNodeData(node: TSNode, nimState: NimState): bool =
let name = $node.tsNodeType() let name = $node.tsNodeType()

View file

@ -614,7 +614,7 @@ macro c2nImport*(filename: static string, recurse: static bool = false, dynlib:
let let
(c2nimout, ret) = gorgeEx(cmd, cache=getCacheValue(hpath)) (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 var
nimout = &"const {header} = \"{fullpath}\"\n\n" & readFile(npath) nimout = &"const {header} = \"{fullpath}\"\n\n" & readFile(npath)

View file

@ -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 = proc execAction*(cmd: string, nostderr=false): string =
## Execute an external command - supported at compile time ## Execute an external command - supported at compile time
@ -24,6 +24,21 @@ proc execAction*(cmd: string, nostderr=false): string =
(result, ret) = execCmdEx(ccmd, opt) (result, ret) = execCmdEx(ccmd, opt)
doAssert ret == 0, "Command failed: " & $(ret, nostderr) & "\nccmd: " & ccmd & "\nresult:\n" & result 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) = proc mkDir*(dir: string) =
## Create a directory at cmopile time ## Create a directory at cmopile time
## ##
@ -70,8 +85,7 @@ proc extractZip*(zipfile, outdir: string) =
discard execAction(&"cd {outdir.quoteShell} && {cmd % zipfile}") discard execAction(&"cd {outdir.quoteShell} && {cmd % zipfile}")
proc downloadUrl*(url, outdir: string) = proc downloadUrl*(url, outdir: string) =
## Download a file using powershell on Windows and curl on other ## Download a file using curl or wget (or powershell on Windows) to the specified directory
## systems to the specified output directory
## ##
## If a zip file, it is automatically extracted after download. ## If a zip file, it is automatically extracted after download.
let let
@ -81,10 +95,17 @@ proc downloadUrl*(url, outdir: string) =
if not (ext == ".zip" and fileExists(outdir/file)): if not (ext == ".zip" and fileExists(outdir/file)):
echo "# Downloading " & file echo "# Downloading " & file
mkDir(outdir) mkDir(outdir)
var cmd = if defined(Windows): var cmd = findExe("curl")
"powershell [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; wget $# -OutFile $#" if cmd.len != 0:
cmd &= " -L $# -o $#"
else: 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]) discard execAction(cmd % [url, (outdir/file).quoteShell])
if ext == ".zip": if ext == ".zip":
@ -176,7 +197,7 @@ proc configure*(path, check: string, flags = "") =
discard execAction(&"cd {path.quoteShell} && bash autogen.sh") discard execAction(&"cd {path.quoteShell} && bash autogen.sh")
if fileExists(path / "configure"): if fileExists(path / "configure"):
echo "# Running configure" echo "# Running configure " & flags
var var
cmd = &"cd {path.quoteShell} && bash configure" cmd = &"cd {path.quoteShell} && bash configure"
@ -202,7 +223,8 @@ proc cmake*(path, check, flags: string) =
if (path / check).fileExists(): if (path / check).fileExists():
return return
echo "# Running cmake " & path echo "# Running cmake " & flags
echo "# Path: " & path
mkDir(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. ## is relative to the `path` and should not be an absolute path.
## ##
## `flags` are any flags that should be passed to the `make` command. ## `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(): if (path / check).fileExists():
return return
echo "# Running make " & path echo "# Running make " & flags
echo "# Path: " & path
var 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: if flags.len != 0:
cmd &= &" {flags}" cmd &= &" {flags}"

View file

@ -1,4 +1,4 @@
import macros, sets, strformat, strutils, tables import macros, strformat, strutils, tables
import regex import regex

View file

@ -1,6 +1,3 @@
import strutils
import strformat
import "."/[getters, globals] import "."/[getters, globals]
var var