Show better error when standard library cannot be found.
This commit is contained in:
parent
c8cd1d9286
commit
182893c529
2 changed files with 21 additions and 3 deletions
|
|
@ -188,7 +188,10 @@ proc setupVM(module: PSym; scriptName: string, flags: Flags): PEvalContext =
|
||||||
else:
|
else:
|
||||||
flags[key] = @[value]
|
flags[key] = @[value]
|
||||||
|
|
||||||
proc getNimPrefixDir(): string =
|
proc isValidLibPath(lib: string): bool =
|
||||||
|
return fileExists(lib / "system.nim")
|
||||||
|
|
||||||
|
proc getNimPrefixDir: string =
|
||||||
let env = getEnv("NIM_LIB_PREFIX")
|
let env = getEnv("NIM_LIB_PREFIX")
|
||||||
if env != "":
|
if env != "":
|
||||||
return env
|
return env
|
||||||
|
|
@ -221,6 +224,19 @@ proc execScript(scriptName: string, flags: Flags, options: Options): PSym =
|
||||||
# Ensure the compiler can find its standard library #220.
|
# Ensure the compiler can find its standard library #220.
|
||||||
compiler_options.gPrefixDir = getNimPrefixDir()
|
compiler_options.gPrefixDir = getNimPrefixDir()
|
||||||
|
|
||||||
|
# Verify that lib path points to existing stdlib.
|
||||||
|
compiler_options.setDefaultLibpath()
|
||||||
|
if not isValidLibPath(compiler_options.libpath):
|
||||||
|
let msg = "Nimble cannot find Nim's standard library.\nLast try in:\n - $1" %
|
||||||
|
compiler_options.libpath
|
||||||
|
let hint = "Nimble does its best to find Nim's standard library, " &
|
||||||
|
"sometimes this fails. You can set the environment variable " &
|
||||||
|
"NIM_LIB_PREFIX to where Nim's `lib` directory is located as " &
|
||||||
|
"a workaround. " &
|
||||||
|
"See https://github.com/nim-lang/nimble#troubleshooting for " &
|
||||||
|
"more info."
|
||||||
|
raiseNimbleError(msg, hint)
|
||||||
|
|
||||||
let pkgName = scriptName.splitFile.name
|
let pkgName = scriptName.splitFile.name
|
||||||
|
|
||||||
# Ensure that "nimblepkg/nimscriptapi" is in the PATH.
|
# Ensure that "nimblepkg/nimscriptapi" is in the PATH.
|
||||||
|
|
|
||||||
|
|
@ -329,12 +329,14 @@ proc readPackageInfo(nf: NimbleFile, options: Options,
|
||||||
try:
|
try:
|
||||||
readPackageInfoFromNims(nf, options, result)
|
readPackageInfoFromNims(nf, options, result)
|
||||||
result.isNimScript = true
|
result.isNimScript = true
|
||||||
except NimbleError:
|
except NimbleError as exc:
|
||||||
|
if exc.hint.len > 0:
|
||||||
|
raise
|
||||||
let msg = "Could not read package info file in " & nf & ";\n" &
|
let msg = "Could not read package info file in " & nf & ";\n" &
|
||||||
" Reading as ini file failed with: \n" &
|
" Reading as ini file failed with: \n" &
|
||||||
" " & iniError.msg & ".\n" &
|
" " & iniError.msg & ".\n" &
|
||||||
" Evaluating as NimScript file failed with: \n" &
|
" Evaluating as NimScript file failed with: \n" &
|
||||||
" " & getCurrentExceptionMsg() & "."
|
" " & exc.msg & "."
|
||||||
raise newException(NimbleError, msg)
|
raise newException(NimbleError, msg)
|
||||||
|
|
||||||
# By default specialVersion is the same as version.
|
# By default specialVersion is the same as version.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue