aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2019-09-06 11:57:14 -0700
committerGanesh Viswanathan <dev@genotrance.com>2019-10-02 15:31:12 -0500
commit2049787f435440a51c7989ca9939a89d9b2aeff6 (patch)
tree4e938b7d4c0c3c85a6297de00b95cb3865e16f08
parent5bf5c7445da4849dc7bf01086ed2b7117a79ed41 (diff)
downloadnimterop-2049787f435440a51c7989ca9939a89d9b2aeff6.tar.gz
nimterop-2049787f435440a51c7989ca9939a89d9b2aeff6.zip
More archive support, Windows lzma test
-rw-r--r--nimterop/build.nim40
-rw-r--r--tests/getheader.nims8
-rw-r--r--tests/lzma.nim2
3 files changed, 43 insertions, 7 deletions
diff --git a/nimterop/build.nim b/nimterop/build.nim
index 15581eb..ee7c4ee 100644
--- a/nimterop/build.nim
+++ b/nimterop/build.nim
@@ -1,4 +1,4 @@
-import macros, osproc, regex, sequtils, strformat, strutils
+import macros, osproc, regex, strformat, strutils
import os except findExe
@@ -105,6 +105,39 @@ proc extractZip*(zipfile, outdir: string) =
echo "# Extracting " & zipfile
discard execAction(&"cd {outdir.quoteShell} && {cmd % zipfile}")
+proc extractTar*(tarfile, outdir: string) =
+ ## Extract a tar file using tar, 7z or 7za to the specified output directory
+ var
+ cmd = ""
+ name = ""
+
+ if findExe("tar").len != 0:
+ let
+ ext = tarfile.splitFile().ext.toLowerAscii()
+ typ =
+ case ext
+ of ".gz", ".tgz": "z"
+ of ".xz": "J"
+ of ".bz2": "j"
+ else: ""
+
+ cmd = "tar xvf" & typ & " " & tarfile.quoteShell
+ else:
+ for i in ["7z", "7za"]:
+ if findExe(i).len != 0:
+ cmd = i & " x $#" % tarfile.quoteShell
+
+ name = tarfile.splitFile().name
+ if ".tar" in name.toLowerAscii():
+ cmd &= " && " & i & " x $#" % name.quoteShell
+
+ break
+
+ echo "# Extracting " & tarfile
+ discard execAction(&"cd {outdir.quoteShell} && {cmd}")
+ if name.len != 0:
+ rmFile(outdir / name)
+
proc downloadUrl*(url, outdir: string) =
## Download a file using curl or wget (or powershell on Windows) to the specified directory
##
@@ -112,8 +145,9 @@ proc downloadUrl*(url, outdir: string) =
let
file = url.extractFilename()
ext = file.splitFile().ext.toLowerAscii()
+ archives = @[".zip", ".xz", ".gz", ".bz2", ".tgz", ".tar"]
- if not (ext == ".zip" and fileExists(outdir/file)):
+ if not (ext in archives and fileExists(outdir/file)):
echo "# Downloading " & file
mkDir(outdir)
var cmd = findExe("curl")
@@ -131,6 +165,8 @@ proc downloadUrl*(url, outdir: string) =
if ext == ".zip":
extractZip(file, outdir)
+ elif ext in archives:
+ extractTar(file, outdir)
proc gitReset*(outdir: string) =
## Hard reset the git repository at the specified directory
diff --git a/tests/getheader.nims b/tests/getheader.nims
index 6d0f73a..840a114 100644
--- a/tests/getheader.nims
+++ b/tests/getheader.nims
@@ -36,7 +36,7 @@ when defined(posix):
testCall(cmd & " -d:lzmaGit -d:lzmaStatic -d:lzmaVersion=v5.2.0" & rcmd, exp & "5.2.0", 0, delete = false)
testCall("cd build/liblzma && git branch", "v5.2.0", 0, delete = false)
- # dl
- testCall(cmd & " -d:lzmaDL" & rcmd, "Need version", 1)
- testCall(cmd & " -d:lzmaDL -d:lzmaVersion=v5.2.4" & rcmd, exp & "5.2.4", 0)
- testCall(cmd & " -d:lzmaDL -d:lzmaStatic -d:lzmaVersion=v5.2.4" & rcmd, exp & "5.2.4", 0, delete = false)
+# dl
+testCall(cmd & " -d:lzmaDL" & rcmd, "Need version", 1)
+testCall(cmd & " -d:lzmaDL -d:lzmaVersion=5.2.4" & rcmd, exp & "5.2.4", 0)
+testCall(cmd & " -d:lzmaDL -d:lzmaStatic -d:lzmaVersion=5.2.4" & rcmd, exp & "5.2.4", 0, delete = false)
diff --git a/tests/lzma.nim b/tests/lzma.nim
index 0cb92f5..422f94d 100644
--- a/tests/lzma.nim
+++ b/tests/lzma.nim
@@ -11,7 +11,7 @@ static:
getHeader(
"lzma.h",
giturl = "https://github.com/xz-mirror/xz",
- dlurl = "https://github.com/xz-mirror/xz/archive/$1.zip",
+ dlurl = "https://tukaani.org/xz/xz-$1.tar.gz",
outdir = baseDir,
conFlags = "--disable-xz --disable-xzdec --disable-lzmadec --disable-lzmainfo"
)