--usenimcache (implied by nim r main) now caches some compile options to avoid recompiling when project was previously compiled with such options. (#17829)

* `--usenimcache` (implied by `nim r main`) now caches some compile options
to avoid recompiling when project was previously compiled with such options.

* works
* add test
* changelog
* use std/with
This commit is contained in:
Timothee Cour 2021-04-25 01:25:31 -07:00 • committed by GitHub
commit ffe4328b35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 91 additions and 52 deletions

View file

@ -29,13 +29,18 @@ const
nimcache = buildDir / "nimcacheTrunner"
# instead of `querySetting(nimcacheDir)`, avoids stomping on other parallel tests
proc runCmd(file, options = ""): auto =
proc runNimCmd(file, options = "", rtarg = ""): auto =
let fileabs = testsDir / file.unixToNativePath
doAssert fileabs.fileExists, fileabs
let cmd = fmt"{nim} {mode} {options} --hints:off {fileabs}"
let cmd = fmt"{nim} {mode} {options} --hints:off {fileabs} {rtarg}"
result = execCmdEx(cmd)
when false: echo result[0] & "\n" & result[1] # for debugging
proc runNimCmdChk(file, options = "", rtarg = ""): string =
let (ret, status) = runNimCmd(file, options, rtarg = rtarg)
doAssert status == 0, $(file, options) & "\n" & ret
ret
when defined(nimTrunnerFfi):
block: # mevalffi
when defined(openbsd):
@ -53,8 +58,8 @@ when defined(nimTrunnerFfi):
hello world stderr
hi stderr
"""
let (output, exitCode) = runCmd("vm/mevalffi.nim", fmt"{opt} --experimental:compiletimeFFI")
let expected = fmt"""
let output = runNimCmdChk("vm/mevalffi.nim", fmt"{opt} --experimental:compiletimeFFI")
doAssert output == fmt"""
{prefix}foo
foo:100
foo:101
@ -62,12 +67,10 @@ foo:102:103
foo:102:103:104
foo:0.03:asdf:103:105
ret=[s1:foobar s2:foobar age:25 pi:3.14]
"""
doAssert output == expected, output
doAssert exitCode == 0
""", output
else: # don't run twice the same test
import std/[strutils]
import std/strutils
template check2(msg) = doAssert msg in output, output
block: # tests with various options `nim doc --project --index --docroot`
@ -142,17 +145,16 @@ sub/mmain.idx""", context
else: doAssert false
block: # mstatic_assert
let (output, exitCode) = runCmd("ccgbugs/mstatic_assert.nim", "-d:caseBad")
let (output, exitCode) = runNimCmd("ccgbugs/mstatic_assert.nim", "-d:caseBad")
check2 "sizeof(bool) == 2"
check exitCode != 0
block: # ABI checks
let file = "misc/msizeof5.nim"
block:
let (output, exitCode) = runCmd(file, "-d:checkAbi")
doAssert exitCode == 0, output
discard runNimCmdChk(file, "-d:checkAbi")
block:
let (output, exitCode) = runCmd(file, "-d:checkAbi -d:caseBad")
let (output, exitCode) = runNimCmd(file, "-d:checkAbi -d:caseBad")
# on platforms that support _StaticAssert natively, errors will show full context, e.g.:
# error: static_assert failed due to requirement 'sizeof(unsigned char) == 8'
# "backend & Nim disagree on size for: BadImportcType{int64} [declared in mabi_check.nim(1, 6)]"
@ -293,3 +295,25 @@ tests/newconfig/bar/mfoo.nims""".splitLines
let (outp, exitCode) = run "echo 1+2; quit(2)"
check3 "3" in outp
doAssert exitCode == 2
block: # nimBetterRun
let file = "misc/mbetterrun.nim"
const nimcache2 = buildDir / "D20210423T185116"
removeDir nimcache2
# related to `-d:nimBetterRun`
let opt = fmt"-r --usenimcache --nimcache:{nimcache2}"
var ret = ""
for a in @["v1", "v2", "v1", "v3"]:
ret.add runNimCmdChk(file, fmt"{opt} -d:mbetterrunVal:{a}")
ret.add runNimCmdChk(file, fmt"{opt} -d:mbetterrunVal:v2", rtarg = "arg1 arg2")
# rt arguments should not cause a recompilation
doAssert ret == """
compiling: v1
running: v1
compiling: v2
running: v2
running: v1
compiling: v3
running: v3
running: v2
""", ret