summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDominik Picheta <dominikpicheta@gmail.com>2017-09-02 15:28:25 +0100
committerDominik Picheta <dominikpicheta@gmail.com>2017-09-02 15:28:25 +0100
commit90fa64501f0eba487182a760fde98f7bb955c3d7 (patch)
treec4d9199a774b570ed8ebe5e4c27117c4a5c03933
parent9b465a236159423c344395194b2e4963e5d8adba (diff)
downloadNim-90fa64501f0eba487182a760fde98f7bb955c3d7.tar.gz
Implement .nimble-link files in the compiler and add tests for them.
-rw-r--r--compiler/nimblecmd.nim17
-rw-r--r--tests/nimble/nimbleDir/linkedPkgs/pkgA-0.1.0/pkgA.nimble-link2
-rw-r--r--tests/nimble/nimbleDir/linkedPkgs/pkgB-#head/pkgB.nimble-link2
-rw-r--r--tests/nimble/nimbleDir/linkedPkgs/pkgB-0.1.0/pkgB.nimble-link2
-rw-r--r--tests/nimble/tnimblepathlink.nim9
-rw-r--r--tests/testament/tester.nim1
6 files changed, 29 insertions, 4 deletions
diff --git a/compiler/nimblecmd.nim b/compiler/nimblecmd.nim
index 853077e31..8042644b0 100644
--- a/compiler/nimblecmd.nim
+++ b/compiler/nimblecmd.nim
@@ -77,9 +77,20 @@ iterator chosen(packages: StringTableRef): string =
     yield res
 
 proc addNimblePath(p: string, info: TLineInfo) =
-  if not contains(options.searchPaths, p):
-    message(info, hintPath, p)
-    options.lazyPaths.insert(p, 0)
+  var path = p
+  let nimbleLinks = toSeq(walkPattern(p / "*.nimble-link"))
+  if nimbleLinks.len > 0:
+    # If the user has more than one .nimble-link file then... we just ignore it.
+    # Spec for these files is available in Nimble's readme:
+    # https://github.com/nim-lang/nimble#nimble-link
+    let nimbleLinkLines = readFile(nimbleLinks[0]).splitLines()
+    path = nimbleLinkLines[1]
+    if not path.isAbsolute():
+      path = p / path
+
+  if not contains(options.searchPaths, path):
+    message(info, hintPath, path)
+    options.lazyPaths.insert(path, 0)
 
 proc addPathRec(dir: string, info: TLineInfo) =
   var packages = newStringTable(modeStyleInsensitive)
diff --git a/tests/nimble/nimbleDir/linkedPkgs/pkgA-0.1.0/pkgA.nimble-link b/tests/nimble/nimbleDir/linkedPkgs/pkgA-0.1.0/pkgA.nimble-link
new file mode 100644
index 000000000..8dc825fc9
--- /dev/null
+++ b/tests/nimble/nimbleDir/linkedPkgs/pkgA-0.1.0/pkgA.nimble-link
@@ -0,0 +1,2 @@
+../../simplePkgs/pkgA-0.1.0/pkgA.nimble
+../../simplePkgs/pkgA-0.1.0/
\ No newline at end of file
diff --git a/tests/nimble/nimbleDir/linkedPkgs/pkgB-#head/pkgB.nimble-link b/tests/nimble/nimbleDir/linkedPkgs/pkgB-#head/pkgB.nimble-link
new file mode 100644
index 000000000..a57a3cb66
--- /dev/null
+++ b/tests/nimble/nimbleDir/linkedPkgs/pkgB-#head/pkgB.nimble-link
@@ -0,0 +1,2 @@
+../../simplePkgs/pkgB-#head/pkgB.nimble
+../../simplePkgs/pkgB-#head/
\ No newline at end of file
diff --git a/tests/nimble/nimbleDir/linkedPkgs/pkgB-0.1.0/pkgB.nimble-link b/tests/nimble/nimbleDir/linkedPkgs/pkgB-0.1.0/pkgB.nimble-link
new file mode 100644
index 000000000..9643c0fa0
--- /dev/null
+++ b/tests/nimble/nimbleDir/linkedPkgs/pkgB-0.1.0/pkgB.nimble-link
@@ -0,0 +1,2 @@
+../../simplePkgs/pkgB-0.1.0/pkgB.nimble
+../../simplePkgs/pkgB-0.1.0/
\ No newline at end of file
diff --git a/tests/nimble/tnimblepathlink.nim b/tests/nimble/tnimblepathlink.nim
new file mode 100644
index 000000000..5b2c7cb5b
--- /dev/null
+++ b/tests/nimble/tnimblepathlink.nim
@@ -0,0 +1,9 @@
+discard """
+  action: run
+  cmd: "nim $target --nimblePath:$fileDir/nimbleDir/linkedPkgs $options $file"
+"""
+import pkgA/module as A
+import pkgB/module as B
+
+doAssert pkgATest() == 1, "Simple linked pkgA-0.1.0 wasn't added to path correctly."
+doAssert pkgBTest() == 0xDEADBEEF, "linked pkgB-#head wasn't picked over pkgB-0.1.0"
\ No newline at end of file
diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim
index 06fd4acec..e4bbc3a00 100644
--- a/tests/testament/tester.nim
+++ b/tests/testament/tester.nim
@@ -80,7 +80,6 @@ proc callCompiler(cmdTemplate, filename, options: string,
   let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target],
                        "options", options, "file", filename.quoteShell,
                        "filedir", filename.getFileDir()])
-  echo(c)
   var p = startProcess(command=c[0], args=c[1.. ^1],
                        options={poStdErrToStdOut, poUsePath})
   let outp = p.outputStream