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
|
var
|
||||||
candidates: seq[string] = @[]
|
candidates: seq[string] = @[]
|
||||||
dir = pkg
|
dir = pkg
|
||||||
|
prev = dir
|
||||||
nimblepkg = ""
|
nimblepkg = ""
|
||||||
let pkgname = pkg.lastPathPart()
|
let pkgname = pkg.lastPathPart()
|
||||||
while true:
|
while true:
|
||||||
|
|
@ -678,15 +679,12 @@ proc findProjectNimFile*(conf: ConfigRef; pkg: string): string =
|
||||||
if ext == ".nimble":
|
if ext == ".nimble":
|
||||||
if nimblepkg.len == 0:
|
if nimblepkg.len == 0:
|
||||||
nimblepkg = name
|
nimblepkg = name
|
||||||
# Scan subfolders for package source since nimble supports that.
|
# Since nimble packages can have their source in a subfolder,
|
||||||
# To save time we only scan with the depth of one as that's the
|
# check the last folder we were in for a possible match.
|
||||||
# common scenario.
|
if dir != prev:
|
||||||
let x = x.extractFilename()
|
let x = prev / x.extractFilename()
|
||||||
for k, d in os.walkDir(dir):
|
if fileExists(x):
|
||||||
if k == pcDir:
|
candidates.add x
|
||||||
for k, f in os.walkDir(d, relative = true):
|
|
||||||
if k == pcFile and f == x:
|
|
||||||
candidates.add d / f
|
|
||||||
else:
|
else:
|
||||||
# If we found more than one nimble file, chances are that we
|
# If we found more than one nimble file, chances are that we
|
||||||
# missed the real project file, or this is an invalid nimble
|
# 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 pkgname in c.extractFilename(): return c
|
||||||
if candidates.len > 0:
|
if candidates.len > 0:
|
||||||
return candidates[0]
|
return candidates[0]
|
||||||
|
prev = dir
|
||||||
dir = parentDir(dir)
|
dir = parentDir(dir)
|
||||||
if dir == "": break
|
if dir == "": break
|
||||||
return ""
|
return ""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue