mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-29 01:51:43 +00:00
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:
@@ -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 ""
|
||||
|
||||
Reference in New Issue
Block a user