--filenames:abs|canonical|legacyRelProj for filenames in compiler msgs (replaces --listfullpaths:on|off) (#17746)
* use canonicalImport for filename_magicSauce * --filenames:abs|canonical|magic * rename: magic => legacyRelProj
This commit is contained in:
parent
c631648cb3
commit
da1c1a7117
9 changed files with 72 additions and 41 deletions
|
|
@ -13,7 +13,7 @@ import
|
|||
|
||||
from terminal import isatty
|
||||
from times import utc, fromUnix, local, getTime, format, DateTime
|
||||
|
||||
from std/private/globs import nativeToUnixPath
|
||||
const
|
||||
hasTinyCBackend* = defined(tinyc)
|
||||
useEffectSystem* = true
|
||||
|
|
@ -78,7 +78,6 @@ type # please make sure we have under 32 options
|
|||
optWholeProject # for 'doc': output any dependency
|
||||
optDocInternal # generate documentation for non-exported symbols
|
||||
optMixedMode # true if some module triggered C++ codegen
|
||||
optListFullPaths # use full paths in toMsgFilename
|
||||
optDeclaredLocs # show declaration locations in messages
|
||||
optNoNimblePath
|
||||
optHotCodeReloading
|
||||
|
|
@ -258,6 +257,14 @@ type
|
|||
stdOrrStdout
|
||||
stdOrrStderr
|
||||
|
||||
FilenameOption* = enum
|
||||
foAbs # absolute path, e.g.: /pathto/bar/foo.nim
|
||||
foRelProject # relative to project path, e.g.: ../foo.nim
|
||||
foCanonical # canonical module name
|
||||
foLegacyRelProj # legacy, shortest of (foAbs, foRelProject)
|
||||
foName # lastPathPart, e.g.: foo.nim
|
||||
foStacktrace # if optExcessiveStackTrace: foAbs else: foName
|
||||
|
||||
ConfigRef* = ref object ## every global configuration
|
||||
## fields marked with '*' are subject to
|
||||
## the incremental compilation mechanisms
|
||||
|
|
@ -270,6 +277,7 @@ type
|
|||
macrosToExpand*: StringTableRef
|
||||
arcToExpand*: StringTableRef
|
||||
m*: MsgConfig
|
||||
filenameOption*: FilenameOption # how to render paths in compiler messages
|
||||
evalTemplateCounter*: int
|
||||
evalMacroCounter*: int
|
||||
exitcode*: int8
|
||||
|
|
@ -413,8 +421,7 @@ const
|
|||
optBoundsCheck, optOverflowCheck, optAssert, optWarns, optRefCheck,
|
||||
optHints, optStackTrace, optLineTrace, # consider adding `optStackTraceMsgs`
|
||||
optTrMacros, optStyleCheck, optCursorInference}
|
||||
DefaultGlobalOptions* = {optThreadAnalysis,
|
||||
optExcessiveStackTrace, optListFullPaths}
|
||||
DefaultGlobalOptions* = {optThreadAnalysis, optExcessiveStackTrace}
|
||||
|
||||
proc getSrcTimestamp(): DateTime =
|
||||
try:
|
||||
|
|
@ -461,6 +468,7 @@ proc newConfigRef*(): ConfigRef =
|
|||
macrosToExpand: newStringTable(modeStyleInsensitive),
|
||||
arcToExpand: newStringTable(modeStyleInsensitive),
|
||||
m: initMsgConfig(),
|
||||
filenameOption: foAbs,
|
||||
cppDefines: initHashSet[string](),
|
||||
headerFile: "", features: {}, legacyFeatures: {}, foreignPackageNotes: foreignPackageNotesDefault,
|
||||
notes: NotesVerbosity[1], mainPackageNotes: NotesVerbosity[1],
|
||||
|
|
@ -514,6 +522,7 @@ proc newConfigRef*(): ConfigRef =
|
|||
|
||||
proc newPartialConfigRef*(): ConfigRef =
|
||||
## create a new ConfigRef that is only good enough for error reporting.
|
||||
# xxx FACTOR with `newConfigRef`
|
||||
when defined(nimDebugUtils):
|
||||
result = getConfigRef()
|
||||
else:
|
||||
|
|
@ -522,6 +531,7 @@ proc newPartialConfigRef*(): ConfigRef =
|
|||
verbosity: 1,
|
||||
options: DefaultOptions,
|
||||
globalOptions: DefaultGlobalOptions,
|
||||
filenameOption: foAbs,
|
||||
foreignPackageNotes: foreignPackageNotesDefault,
|
||||
notes: NotesVerbosity[1], mainPackageNotes: NotesVerbosity[1])
|
||||
|
||||
|
|
@ -885,6 +895,25 @@ proc findProjectNimFile*(conf: ConfigRef; pkg: string): string =
|
|||
if dir == "": break
|
||||
return ""
|
||||
|
||||
proc canonicalImportAux*(conf: ConfigRef, file: AbsoluteFile): string =
|
||||
##[
|
||||
Shows the canonical module import, e.g.:
|
||||
system, std/tables, fusion/pointers, system/assertions, std/private/asciitables
|
||||
]##
|
||||
var ret = getRelativePathFromConfigPath(conf, file, isTitle = true)
|
||||
let dir = getNimbleFile(conf, $file).parentDir.AbsoluteDir
|
||||
if not dir.isEmpty:
|
||||
let relPath = relativeTo(file, dir)
|
||||
if not relPath.isEmpty and (ret.isEmpty or relPath.string.len < ret.string.len):
|
||||
ret = relPath
|
||||
if ret.isEmpty:
|
||||
ret = relativeTo(file, conf.projectPath)
|
||||
result = ret.string
|
||||
|
||||
proc canonicalImport*(conf: ConfigRef, file: AbsoluteFile): string =
|
||||
let ret = canonicalImportAux(conf, file)
|
||||
result = ret.nativeToUnixPath.changeFileExt("")
|
||||
|
||||
proc canonDynlibName(s: string): string =
|
||||
let start = if s.startsWith("lib"): 3 else: 0
|
||||
let ende = strutils.find(s, {'(', ')', '.'})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue