Skip to content

Commit 15043d3

Browse files
timotheecourAraq
authored andcommitted
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
1 parent 871d5e7 commit 15043d3

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

compiler/lineinfos.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ const
9797
warnCycleCreated: "$1",
9898
warnUser: "$1",
9999
hintSuccess: "operation successful: $#",
100-
hintSuccessX: "operation successful ($# lines compiled; $# sec total; $#; $#)",
100+
# keep in sync with `pegSuccess` see testament.nim
101+
hintSuccessX: "$loc LOC; $sec sec; $mem; $build build; $project proj; $output out",
101102
hintCC: "CC: \'$1\'", # unused
102103
hintLineTooLong: "line too long",
103104
hintXDeclaredButNotUsed: "'$1' is declared but not used",

compiler/main.nim

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,16 +355,24 @@ proc mainCommand*(graph: ModuleGraph) =
355355

356356
if conf.errorCounter == 0 and
357357
conf.cmd notin {cmdInterpret, cmdRun, cmdDump}:
358-
when declared(system.getMaxMem):
359-
let usedMem = formatSize(getMaxMem()) & " peakmem"
360-
else:
361-
let usedMem = formatSize(getTotalMem())
362-
rawMessage(conf, hintSuccessX, [$conf.linesCompiled,
363-
formatFloat(epochTime() - conf.lastCmdTime, ffDecimal, 3),
364-
usedMem,
365-
if isDefined(conf, "danger"): "Dangerous Release Build"
366-
elif isDefined(conf, "release"): "Release Build"
367-
else: "Debug Build"])
358+
let mem =
359+
when declared(system.getMaxMem): formatSize(getMaxMem()) & " peakmem"
360+
else: formatSize(getTotalMem()) & " totmem"
361+
let loc = $conf.linesCompiled
362+
let build = if isDefined(conf, "danger"): "Dangerous Release"
363+
elif isDefined(conf, "release"): "Release"
364+
else: "Debug"
365+
let sec = formatFloat(epochTime() - conf.lastCmdTime, ffDecimal, 3)
366+
let project = if optListFullPaths in conf.globalOptions: $conf.projectFull else: $conf.projectName
367+
let output = if optListFullPaths in conf.globalOptions: $conf.getOutFileFull else: $conf.outFile
368+
rawMessage(conf, hintSuccessX, [
369+
"loc", loc,
370+
"sec", sec,
371+
"mem", mem,
372+
"build", build,
373+
"project", project,
374+
"output", output,
375+
])
368376

369377
when PrintRopeCacheStats:
370378
echo "rope cache stats: "

compiler/options.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,8 @@ type
284284
severity: Severity) {.closure, gcsafe.}
285285
cppCustomNamespace*: string
286286

287+
proc getOutFileFull*(a: ConfigRef): AbsoluteFile = a.outDir / a.outFile
288+
287289
proc hcrOn*(conf: ConfigRef): bool = return optHotCodeReloading in conf.globalOptions
288290

289291
template depConfigFields*(fn) {.dirty.} =

testament/testament.nim

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,14 @@ let
7474
'template/generic instantiation' ( ' of `' [^`]+ '`' )? ' from here' .*
7575
"""
7676
pegOtherError = peg"'Error:' \s* {.*}"
77-
pegSuccess = peg"'Hint: operation successful'.*"
7877
pegOfInterest = pegLineError / pegOtherError
7978

8079
var gTargets = {low(TTarget)..high(TTarget)}
8180

81+
proc isSuccess(input: string): bool =
82+
# not clear how to do the equivalent of pkg/regex's: re"FOO(.*?)BAR" in pegs
83+
input.startsWith("Hint: ") and input.endsWith("[SuccessX]")
84+
8285
proc normalizeMsg(s: string): string =
8386
result = newStringOfCap(s.len+1)
8487
for x in splitLines(s):
@@ -157,7 +160,7 @@ proc callCompiler(cmdTemplate, filename, options, nimcache: string,
157160
elif x =~ pegLineTemplate and err == "":
158161
# `tmpl` contains the last template expansion before the error
159162
tmpl = x
160-
elif x =~ pegSuccess:
163+
elif x.isSuccess:
161164
suc = x
162165
elif not running(p):
163166
break
@@ -170,6 +173,7 @@ proc callCompiler(cmdTemplate, filename, options, nimcache: string,
170173
result.tfile = ""
171174
result.tline = 0
172175
result.tcolumn = 0
176+
result.err = reNimcCrash
173177
if tmpl =~ pegLineTemplate:
174178
result.tfile = extractFilename(matches[0])
175179
result.tline = parseInt(matches[1])
@@ -181,7 +185,7 @@ proc callCompiler(cmdTemplate, filename, options, nimcache: string,
181185
result.msg = matches[3]
182186
elif err =~ pegOtherError:
183187
result.msg = matches[0]
184-
elif suc =~ pegSuccess:
188+
elif suc.isSuccess:
185189
result.err = reSuccess
186190

187191
proc callCCompiler(cmdTemplate, filename, options: string,

0 commit comments

Comments
 (0)