Nim/tools/deps.nim
Andrey Makarov b88496ac67
fix compilation on Debian 7 (no git -C) (#18427)
* fix compilation on Debian 7 (no git -C)

* address review

* allow specify branch for testing unmerged csources

* temporarily change csources checkout parameters for testing

* Update tools/deps.nim

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>

* fix failure

* Update config/build_config.txt

* set proper git branch/hash

Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2021-07-06 20:09:56 +02:00

41 lines
1.3 KiB
Nim

import os, uri, strformat, strutils
import std/private/gitutils
proc exec(cmd: string) =
echo "deps.cmd: " & cmd
let status = execShellCmd(cmd)
doAssert status == 0, cmd
proc execRetry(cmd: string) =
let ok = retryCall(call = block:
let status = execShellCmd(cmd)
let result = status == 0
if not result:
echo fmt"failed command: '{cmd}', status: {status}"
result)
doAssert ok, cmd
proc cloneDependency*(destDirBase: string, url: string, commit = commitHead,
appendRepoName = true, allowBundled = false) =
let destDirBase = destDirBase.absolutePath
let p = url.parseUri.path
let name = p.splitFile.name
var destDir = destDirBase
if appendRepoName: destDir = destDir / name
let destDir2 = destDir.quoteShell
if not dirExists(destDir):
# note: old code used `destDir / .git` but that wouldn't prevent git clone
# from failing
execRetry fmt"git clone -q {url} {destDir2}"
if isGitRepo(destDir):
let oldDir = getCurrentDir()
setCurrentDir(destDir2)
try:
execRetry "git fetch -q"
exec fmt"git checkout -q {commit}"
finally:
setCurrentDir(oldDir)
elif allowBundled:
discard "this dependency was bundled with Nim, don't do anything"
else:
quit "FAILURE: " & destdir & " already exists but is not a git repo"