diff options
Diffstat (limited to 'tools/deps.nim')
-rw-r--r-- | tools/deps.nim | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/tools/deps.nim b/tools/deps.nim index b238f12ed..e43f7a2b4 100644 --- a/tools/deps.nim +++ b/tools/deps.nim @@ -1,26 +1,22 @@ -import os, uri, strformat, osproc, strutils +import std/[os, uri, strformat, strutils] +import std/private/gitutils + +when defined(nimPreviewSlimSystem): + import std/assertions proc exec(cmd: string) = echo "deps.cmd: " & cmd let status = execShellCmd(cmd) doAssert status == 0, cmd -proc execEx(cmd: string): tuple[output: TaintedString, exitCode: int] = - echo "deps.cmd: " & cmd - execCmdEx(cmd, {poStdErrToStdOut, poUsePath, poEvalCommand}) - -proc isGitRepo(dir: string): bool = - # This command is used to get the relative path to the root of the repository. - # Using this, we can verify whether a folder is a git repository by checking - # whether the command success and if the output is empty. - let (output, status) = execEx fmt"git -C {quoteShell(dir)} rev-parse --show-cdup" - # On Windows there will be a trailing newline on success, remove it. - # The value of a successful call typically won't have a whitespace (it's - # usually a series of ../), so we know that it's safe to unconditionally - # remove trailing whitespaces from the result. - result = status == 0 and output.strip() == "" - -const commitHead* = "HEAD" +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) = @@ -29,14 +25,19 @@ proc cloneDependency*(destDirBase: string, url: string, commit = commitHead, let name = p.splitFile.name var destDir = destDirBase if appendRepoName: destDir = destDir / name - let destDir2 = destDir.quoteShell + let quotedDestDir = destDir.quoteShell if not dirExists(destDir): # note: old code used `destDir / .git` but that wouldn't prevent git clone # from failing - exec fmt"git clone -q {url} {destDir2}" + execRetry fmt"git clone -q {url} {quotedDestDir}" if isGitRepo(destDir): - exec fmt"git -C {destDir2} fetch -q" - exec fmt"git -C {destDir2} checkout -q {commit}" + let oldDir = getCurrentDir() + setCurrentDir(destDir) + 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: |