More archive support, Windows lzma test

This commit is contained in:
Ganesh Viswanathan 2019-09-06 11:57:14 -07:00
commit 2049787f43
3 changed files with 43 additions and 7 deletions

View file

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

View file

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

View file

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