compilesettings: add libpath (#16997)

* compilesettings: add libpath

* add test

* changelog

* fixup

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
Timothee Cour 2021-02-12 14:50:41 -08:00 • committed by GitHub
commit 4326f743d0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 19 deletions

View file

@ -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 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 - `std/wrapnils` doesn't use `experimental:dotOperators` anymore, avoiding
issues like https://github.com/nim-lang/Nim/issues/13063 (which affected error messages) issues like https://github.com/nim-lang/Nim/issues/13063 (which affected error messages)
for modules importing `std/wrapnils`. for modules importing `std/wrapnils`.

View file

@ -12,7 +12,7 @@ import
ast, astalgo, modules, passes, condsyms, ast, astalgo, modules, passes, condsyms,
options, sem, llstream, lineinfos, vm, options, sem, llstream, lineinfos, vm,
vmdef, modulegraphs, idents, os, pathutils, vmdef, modulegraphs, idents, os, pathutils,
passaux, scriptconfig passaux, scriptconfig, std/compilesettings
type type
Interpreter* = ref object ## Use Nim as an interpreter with this object Interpreter* = ref object ## Use Nim as an interpreter with this object
@ -92,10 +92,9 @@ proc findNimStdLib*(): string =
return "" return ""
proc findNimStdLibCompileTime*(): string = 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. ## and asserts on error.
const exe = getCurrentCompilerExe() result = querySetting(libPath)
result = exe.splitFile.dir.parentDir / "lib"
doAssert fileExists(result / "system.nim"), "result:" & result doAssert fileExists(result / "system.nim"), "result:" & result
proc createInterpreter*(scriptName: string; proc createInterpreter*(scriptName: string;

View file

@ -131,6 +131,7 @@ when defined(nimHasInvariant):
of compileOptions: result = conf.compileOptions of compileOptions: result = conf.compileOptions
of ccompilerPath: result = conf.cCompilerPath of ccompilerPath: result = conf.cCompilerPath
of backend: result = $conf.backend of backend: result = $conf.backend
of libPath: result = conf.libpath.string
proc querySettingSeqImpl(conf: ConfigRef, switch: BiggestInt): seq[string] = proc querySettingSeqImpl(conf: ConfigRef, switch: BiggestInt): seq[string] =
template copySeq(field: untyped): untyped = template copySeq(field: untyped): untyped =

View file

@ -31,6 +31,7 @@ type
ccompilerPath ## the path to the C/C++ compiler ccompilerPath ## the path to the C/C++ compiler
backend ## the backend (eg: c|cpp|objc|js); both `nim doc --backend:js` backend ## the backend (eg: c|cpp|objc|js); both `nim doc --backend:js`
## and `nim js` would imply 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 ## \ MultipleValueSetting* {.pure.} = enum ## \
## settings resulting in a seq of string values ## settings resulting in a seq of string values

View file

@ -18,10 +18,12 @@ const
template tpath(): untyped = getAppDir() / "tests" template tpath(): untyped = getAppDir() / "tests"
import std/compilesettings
proc parseTest(filename: string; epcMode=false): Test = proc parseTest(filename: string; epcMode=false): Test =
const cursorMarker = "#[!]#" const cursorMarker = "#[!]#"
let nimsug = curDir & addFileExt("nimsuggest", ExeExt) let nimsug = curDir & addFileExt("nimsuggest", ExeExt)
let libpath = findExe("nim").splitFile().dir /../ "lib" const libpath = querySetting(libPath)
result.filename = filename result.filename = filename
result.dest = getTempDir() / extractFilename(filename) result.dest = getTempDir() / extractFilename(filename)
result.cmd = nimsug & " --tester " & result.dest result.cmd = nimsug & " --tester " & result.dest
@ -329,7 +331,7 @@ proc main() =
failures += runTest(xx) failures += runTest(xx)
failures += runEpcTest(xx) failures += runEpcTest(xx)
else: else:
for x in walkFiles(getAppDir() / "tests/t*.nim"): for x in walkFiles(tpath() / "t*.nim"):
echo "Test ", x echo "Test ", x
let xx = expandFilename x let xx = expandFilename x
when not defined(windows): when not defined(windows):

View file

@ -3,18 +3,15 @@ cmd: "nim c --nimcache:build/myNimCache --nimblePath:myNimblePath $file"
joinable: false 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 static: main()
nc = querySetting(nimcacheDir) main()
np = querySettingSeq(nimblePaths)
static:
echo nc
echo np
doAssert "myNimCache" in nc
doAssert "myNimblePath" in np[0]
doAssert querySetting(backend) == "c"