Skip to content

Commit

Permalink
correctly honor cmdline --hint:conf:on/off ; correctly show Conf hint…
Browse files Browse the repository at this point in the history
…s in order
  • Loading branch information
timotheecour committed Feb 26, 2020
1 parent ed82b9a commit 8a3eb98
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 3 deletions.
2 changes: 2 additions & 0 deletions compiler/cmdlinehelper.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ proc initDefinesProg*(self: NimProg, conf: ConfigRef, name: string) =
defineSymbol conf.symbols, name

proc processCmdLineAndProjectPath*(self: NimProg, conf: ConfigRef) =
conf.isCmdLine = true
self.processCmdLine(passCmd1, "", conf)
conf.isCmdLine = false
if self.supportsStdinFile and conf.projectName == "-":
handleStdinInput(conf)
elif conf.projectName != "":
Expand Down
6 changes: 6 additions & 0 deletions compiler/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,17 @@ proc processSpecificNote*(arg: string, state: TSpecialWord, pass: TCmdLinePass,
incl(conf.notes, n)
incl(conf.mainPackageNotes, n)
incl(conf.enableNotes, n)
if conf.isCmdLine:
incl(conf.cmdLineNotes, n)
excl(conf.cmdLineDisabledNotes, n)
of "off":
excl(conf.notes, n)
excl(conf.mainPackageNotes, n)
incl(conf.disableNotes, n)
excl(conf.foreignPackageNotes, n)
if conf.isCmdLine:
incl(conf.cmdLineDisabledNotes, n)
excl(conf.cmdLineNotes, n)
else: localError(conf, info, errOnOrOffExpectedButXFound % arg)

proc processCompile(conf: ConfigRef; filename: string) =
Expand Down
5 changes: 4 additions & 1 deletion compiler/msgs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,10 @@ proc rawMessage*(conf: ConfigRef; msg: TMsgKind, args: openArray[string]) =
inc(conf.warnCounter)
of hintMin..hintMax:
sev = Severity.Hint
if not conf.hasHint(msg): return
if msg in conf.cmdLineDisabledNotes: return # eg: `--hints:conf:off` passed on cmdline
# handle `--hints:off` (regardless of cmdline/cfg file)
# handle `--hints:conf:on` on cmdline
if not conf.hasHint(msg) and not (optHints in conf.options and msg in conf.cmdLineNotes)): return
title = HintTitle
color = HintColor
if msg != hintUserRaw: kind = HintsToStr[ord(msg) - ord(hintMin)]
Expand Down
1 change: 1 addition & 0 deletions compiler/nimconf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef) =
template runNimScriptIfExists(path: AbsoluteFile) =
let p = path # eval once
if fileExists(p):
configFiles.add(p)
runNimScript(cache, p, freshDefines = false, conf)

if optSkipSystemConfigFile notin conf.globalOptions:
Expand Down
4 changes: 4 additions & 0 deletions compiler/options.nim
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ type
foreignPackageNotes*: TNoteKinds
notes*: TNoteKinds
mainPackageNotes*: TNoteKinds
cmdLineNotes*: TNoteKinds
cmdLineDisabledNotes*: TNoteKinds
mainPackageId*: int
errorCounter*: int
hintCounter*: int
Expand Down Expand Up @@ -286,6 +288,7 @@ type
structuredErrorHook*: proc (config: ConfigRef; info: TLineInfo; msg: string;
severity: Severity) {.closure, gcsafe.}
cppCustomNamespace*: string
isCmdLine*: bool # whether we are currently processing cmdline args, not cfg files

proc hasHint*(conf: ConfigRef, note: TNoteKind): bool =
optHints in conf.options and note in conf.notes
Expand Down Expand Up @@ -391,6 +394,7 @@ proc newConfigRef*(): ConfigRef =
arguments: "",
suggestMaxResults: 10_000,
maxLoopIterationsVM: 10_000_000,
isCmdLine: false,
)
setTargetFromSystem(result.target)
# enable colors by default on terminals
Expand Down
3 changes: 1 addition & 2 deletions compiler/scriptconfig.nim
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ proc setupVM*(module: PSym; cache: IdentCache; scriptName: string;

proc runNimScript*(cache: IdentCache; scriptName: AbsoluteFile;
freshDefines=true; conf: ConfigRef) =
rawMessage(conf, hintConf, scriptName.string)
let oldSymbolFiles = conf.symbolFiles
conf.symbolFiles = disabledSf

Expand All @@ -224,7 +223,7 @@ proc runNimScript*(cache: IdentCache; scriptName: AbsoluteFile;
incl(m.flags, sfMainModule)
graph.vm = setupVM(m, cache, scriptName.string, graph)

graph.compileSystemModule() # TODO: see why this unsets hintConf in conf.notes
graph.compileSystemModule()
discard graph.processModule(m, llStreamOpen(scriptName, fmRead))

# watch out, "newruntime" can be set within NimScript itself and then we need
Expand Down

0 comments on commit 8a3eb98

Please sign in to comment.