Merge pull request #2358 from gradha/pr_expands_paths_in_find_exe
Expands tildes for entries in $PATH when looking for a binary.
This commit is contained in:
commit
880e39d123
1 changed files with 7 additions and 2 deletions
|
|
@ -1863,16 +1863,21 @@ proc getFileSize*(file: string): BiggestInt {.rtl, extern: "nos$1",
|
||||||
close(f)
|
close(f)
|
||||||
else: raiseOSError(osLastError())
|
else: raiseOSError(osLastError())
|
||||||
|
|
||||||
|
proc expandTilde*(path: string): string {.tags: [ReadEnvEffect].}
|
||||||
|
|
||||||
proc findExe*(exe: string): string {.tags: [ReadDirEffect, ReadEnvEffect].} =
|
proc findExe*(exe: string): string {.tags: [ReadDirEffect, ReadEnvEffect].} =
|
||||||
## Searches for `exe` in the current working directory and then
|
## Searches for `exe` in the current working directory and then
|
||||||
## in directories listed in the ``PATH`` environment variable.
|
## in directories listed in the ``PATH`` environment variable.
|
||||||
## Returns "" if the `exe` cannot be found. On DOS-like platforms, `exe`
|
## Returns "" if the `exe` cannot be found. On DOS-like platforms, `exe`
|
||||||
## is added an ``.exe`` file extension if it has no extension.
|
## is added the `ExeExt <#ExeExt>`_ file extension if it has none.
|
||||||
result = addFileExt(exe, os.ExeExt)
|
result = addFileExt(exe, os.ExeExt)
|
||||||
if existsFile(result): return
|
if existsFile(result): return
|
||||||
var path = string(os.getEnv("PATH"))
|
var path = string(os.getEnv("PATH"))
|
||||||
for candidate in split(path, PathSep):
|
for candidate in split(path, PathSep):
|
||||||
var x = candidate / result
|
when defined(windows):
|
||||||
|
var x = candidate / result
|
||||||
|
else:
|
||||||
|
var x = expandTilde(candidate) / result
|
||||||
if existsFile(x): return x
|
if existsFile(x): return x
|
||||||
result = ""
|
result = ""
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue