compiler/options: only check the last folder for a candidate (#12421)
This prevents a nimble file from causing a different project to be targeted instead of the desired one.
This commit is contained in:
parent
734da9e1df
commit
37dfb7ecc6
1 changed files with 8 additions and 9 deletions
|
|
@ -665,6 +665,7 @@ proc findProjectNimFile*(conf: ConfigRef; pkg: string): string =
|
|||
var
|
||||
candidates: seq[string] = @[]
|
||||
dir = pkg
|
||||
prev = dir
|
||||
nimblepkg = ""
|
||||
let pkgname = pkg.lastPathPart()
|
||||
while true:
|
||||
|
|
@ -678,15 +679,12 @@ proc findProjectNimFile*(conf: ConfigRef; pkg: string): string =
|
|||
if ext == ".nimble":
|
||||
if nimblepkg.len == 0:
|
||||
nimblepkg = name
|
||||
# Scan subfolders for package source since nimble supports that.
|
||||
# To save time we only scan with the depth of one as that's the
|
||||
# common scenario.
|
||||
let x = x.extractFilename()
|
||||
for k, d in os.walkDir(dir):
|
||||
if k == pcDir:
|
||||
for k, f in os.walkDir(d, relative = true):
|
||||
if k == pcFile and f == x:
|
||||
candidates.add d / f
|
||||
# Since nimble packages can have their source in a subfolder,
|
||||
# check the last folder we were in for a possible match.
|
||||
if dir != prev:
|
||||
let x = prev / x.extractFilename()
|
||||
if fileExists(x):
|
||||
candidates.add x
|
||||
else:
|
||||
# If we found more than one nimble file, chances are that we
|
||||
# missed the real project file, or this is an invalid nimble
|
||||
|
|
@ -697,6 +695,7 @@ proc findProjectNimFile*(conf: ConfigRef; pkg: string): string =
|
|||
if pkgname in c.extractFilename(): return c
|
||||
if candidates.len > 0:
|
||||
return candidates[0]
|
||||
prev = dir
|
||||
dir = parentDir(dir)
|
||||
if dir == "": break
|
||||
return ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue