diff options
Diffstat (limited to 'compiler/options.nim')
-rw-r--r-- | compiler/options.nim | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/compiler/options.nim b/compiler/options.nim index 3c91d4439..ea6b91321 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -208,7 +208,31 @@ proc removeTrailingDirSep*(path: string): string = proc getGeneratedPath: string = result = if nimcacheDir.len > 0: nimcacheDir else: gProjectPath.shortenDir / genSubDir - + +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 = "" + +proc withPackageName*(path: string): string = + let x = path.getPackageName + if x.len == 0: + result = path + else: + let (p, file, ext) = path.splitFile + result = (p / (x & '_' & file)) & ext + proc toGeneratedFile*(path, ext: string): string = ## converts "/home/a/mymodule.nim", "rod" to "/home/a/nimcache/mymodule.rod" var (head, tail) = splitPath(path) @@ -261,9 +285,13 @@ proc FindFile*(f: string): string {.procvar.} = if result.len == 0: result = f.toLower.rawFindFile2 -proc findModule*(modulename: string): string {.inline.} = +proc findModule*(modulename, currentModule: string): string = # returns path to module - result = FindFile(AddFileExt(modulename, nimExt)) + let m = addFileExt(modulename, nimExt) + let currentPath = currentModule.splitFile.dir + result = currentPath / m + if not existsFile(result): + result = FindFile(m) proc libCandidates*(s: string, dest: var seq[string]) = var le = strutils.find(s, '(') |