mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
* wip; use strictdefs for compiler * checkpoint * complete the chores * more fixes * first phase cleanup * Update compiler/bitsets.nim * cleanup
45 lines
1.3 KiB
Nim
45 lines
1.3 KiB
Nim
#
|
|
#
|
|
# The Nim Compiler
|
|
# (c) Copyright 2017 Andreas Rumpf
|
|
#
|
|
# See the file "copying.txt", included in this
|
|
# distribution, for details about the copyright.
|
|
#
|
|
|
|
iterator myParentDirs(p: string): string =
|
|
# XXX os's parentDirs is stupid (multiple yields) and triggers an old bug...
|
|
var current = p
|
|
while true:
|
|
current = current.parentDir
|
|
if current.len == 0: break
|
|
yield current
|
|
|
|
proc getNimbleFile*(conf: ConfigRef; path: string): string =
|
|
## returns absolute path to nimble file, e.g.: /pathto/cligen.nimble
|
|
result = ""
|
|
var parents = 0
|
|
block packageSearch:
|
|
for d in myParentDirs(path):
|
|
if conf.packageCache.hasKey(d):
|
|
#echo "from cache ", d, " |", packageCache[d], "|", path.splitFile.name
|
|
return conf.packageCache[d]
|
|
inc parents
|
|
for file in walkFiles(d / "*.nimble"):
|
|
result = file
|
|
break packageSearch
|
|
# we also store if we didn't find anything:
|
|
for d in myParentDirs(path):
|
|
#echo "set cache ", d, " |", result, "|", parents
|
|
conf.packageCache[d] = result
|
|
dec parents
|
|
if parents <= 0: break
|
|
|
|
proc getPackageName*(conf: ConfigRef; path: string): string =
|
|
## returns nimble package name, e.g.: `cligen`
|
|
let path = getNimbleFile(conf, path)
|
|
if path.len > 0:
|
|
return path.splitFile.name
|
|
else:
|
|
return "unknown"
|