compiler/[msgs, options]: confine --listFullPaths to compiler messages (#11583)

* compiler/[msgs, options]: make toFilename independent of listFullPaths

toFilename is used mainly in codegen, as such it should not follow
--listFullPaths

* compiler/msgs: use toMsgFilename for toFileLineCol

This proc is mainly used for compiler messages, so it should follow
--listFullPaths

* compiler/msgs: remove toFileLine

unused proc

* compiler/msgs: cleanup toMsgFilename

Also improved path choosing logic, /home should now be preferred over
../home on *nix
This commit is contained in:
alaviss 2019-06-26 07:40:11 +07:00 • committed by Andreas Rumpf
commit 2f1a1b7106
2 changed files with 13 additions and 17 deletions

View file

@ -159,10 +159,7 @@ template toFilename*(conf: ConfigRef; fileIdx: FileIndex): string =
if fileIdx.int32 < 0 or conf == nil: if fileIdx.int32 < 0 or conf == nil:
"???" "???"
else: else:
if optListFullPaths in conf.globalOptions: conf.m.fileInfos[fileIdx.int32].projPath.string
conf.m.fileInfos[fileIdx.int32].fullPath.string
else:
conf.m.fileInfos[fileIdx.int32].projPath.string
proc toFullPath*(conf: ConfigRef; fileIdx: FileIndex): string = proc toFullPath*(conf: ConfigRef; fileIdx: FileIndex): string =
if fileIdx.int32 < 0 or conf == nil: result = "???" if fileIdx.int32 < 0 or conf == nil: result = "???"
@ -200,14 +197,16 @@ template toFullPathConsiderDirty*(conf: ConfigRef; info: TLineInfo): string =
proc toMsgFilename*(conf: ConfigRef; info: TLineInfo): string = proc toMsgFilename*(conf: ConfigRef; info: TLineInfo): string =
if info.fileIndex.int32 < 0: if info.fileIndex.int32 < 0:
result = "???" return "???"
return let
let absPath = conf.m.fileInfos[info.fileIndex.int32].fullPath.string absPath = conf.m.fileInfos[info.fileIndex.int32].fullPath.string
if optListFullPaths in conf.globalOptions: relPath = conf.m.fileInfos[info.fileIndex.int32].projPath.string
result = absPath result = if (optListFullPaths in conf.globalOptions) or
else: (relPath.len > absPath.len) or
let relPath = conf.m.fileInfos[info.fileIndex.int32].projPath.string (relPath.count("..") > 2):
result = if relPath.count("..") > 2: absPath else: relPath absPath
else:
relPath
proc toLinenumber*(info: TLineInfo): int {.inline.} = proc toLinenumber*(info: TLineInfo): int {.inline.} =
result = int info.line result = int info.line
@ -215,12 +214,9 @@ proc toLinenumber*(info: TLineInfo): int {.inline.} =
proc toColumn*(info: TLineInfo): int {.inline.} = proc toColumn*(info: TLineInfo): int {.inline.} =
result = info.col result = info.col
proc toFileLine*(conf: ConfigRef; info: TLineInfo): string {.inline.} =
result = toFilename(conf, info) & ":" & $info.line
proc toFileLineCol*(conf: ConfigRef; info: TLineInfo): string {.inline.} = proc toFileLineCol*(conf: ConfigRef; info: TLineInfo): string {.inline.} =
# consider calling `helpers.lineInfoToString` instead # consider calling `helpers.lineInfoToString` instead
result = toFilename(conf, info) & "(" & $info.line & ", " & result = toMsgFilename(conf, info) & "(" & $info.line & ", " &
$(info.col + ColOffset) & ")" $(info.col + ColOffset) & ")"
proc `$`*(conf: ConfigRef; info: TLineInfo): string = toFileLineCol(conf, info) proc `$`*(conf: ConfigRef; info: TLineInfo): string = toFileLineCol(conf, info)

View file

@ -78,7 +78,7 @@ type # please make sure we have under 32 options
optWholeProject # for 'doc2': output any dependency optWholeProject # for 'doc2': output any dependency
optDocInternal # generate documentation for non-exported symbols optDocInternal # generate documentation for non-exported symbols
optMixedMode # true if some module triggered C++ codegen optMixedMode # true if some module triggered C++ codegen
optListFullPaths # use full paths in toMsgFilename, toFilename optListFullPaths # use full paths in toMsgFilename
optNoNimblePath optNoNimblePath
optHotCodeReloading optHotCodeReloading
optDynlibOverrideAll optDynlibOverrideAll