diff options
author | EXetoC <exetoc@gmail.com> | 2014-03-06 02:46:31 +0100 |
---|---|---|
committer | EXetoC <exetoc@gmail.com> | 2014-03-06 02:46:31 +0100 |
commit | d1bc6cf0981eddf283515c2d77bccca76abff99f (patch) | |
tree | ac28e32bd6143c7a06c44dbea632f28f65ea3d20 /compiler/options.nim | |
parent | 853bdbf4948db7774bc3caf74f67ba1228f65016 (diff) | |
parent | 7904446c47f952a026d408f04431dbaf6d887b37 (diff) | |
download | Nim-d1bc6cf0981eddf283515c2d77bccca76abff99f.tar.gz |
Merge branch 'devel' into alloc-overloads
Diffstat (limited to 'compiler/options.nim')
-rw-r--r-- | compiler/options.nim | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/compiler/options.nim b/compiler/options.nim index 4f642e626..102ebc386 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -209,21 +209,42 @@ proc getGeneratedPath: string = result = if nimcacheDir.len > 0: nimcacheDir else: gProjectPath.shortenDir / genSubDir +template newPackageCache(): expr = + newStringTable(when FileSystemCaseSensitive: + modeCaseInsensitive + else: + modeCaseSensitive) + +var packageCache = newPackageCache() + +proc resetPackageCache*() = packageCache = newPackageCache() + +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 getPackageName*(path: string): string = - var q = 1 - var b = 0 - if path[len(path)-1] in {DirSep, AltSep}: q = 2 - for i in countdown(len(path)-q, 0): - if path[i] in {DirSep, AltSep}: - if b == 0: b = i - else: - let x = path.substr(i+1, b-1) - case x.normalize - of "lib", "src", "source", "package", "pckg", "library", "private": - b = i - else: - return x.replace('.', '_') - result = "" + var parents = 0 + block packageSearch: + for d in myParentDirs(path): + if packageCache.hasKey(d): + #echo "from cache ", d, " |", packageCache[d], "|", path.splitFile.name + return packageCache[d] + inc parents + for file in walkFiles(d / "*.babel"): + result = file.splitFile.name + break packageSearch + # we also store if we didn't find anything: + if result.isNil: result = "" + for d in myParentDirs(path): + #echo "set cache ", d, " |", result, "|", parents + packageCache[d] = result + dec parents + if parents <= 0: break proc withPackageName*(path: string): string = let x = path.getPackageName |