Skip to content

Delay the error about missing nim until first usage #1096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 11 additions & 15 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2140,30 +2140,30 @@ proc useLockedNim(options: var Options, realDir: string) =
raise nimbleError("Trying to use nim from $1 " % realDir,
"If you are using develop mode nim make sure to compile it.")

options.nim = nim
options.nimBin = nim
let separator = when defined(windows): ";" else: ":"

putEnv("PATH", realDir / "bin" & separator & getEnv("PATH"))
display("Info:", "using $1 for compilation" % options.nim, priority = HighPriority)

proc setNimBin*(options: var Options) =
# Find nim binary and set into options
if options.nim.len != 0:
if options.nimBin.len != 0:
# --nim:<path> takes priority...
if options.nim.splitPath().head.len == 0:
if options.nimBin.splitPath().head.len == 0:
# Just filename, search in PATH - nim_temp shortcut
let pnim = findExe(options.nim)
let pnim = findExe(options.nimBin)
if pnim.len != 0:
options.nim = pnim
options.nimBin = pnim
else:
raise nimbleError(
"Unable to find `$1` in $PATH" % options.nim)
elif not options.nim.isAbsolute():
"Unable to find `$1` in $PATH" % options.nimBin)
elif not options.nimBin.isAbsolute():
# Relative path
options.nim = expandTilde(options.nim).absolutePath()
options.nimBin = expandTilde(options.nimBin).absolutePath()

if not fileExists(options.nim):
raise nimbleError("Unable to find `$1`" % options.nim)
if not fileExists(options.nimBin):
raise nimbleError("Unable to find `$1`" % options.nimBin)
else:
let lockFile = options.lockFile(getCurrentDir())

Expand All @@ -2184,12 +2184,8 @@ proc setNimBin*(options: var Options) =
break

# Search PATH
if options.nim.len == 0: options.nim = findExe("nim")
if options.nimBin.len == 0: options.nimBin = findExe("nim")

if options.nim.len == 0:
# Nim not found in PATH
raise nimbleError(
"Unable to find `nim` binary - add to $PATH or use `--nim`")

when isMainModule:
var exitCode = QuitSuccess
Expand Down
10 changes: 8 additions & 2 deletions src/nimblepkg/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type
dumpMode*: DumpMode
startDir*: string # Current directory on startup - is top level pkg dir for
# some commands, useful when processing deps
nim*: string # Nim compiler location
nimBin*: string # Nim compiler location. Typically accessed via options.nim.
localdeps*: bool # True if project local deps mode
developLocaldeps*: bool # True if local deps + nimble develop pkg1 ...
disableSslCertCheck*: bool
Expand Down Expand Up @@ -352,6 +352,12 @@ proc promptList*(options: Options, question: string, args: openarray[string]): s
## options is selected.
return promptList(options.forcePrompts, question, args)

proc nim*(options: Options): string =
if options.nimBin.len == 0:
raise nimbleError(
"Unable to find `nim` binary - add to $PATH or use `--nim`")
return options.nimBin

proc getNimbleDir*(options: Options): string =
return options.nimbleDir

Expand Down Expand Up @@ -509,7 +515,7 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
of "offline": result.offline = true
of "nocolor": result.noColor = true
of "disablevalidation": result.disableValidation = true
of "nim": result.nim = val
of "nim": result.nimBin = val
of "localdeps", "l": result.localdeps = true
of "nosslcheck": result.disableSslCertCheck = true
of "nolockfile": result.disableLockFile = true
Expand Down