summary refs log tree commit diff stats
path: root/tools/deps.nim
diff options
context:
space:
mode:
authoralaviss <leorize+oss@disroot.org>2020-09-26 07:31:55 +0000
committerGitHub <noreply@github.com>2020-09-26 09:31:55 +0200
commitd4892e9388084e71f9389efce7bba42d8c069d09 (patch)
tree8e07bb0c4af2e46b3dbcaee58859d0cfd115a662 /tools/deps.nim
parent2de6e18774ec9f0f15c88ab916d7f501ba13b467 (diff)
downloadNim-d4892e9388084e71f9389efce7bba42d8c069d09.tar.gz
koch, compiler: bundle fusion as part of the source archive (#15409)
This allows distributions to build Nim from the downloaded source
archive without an Internet connection.
Diffstat (limited to 'tools/deps.nim')
-rw-r--r--tools/deps.nim25
1 files changed, 21 insertions, 4 deletions
diff --git a/tools/deps.nim b/tools/deps.nim
index 888237761..394dc0d25 100644
--- a/tools/deps.nim
+++ b/tools/deps.nim
@@ -1,13 +1,25 @@
-import os, uri, strformat
+import os, uri, strformat, osproc
 
 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"
+  result = status == 0 and output == ""
+
 const commitHead* = "HEAD"
 
-proc cloneDependency*(destDirBase: string, url: string, commit = commitHead, appendRepoName = true) =
+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
@@ -18,5 +30,10 @@ proc cloneDependency*(destDirBase: string, url: string, commit = commitHead, app
     # note: old code used `destDir / .git` but that wouldn't prevent git clone
     # from failing
     exec fmt"git clone -q {url} {destDir2}"
-  exec fmt"git -C {destDir2} fetch -q"
-  exec fmt"git -C {destDir2} checkout -q {commit}"
+  if isGitRepo(destDir):
+    exec 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"
+  else:
+    quit "FAILURE: " & destdir & " already exists but is not a git repo"