fix #16731: using deprecated flags triggers a warning (#17225)

* using deprecated flags triggers a warning
* cleanups
* fixup
* address comments
This commit is contained in:
Timothee Cour 2021-03-02 04:07:05 -08:00 • committed by GitHub
commit a0daa7a76d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 24 deletions

View file

@ -234,15 +234,20 @@ const
errGuiConsoleOrLibExpectedButXFound = "'gui', 'console' or 'lib' expected, but '$1' found" errGuiConsoleOrLibExpectedButXFound = "'gui', 'console' or 'lib' expected, but '$1' found"
errInvalidExceptionSystem = "'goto', 'setjump', 'cpp' or 'quirky' expected, but '$1' found" errInvalidExceptionSystem = "'goto', 'setjump', 'cpp' or 'quirky' expected, but '$1' found"
template warningOptionNoop(switch: string) =
warningDeprecated(conf, info, "'$#' is deprecated, now a noop" % switch)
template deprecatedAlias(oldName, newName: string) =
warningDeprecated(conf, info, "'$#' is a deprecated alias for '$#'" % [oldName, newName])
proc testCompileOptionArg*(conf: ConfigRef; switch, arg: string, info: TLineInfo): bool = proc testCompileOptionArg*(conf: ConfigRef; switch, arg: string, info: TLineInfo): bool =
case switch.normalize case switch.normalize
of "gc": of "gc":
case arg.normalize case arg.normalize
of "boehm": result = conf.selectedGC == gcBoehm of "boehm": result = conf.selectedGC == gcBoehm
of "refc": result = conf.selectedGC == gcRefc of "refc": result = conf.selectedGC == gcRefc
of "v2": result = false
of "markandsweep": result = conf.selectedGC == gcMarkAndSweep of "markandsweep": result = conf.selectedGC == gcMarkAndSweep
of "generational": result = false of "v2", "generational": warningOptionNoop(arg)
of "destructors", "arc": result = conf.selectedGC == gcArc of "destructors", "arc": result = conf.selectedGC == gcArc
of "orc": result = conf.selectedGC == gcOrc of "orc": result = conf.selectedGC == gcOrc
of "hooks": result = conf.selectedGC == gcHooks of "hooks": result = conf.selectedGC == gcHooks
@ -298,7 +303,6 @@ proc testCompileOption*(conf: ConfigRef; switch: string, info: TLineInfo): bool
result = conf.options * {optNaNCheck, optInfCheck} == {optNaNCheck, optInfCheck} result = conf.options * {optNaNCheck, optInfCheck} == {optNaNCheck, optInfCheck}
of "infchecks": result = contains(conf.options, optInfCheck) of "infchecks": result = contains(conf.options, optInfCheck)
of "nanchecks": result = contains(conf.options, optNaNCheck) of "nanchecks": result = contains(conf.options, optNaNCheck)
of "nilchecks": result = false # not a thing
of "objchecks": result = contains(conf.options, optObjCheck) of "objchecks": result = contains(conf.options, optObjCheck)
of "fieldchecks": result = contains(conf.options, optFieldCheck) of "fieldchecks": result = contains(conf.options, optFieldCheck)
of "rangechecks": result = contains(conf.options, optRangeCheck) of "rangechecks": result = contains(conf.options, optRangeCheck)
@ -313,14 +317,13 @@ proc testCompileOption*(conf: ConfigRef; switch: string, info: TLineInfo): bool
of "symbolfiles": result = conf.symbolFiles != disabledSf of "symbolfiles": result = conf.symbolFiles != disabledSf
of "genscript": result = contains(conf.globalOptions, optGenScript) of "genscript": result = contains(conf.globalOptions, optGenScript)
of "threads": result = contains(conf.globalOptions, optThreads) of "threads": result = contains(conf.globalOptions, optThreads)
of "taintmode": result = false # pending https://github.com/nim-lang/Nim/issues/16731
of "tlsemulation": result = contains(conf.globalOptions, optTlsEmulation) of "tlsemulation": result = contains(conf.globalOptions, optTlsEmulation)
of "implicitstatic": result = contains(conf.options, optImplicitStatic) of "implicitstatic": result = contains(conf.options, optImplicitStatic)
of "patterns", "trmacros": result = contains(conf.options, optTrMacros) of "patterns", "trmacros":
if switch.normalize == "patterns": deprecatedAlias(switch, "trmacros")
result = contains(conf.options, optTrMacros)
of "excessivestacktrace": result = contains(conf.globalOptions, optExcessiveStackTrace) of "excessivestacktrace": result = contains(conf.globalOptions, optExcessiveStackTrace)
of "nilseqs": of "nilseqs", "nilchecks", "taintmode": warningOptionNoop(switch)
warningDeprecated(conf, info, "nilseqs is a deprecated noop")
result = false
else: invalidCmdLineOption(conf, passCmd1, switch, info) else: invalidCmdLineOption(conf, passCmd1, switch, info)
proc processPath(conf: ConfigRef; path: string, info: TLineInfo, proc processPath(conf: ConfigRef; path: string, info: TLineInfo,
@ -468,7 +471,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
addPath(conf, if pass == passPP: processCfgPath(conf, path, info) addPath(conf, if pass == passPP: processCfgPath(conf, path, info)
else: processPath(conf, path, info), info) else: processPath(conf, path, info), info)
of "nimblepath", "babelpath": of "nimblepath", "babelpath":
# keep the old name for compat if switch.normalize == "babelpath": deprecatedAlias(switch, "nimblepath")
if pass in {passCmd2, passPP} and optNoNimblePath notin conf.globalOptions: if pass in {passCmd2, passPP} and optNoNimblePath notin conf.globalOptions:
expectArg(conf, switch, arg, pass, info) expectArg(conf, switch, arg, pass, info)
var path = processPath(conf, arg, info, notRelativeToProj=true) var path = processPath(conf, arg, info, notRelativeToProj=true)
@ -477,6 +480,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
path = nimbleDir / RelativeDir"pkgs" path = nimbleDir / RelativeDir"pkgs"
nimblePath(conf, path, info) nimblePath(conf, path, info)
of "nonimblepath", "nobabelpath": of "nonimblepath", "nobabelpath":
if switch.normalize == "nobabelpath": deprecatedAlias(switch, "nonimblepath")
expectNoArg(conf, switch, arg, pass, info) expectNoArg(conf, switch, arg, pass, info)
disableNimblePath(conf) disableNimblePath(conf)
of "clearnimblepath": of "clearnimblepath":
@ -510,8 +514,6 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
if backend == TBackend.default: localError(conf, info, "invalid backend: '$1'" % arg) if backend == TBackend.default: localError(conf, info, "invalid backend: '$1'" % arg)
conf.backend = backend conf.backend = backend
of "doccmd": conf.docCmd = arg of "doccmd": conf.docCmd = arg
of "mainmodule", "m":
discard "allow for backwards compatibility, but don't do anything"
of "define", "d": of "define", "d":
expectArg(conf, switch, arg, pass, info) expectArg(conf, switch, arg, pass, info)
if {':', '='} in arg: if {':', '='} in arg:
@ -526,9 +528,6 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
of "undef", "u": of "undef", "u":
expectArg(conf, switch, arg, pass, info) expectArg(conf, switch, arg, pass, info)
undefSymbol(conf.symbols, arg) undefSymbol(conf.symbols, arg)
of "symbol":
expectArg(conf, switch, arg, pass, info)
# deprecated, do nothing
of "compile": of "compile":
expectArg(conf, switch, arg, pass, info) expectArg(conf, switch, arg, pass, info)
if pass in {passCmd2, passPP}: processCompile(conf, arg) if pass in {passCmd2, passPP}: processCompile(conf, arg)
@ -652,13 +651,11 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
else: else:
undefSymbol(conf.symbols, "hotcodereloading") undefSymbol(conf.symbols, "hotcodereloading")
undefSymbol(conf.symbols, "useNimRtl") undefSymbol(conf.symbols, "useNimRtl")
of "nilseqs": warningDeprecated(conf, info, "nilseqs is a deprecated noop")
of "checks", "x": processOnOffSwitch(conf, ChecksOptions, arg, pass, info) of "checks", "x": processOnOffSwitch(conf, ChecksOptions, arg, pass, info)
of "floatchecks": of "floatchecks":
processOnOffSwitch(conf, {optNaNCheck, optInfCheck}, arg, pass, info) processOnOffSwitch(conf, {optNaNCheck, optInfCheck}, arg, pass, info)
of "infchecks": processOnOffSwitch(conf, {optInfCheck}, arg, pass, info) of "infchecks": processOnOffSwitch(conf, {optInfCheck}, arg, pass, info)
of "nanchecks": processOnOffSwitch(conf, {optNaNCheck}, arg, pass, info) of "nanchecks": processOnOffSwitch(conf, {optNaNCheck}, arg, pass, info)
of "nilchecks": discard "no such thing anymore"
of "objchecks": processOnOffSwitch(conf, {optObjCheck}, arg, pass, info) of "objchecks": processOnOffSwitch(conf, {optObjCheck}, arg, pass, info)
of "fieldchecks": processOnOffSwitch(conf, {optFieldCheck}, arg, pass, info) of "fieldchecks": processOnOffSwitch(conf, {optFieldCheck}, arg, pass, info)
of "rangechecks": processOnOffSwitch(conf, {optRangeCheck}, arg, pass, info) of "rangechecks": processOnOffSwitch(conf, {optRangeCheck}, arg, pass, info)
@ -669,15 +666,14 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
of "stylechecks": processOnOffSwitch(conf, {optStyleCheck}, arg, pass, info) of "stylechecks": processOnOffSwitch(conf, {optStyleCheck}, arg, pass, info)
of "linedir": processOnOffSwitch(conf, {optLineDir}, arg, pass, info) of "linedir": processOnOffSwitch(conf, {optLineDir}, arg, pass, info)
of "assertions", "a": processOnOffSwitch(conf, {optAssert}, arg, pass, info) of "assertions", "a": processOnOffSwitch(conf, {optAssert}, arg, pass, info)
of "deadcodeelim": discard # deprecated, dead code elim always on
of "threads": of "threads":
processOnOffSwitchG(conf, {optThreads}, arg, pass, info) processOnOffSwitchG(conf, {optThreads}, arg, pass, info)
#if optThreads in conf.globalOptions: conf.setNote(warnGcUnsafe) #if optThreads in conf.globalOptions: conf.setNote(warnGcUnsafe)
of "tlsemulation": processOnOffSwitchG(conf, {optTlsEmulation}, arg, pass, info) of "tlsemulation": processOnOffSwitchG(conf, {optTlsEmulation}, arg, pass, info)
of "taintmode": discard # pending https://github.com/nim-lang/Nim/issues/16731
of "implicitstatic": of "implicitstatic":
processOnOffSwitch(conf, {optImplicitStatic}, arg, pass, info) processOnOffSwitch(conf, {optImplicitStatic}, arg, pass, info)
of "patterns", "trmacros": of "patterns", "trmacros":
if switch.normalize == "patterns": deprecatedAlias(switch, "trmacros")
processOnOffSwitch(conf, {optTrMacros}, arg, pass, info) processOnOffSwitch(conf, {optTrMacros}, arg, pass, info)
of "opt": of "opt":
expectArg(conf, switch, arg, pass, info) expectArg(conf, switch, arg, pass, info)
@ -805,6 +801,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
expectNoArg(conf, switch, arg, pass, info) expectNoArg(conf, switch, arg, pass, info)
helpOnError(conf, pass) helpOnError(conf, pass)
of "symbolfiles", "incremental", "ic": of "symbolfiles", "incremental", "ic":
if switch.normalize == "symbolfiles": deprecatedAlias(switch, "incremental")
# xxx maybe also ic, since not in help?
if pass in {passCmd2, passPP}: if pass in {passCmd2, passPP}:
case arg.normalize case arg.normalize
of "on": conf.symbolFiles = v2Sf of "on": conf.symbolFiles = v2Sf
@ -823,6 +821,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
of "skipparentcfg": of "skipparentcfg":
processOnOffSwitchG(conf, {optSkipParentConfigFiles}, arg, pass, info) processOnOffSwitchG(conf, {optSkipParentConfigFiles}, arg, pass, info)
of "genscript", "gendeps": of "genscript", "gendeps":
if switch.normalize == "gendeps": deprecatedAlias(switch, "genscript")
processOnOffSwitchG(conf, {optGenScript}, arg, pass, info) processOnOffSwitchG(conf, {optGenScript}, arg, pass, info)
processOnOffSwitchG(conf, {optCompileOnly}, arg, pass, info) processOnOffSwitchG(conf, {optCompileOnly}, arg, pass, info)
of "colors": processOnOffSwitchG(conf, {optUseColors}, arg, pass, info) of "colors": processOnOffSwitchG(conf, {optUseColors}, arg, pass, info)
@ -864,9 +863,6 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
dynlibOverride(conf, switch, arg, pass, info) dynlibOverride(conf, switch, arg, pass, info)
of "dynliboverrideall": of "dynliboverrideall":
processOnOffSwitchG(conf, {optDynlibOverrideAll}, arg, pass, info) processOnOffSwitchG(conf, {optDynlibOverrideAll}, arg, pass, info)
of "cs":
# only supported for compatibility. Does nothing.
expectArg(conf, switch, arg, pass, info)
of "experimental": of "experimental":
if arg.len == 0: if arg.len == 0:
conf.features.incl oldExperimentalFeatures conf.features.incl oldExperimentalFeatures
@ -968,13 +964,14 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
processOnOffSwitchG(conf, {optPanics}, arg, pass, info) processOnOffSwitchG(conf, {optPanics}, arg, pass, info)
if optPanics in conf.globalOptions: if optPanics in conf.globalOptions:
defineSymbol(conf.symbols, "nimPanics") defineSymbol(conf.symbols, "nimPanics")
of "sourcemap": of "sourcemap": # xxx document in --fullhelp
conf.globalOptions.incl optSourcemap conf.globalOptions.incl optSourcemap
conf.options.incl optLineDir conf.options.incl optLineDir
of "deepcopy": of "deepcopy":
processOnOffSwitchG(conf, {optEnableDeepCopy}, arg, pass, info) processOnOffSwitchG(conf, {optEnableDeepCopy}, arg, pass, info)
of "": # comes from "-" in for example: `nim c -r -` (gets stripped from -) of "": # comes from "-" in for example: `nim c -r -` (gets stripped from -)
handleStdinInput(conf) handleStdinInput(conf)
of "nilseqs", "nilchecks", "mainmodule", "m", "symbol", "taintmode", "cs", "deadcodeelim": warningOptionNoop(switch)
else: else:
if strutils.find(switch, '.') >= 0: options.setConfigVar(conf, switch, arg) if strutils.find(switch, '.') >= 0: options.setConfigVar(conf, switch, arg)
else: invalidCmdLineOption(conf, pass, switch, info) else: invalidCmdLineOption(conf, pass, switch, info)
@ -984,7 +981,6 @@ proc processCommand*(switch: string, pass: TCmdLinePass; config: ConfigRef) =
splitSwitch(config, switch, cmd, arg, pass, gCmdLineInfo) splitSwitch(config, switch, cmd, arg, pass, gCmdLineInfo)
processSwitch(cmd, arg, pass, gCmdLineInfo, config) processSwitch(cmd, arg, pass, gCmdLineInfo, config)
proc processSwitch*(pass: TCmdLinePass; p: OptParser; config: ConfigRef) = proc processSwitch*(pass: TCmdLinePass; p: OptParser; config: ConfigRef) =
# hint[X]:off is parsed as (p.key = "hint[X]", p.val = "off") # hint[X]:off is parsed as (p.key = "hint[X]", p.val = "off")
# we transform it to (key = hint, val = [X]:off) # we transform it to (key = hint, val = [X]:off)

View file

@ -61,8 +61,8 @@ Advanced options:
--noMain:on|off do not generate a main procedure --noMain:on|off do not generate a main procedure
--genScript:on|off generate a compile script (in the 'nimcache' --genScript:on|off generate a compile script (in the 'nimcache'
subdirectory named 'compile_$$project$$scriptext'), subdirectory named 'compile_$$project$$scriptext'),
and a '.deps' file containing the dependencies;
implies --compileOnly implies --compileOnly
--genDeps:on|off generate a '.deps' file containing the dependencies
--os:SYMBOL set the target operating system (cross-compilation) --os:SYMBOL set the target operating system (cross-compilation)
--cpu:SYMBOL set the target processor (cross-compilation) --cpu:SYMBOL set the target processor (cross-compilation)
--debuginfo:on|off enables debug information --debuginfo:on|off enables debug information