summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2021-02-12 14:50:41 -0800
committerGitHub <noreply@github.com>2021-02-12 23:50:41 +0100
commit4326f743d0fe6fb206047db8025206d3cf0d554b (patch)
treec810e66f1468685e09c94d5ae43887926552bd80
parentafa87f223cdb9fd10e8b6f70aad51c44da7303a7 (diff)
downloadNim-4326f743d0fe6fb206047db8025206d3cf0d554b.tar.gz
compilesettings: add libpath (#16997)
* compilesettings: add libpath

* add test

* changelog

* fixup

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
-rw-r--r--changelog.md1
-rw-r--r--compiler/nimeval.nim7
-rw-r--r--compiler/vmops.nim1
-rw-r--r--lib/std/compilesettings.nim1
-rw-r--r--nimsuggest/tester.nim6
-rw-r--r--tests/vm/tcompilesetting.nim23
6 files changed, 20 insertions, 19 deletions
diff --git a/changelog.md b/changelog.md
index a4833bbd3..5adb15ff9 100644
--- a/changelog.md
+++ b/changelog.md
@@ -142,6 +142,7 @@ provided by the operating system.
 
 - Added experimental `linenoise.readLineStatus` to get line and status (e.g. ctrl-D or ctrl-C).
 
+- Added `compilesettings.SingleValueSetting.libPath`
 - `std/wrapnils` doesn't use `experimental:dotOperators` anymore, avoiding
   issues like https://github.com/nim-lang/Nim/issues/13063 (which affected error messages)
   for modules importing `std/wrapnils`.
diff --git a/compiler/nimeval.nim b/compiler/nimeval.nim
index 0170c9949..9be595cce 100644
--- a/compiler/nimeval.nim
+++ b/compiler/nimeval.nim
@@ -12,7 +12,7 @@ import
   ast, astalgo, modules, passes, condsyms,
   options, sem, llstream, lineinfos, vm,
   vmdef, modulegraphs, idents, os, pathutils,
-  passaux, scriptconfig
+  passaux, scriptconfig, std/compilesettings
 
 type
   Interpreter* = ref object ## Use Nim as an interpreter with this object
@@ -92,10 +92,9 @@ proc findNimStdLib*(): string =
     return ""
 
 proc findNimStdLibCompileTime*(): string =
-  ## Same as ``findNimStdLib`` but uses source files used at compile time,
+  ## Same as `findNimStdLib` but uses source files used at compile time,
   ## and asserts on error.
-  const exe = getCurrentCompilerExe()
-  result = exe.splitFile.dir.parentDir / "lib"
+  result = querySetting(libPath)
   doAssert fileExists(result / "system.nim"), "result:" & result
 
 proc createInterpreter*(scriptName: string;
diff --git a/compiler/vmops.nim b/compiler/vmops.nim
index ec44a7c08..eb861cd54 100644
--- a/compiler/vmops.nim
+++ b/compiler/vmops.nim
@@ -131,6 +131,7 @@ when defined(nimHasInvariant):
     of compileOptions: result = conf.compileOptions
     of ccompilerPath: result = conf.cCompilerPath
     of backend: result = $conf.backend
+    of libPath: result = conf.libpath.string
 
   proc querySettingSeqImpl(conf: ConfigRef, switch: BiggestInt): seq[string] =
     template copySeq(field: untyped): untyped =
diff --git a/lib/std/compilesettings.nim b/lib/std/compilesettings.nim
index 5f3da011e..7058e55a5 100644
--- a/lib/std/compilesettings.nim
+++ b/lib/std/compilesettings.nim
@@ -31,6 +31,7 @@ type
     ccompilerPath     ## the path to the C/C++ compiler
     backend           ## the backend (eg: c|cpp|objc|js); both `nim doc --backend:js`
                       ## and `nim js` would imply backend=js
+    libPath           ## the absolute path to the stdlib library, i.e. nim's `--lib`, since 1.5.1
 
   MultipleValueSetting* {.pure.} = enum ## \
                       ## settings resulting in a seq of string values
diff --git a/nimsuggest/tester.nim b/nimsuggest/tester.nim
index 019181810..425430ede 100644
--- a/nimsuggest/tester.nim
+++ b/nimsuggest/tester.nim
@@ -18,10 +18,12 @@ const
 
 template tpath(): untyped = getAppDir() / "tests"
 
+import std/compilesettings
+
 proc parseTest(filename: string; epcMode=false): Test =
   const cursorMarker = "#[!]#"
   let nimsug = curDir & addFileExt("nimsuggest", ExeExt)
-  let libpath = findExe("nim").splitFile().dir /../ "lib"
+  const libpath = querySetting(libPath)
   result.filename = filename
   result.dest = getTempDir() / extractFilename(filename)
   result.cmd = nimsug & " --tester " & result.dest
@@ -329,7 +331,7 @@ proc main() =
     failures += runTest(xx)
     failures += runEpcTest(xx)
   else:
-    for x in walkFiles(getAppDir() / "tests/t*.nim"):
+    for x in walkFiles(tpath() / "t*.nim"):
       echo "Test ", x
       let xx = expandFilename x
       when not defined(windows):
diff --git a/tests/vm/tcompilesetting.nim b/tests/vm/tcompilesetting.nim
index 98565ab94..5bf559c74 100644
--- a/tests/vm/tcompilesetting.nim
+++ b/tests/vm/tcompilesetting.nim
@@ -3,18 +3,15 @@ cmd: "nim c --nimcache:build/myNimCache --nimblePath:myNimblePath $file"
 joinable: false
 """
 
-import strutils
+import std/[strutils,compilesettings]
+from std/os import fileExists, `/`
 
-import std / compilesettings
+template main =
+  doAssert querySetting(nimcacheDir) == nimcacheDir.querySetting
+  doAssert "myNimCache" in nimcacheDir.querySetting
+  doAssert "myNimblePath" in nimblePaths.querySettingSeq[0]
+  doAssert querySetting(backend) == "c"
+  doAssert fileExists(libPath.querySetting / "system.nim")
 
-const
-  nc = querySetting(nimcacheDir)
-  np = querySettingSeq(nimblePaths)
-
-static:
-  echo nc
-  echo np
-
-doAssert "myNimCache" in nc
-doAssert "myNimblePath" in np[0]
-doAssert querySetting(backend) == "c"
+static: main()
+main()