make SuccessX show project file + output file (#13043)

* make SuccessX show project file + output file
* address comments
* fix test and add `result.err = reNimcCrash` otherwise hard to see where reNimcCrash used
* address comments
This commit is contained in:
Timothee Cour 2020-01-07 15:39:07 -08:00 • committed by Andreas Rumpf
commit 15043d35b8
4 changed files with 29 additions and 14 deletions

View file

@ -97,7 +97,8 @@ const
warnCycleCreated: "$1", warnCycleCreated: "$1",
warnUser: "$1", warnUser: "$1",
hintSuccess: "operation successful: $#", hintSuccess: "operation successful: $#",
hintSuccessX: "operation successful ($# lines compiled; $# sec total; $#; $#)", # keep in sync with `pegSuccess` see testament.nim
hintSuccessX: "$loc LOC; $sec sec; $mem; $build build; $project proj; $output out",
hintCC: "CC: \'$1\'", # unused hintCC: "CC: \'$1\'", # unused
hintLineTooLong: "line too long", hintLineTooLong: "line too long",
hintXDeclaredButNotUsed: "'$1' is declared but not used", hintXDeclaredButNotUsed: "'$1' is declared but not used",

View file

@ -355,16 +355,24 @@ proc mainCommand*(graph: ModuleGraph) =
if conf.errorCounter == 0 and if conf.errorCounter == 0 and
conf.cmd notin {cmdInterpret, cmdRun, cmdDump}: conf.cmd notin {cmdInterpret, cmdRun, cmdDump}:
when declared(system.getMaxMem): let mem =
let usedMem = formatSize(getMaxMem()) & " peakmem" when declared(system.getMaxMem): formatSize(getMaxMem()) & " peakmem"
else: else: formatSize(getTotalMem()) & " totmem"
let usedMem = formatSize(getTotalMem()) let loc = $conf.linesCompiled
rawMessage(conf, hintSuccessX, [$conf.linesCompiled, let build = if isDefined(conf, "danger"): "Dangerous Release"
formatFloat(epochTime() - conf.lastCmdTime, ffDecimal, 3), elif isDefined(conf, "release"): "Release"
usedMem, else: "Debug"
if isDefined(conf, "danger"): "Dangerous Release Build" let sec = formatFloat(epochTime() - conf.lastCmdTime, ffDecimal, 3)
elif isDefined(conf, "release"): "Release Build" let project = if optListFullPaths in conf.globalOptions: $conf.projectFull else: $conf.projectName
else: "Debug Build"]) let output = if optListFullPaths in conf.globalOptions: $conf.getOutFileFull else: $conf.outFile
rawMessage(conf, hintSuccessX, [
"loc", loc,
"sec", sec,
"mem", mem,
"build", build,
"project", project,
"output", output,
])
when PrintRopeCacheStats: when PrintRopeCacheStats:
echo "rope cache stats: " echo "rope cache stats: "

View file

@ -284,6 +284,8 @@ type
severity: Severity) {.closure, gcsafe.} severity: Severity) {.closure, gcsafe.}
cppCustomNamespace*: string cppCustomNamespace*: string
proc getOutFileFull*(a: ConfigRef): AbsoluteFile = a.outDir / a.outFile
proc hcrOn*(conf: ConfigRef): bool = return optHotCodeReloading in conf.globalOptions proc hcrOn*(conf: ConfigRef): bool = return optHotCodeReloading in conf.globalOptions
template depConfigFields*(fn) {.dirty.} = template depConfigFields*(fn) {.dirty.} =

View file

@ -74,11 +74,14 @@ let
'template/generic instantiation' ( ' of `' [^`]+ '`' )? ' from here' .* 'template/generic instantiation' ( ' of `' [^`]+ '`' )? ' from here' .*
""" """
pegOtherError = peg"'Error:' \s* {.*}" pegOtherError = peg"'Error:' \s* {.*}"
pegSuccess = peg"'Hint: operation successful'.*"
pegOfInterest = pegLineError / pegOtherError pegOfInterest = pegLineError / pegOtherError
var gTargets = {low(TTarget)..high(TTarget)} var gTargets = {low(TTarget)..high(TTarget)}
proc isSuccess(input: string): bool =
# not clear how to do the equivalent of pkg/regex's: re"FOO(.*?)BAR" in pegs
input.startsWith("Hint: ") and input.endsWith("[SuccessX]")
proc normalizeMsg(s: string): string = proc normalizeMsg(s: string): string =
result = newStringOfCap(s.len+1) result = newStringOfCap(s.len+1)
for x in splitLines(s): for x in splitLines(s):
@ -157,7 +160,7 @@ proc callCompiler(cmdTemplate, filename, options, nimcache: string,
elif x =~ pegLineTemplate and err == "": elif x =~ pegLineTemplate and err == "":
# `tmpl` contains the last template expansion before the error # `tmpl` contains the last template expansion before the error
tmpl = x tmpl = x
elif x =~ pegSuccess: elif x.isSuccess:
suc = x suc = x
elif not running(p): elif not running(p):
break break
@ -170,6 +173,7 @@ proc callCompiler(cmdTemplate, filename, options, nimcache: string,
result.tfile = "" result.tfile = ""
result.tline = 0 result.tline = 0
result.tcolumn = 0 result.tcolumn = 0
result.err = reNimcCrash
if tmpl =~ pegLineTemplate: if tmpl =~ pegLineTemplate:
result.tfile = extractFilename(matches[0]) result.tfile = extractFilename(matches[0])
result.tline = parseInt(matches[1]) result.tline = parseInt(matches[1])
@ -181,7 +185,7 @@ proc callCompiler(cmdTemplate, filename, options, nimcache: string,
result.msg = matches[3] result.msg = matches[3]
elif err =~ pegOtherError: elif err =~ pegOtherError:
result.msg = matches[0] result.msg = matches[0]
elif suc =~ pegSuccess: elif suc.isSuccess:
result.err = reSuccess result.err = reSuccess
proc callCCompiler(cmdTemplate, filename, options: string, proc callCCompiler(cmdTemplate, filename, options: string,