config system: special case -d:release and -d:danger [backport:1.4] (#18051)

(cherry picked from commit df429fa287)
This commit is contained in:
Andreas Rumpf
2021-05-20 11:52:46 +02:00
committed by narimiran
parent 94f80f5bcb
commit 8001c7be98
5 changed files with 28 additions and 6 deletions

View File

@@ -2,6 +2,13 @@
## Changes affecting backward compatibility
- The configuration subsystem now allows for `-d:release` and `-d:danger` to work as expected.
The downside is that these defines now have custom logic that doesn't apply for
other defines.
## Standard library additions and changes
- Added support for parenthesized expressions in `strformat`

View File

@@ -391,6 +391,19 @@ proc handleStdinInput*(conf: ConfigRef) =
if conf.outDir.isEmpty:
conf.outDir = getNimcacheDir(conf)
proc specialDefine(conf: ConfigRef, key: string) =
# Keep this syncronized with the default config/nim.cfg!
if cmpIgnoreStyle(key, "nimQuirky") == 0:
conf.exc = excQuirky
elif cmpIgnoreStyle(key, "release") == 0 or cmpIgnoreStyle(key, "danger") == 0:
conf.options.excl {optStackTrace, optLineTrace, optLineDir, optOptimizeSize}
conf.globalOptions.excl {optExcessiveStackTrace, optCDebug}
conf.options.incl optOptimizeSpeed
if cmpIgnoreStyle(key, "danger") == 0 or cmpIgnoreStyle(key, "quick") == 0:
conf.options.excl {optObjCheck, optFieldCheck, optRangeCheck, optBoundsCheck,
optOverflowCheck, optAssert, optStackTrace, optLineTrace, optLineDir}
conf.globalOptions.excl {optCDebug}
proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
conf: ConfigRef) =
var
@@ -450,12 +463,10 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
expectArg(conf, switch, arg, pass, info)
if {':', '='} in arg:
splitSwitch(conf, arg, key, val, pass, info)
if cmpIgnoreStyle(key, "nimQuirky") == 0:
conf.exc = excQuirky
specialDefine(conf, key)
defineSymbol(conf.symbols, key, val)
else:
if cmpIgnoreStyle(arg, "nimQuirky") == 0:
conf.exc = excQuirky
specialDefine(conf, arg)
defineSymbol(conf.symbols, arg)
of "undef", "u":
expectArg(conf, switch, arg, pass, info)

View File

@@ -52,6 +52,7 @@ path="$lib/pure"
nimblepath="$home/.nimble/pkgs/"
@end
# Syncronize with compiler/commands.specialDefine
@if danger or quick:
obj_checks:off
field_checks:off
@@ -69,6 +70,7 @@ path="$lib/pure"
@end
@end
# Syncronize with compiler/commands.specialDefine
@if release or danger:
stacktrace:off
excessiveStackTrace:off

View File

@@ -1,6 +1,6 @@
discard """
cmd: "nim default --hint:cc:off --hint:cc $file"
output: '''hello world! 0.5'''
output: '''hello world! 0.5 true'''
nimout: '''[NimScript] exec: gcc -v'''
"""
@@ -10,4 +10,4 @@ when not defined(definedefine):
import math, mfriends
discard gen[int]()
echo "hello world! ", ln 2.0
echo "hello world! ", ln 2.0, " ", compileOption("opt", "speed")

View File

@@ -3,6 +3,8 @@ mode = ScriptMode.Whatif
exec "gcc -v"
--define:release
--forceBuild
--path: "../friends"