summary refs log tree commit diff stats
path: root/tools/deps.nim
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-01-28 22:51:12 -0800
committerGitHub <noreply@github.com>2021-01-29 07:51:12 +0100
commit478d15f7f4bb48a8442e54d8ab08aaade39e5270 (patch)
tree273d965edc5b69cf46c0c8b25adadd930e689417 /tools/deps.nim
parentb0f38a63c4916be139f1a289264a5df68bcb4c07 (diff)
downloadNim-478d15f7f4bb48a8442e54d8ab08aaade39e5270.tar.gz
improve code in categories.nim; add std/private/gitutils; fix flakyness in nim CI (cloneDependency in deps.nim) (#16856)
* improve code in categories.nim; gitutils; fix flakyness in deps.nim
* cleanups
Diffstat (limited to 'tools/deps.nim')
-rw-r--r--tools/deps.nim31
1 files changed, 12 insertions, 19 deletions
diff --git a/tools/deps.nim b/tools/deps.nim
index 4ff171482..8ed95b59a 100644
--- a/tools/deps.nim
+++ b/tools/deps.nim
@@ -1,26 +1,19 @@
-import os, uri, strformat, osproc, strutils
+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 execEx(cmd: string): tuple[output: string, 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) =
@@ -33,9 +26,9 @@ proc cloneDependency*(destDirBase: string, url: string, commit = commitHead,
   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} {destDir2}"
   if isGitRepo(destDir):
-    exec fmt"git -C {destDir2} fetch -q"
+    execRetry fmt"git -C {destDir2} fetch -q"
     exec fmt"git -C {destDir2} checkout -q {commit}"
   elif allowBundled:
     discard "this dependency was bundled with Nim, don't do anything"