This commit is contained in:
Araq
2018-12-14 09:56:59 +01:00
parent 359a4b5fac
commit f551b72fba
2 changed files with 92 additions and 13 deletions

View File

@@ -48,18 +48,26 @@ proc loadConfigsAndRunMainCommand*(self: NimProg, cache: IdentCache; conf: Confi
if self.suggestMode:
conf.command = "nimsuggest"
# These defines/options should not be enabled while processing nimscript
# bug #4446, #9420, #8991, #9589, #9153
undefSymbol(conf.symbols, "profiler")
undefSymbol(conf.symbols, "memProfiler")
undefSymbol(conf.symbols, "nodejs")
when false:
# These defines/options should not be enabled while processing nimscript
# bug #4446, #9420, #8991, #9589, #9153
undefSymbol(conf.symbols, "profiler")
undefSymbol(conf.symbols, "memProfiler")
undefSymbol(conf.symbols, "nodejs")
# bug #9120
conf.globalOptions.excl(optTaintMode)
# bug #9120
conf.globalOptions.excl(optTaintMode)
proc runNimScriptIfExists(path: AbsoluteFile)=
if fileExists(path):
runNimScript(cache, path, freshDefines = false, conf)
template runNimScriptIfExists(path: AbsoluteFile) =
let p = path # eval once
if fileExists(p):
var tempConf = newConfigRef()
setDefaultLibpath(tempConf)
initDefines(tempConf.symbols)
tempConf.command = conf.command
tempConf.commandArgs = conf.commandArgs
runNimScript(cache, p, freshDefines = false, tempConf)
mergeConfigs(conf, tempConf)
# Caution: make sure this stays in sync with `loadConfigs`
if optSkipSystemConfigFile notin conf.globalOptions:
@@ -88,9 +96,6 @@ proc loadConfigsAndRunMainCommand*(self: NimProg, cache: IdentCache; conf: Confi
# 'nimsuggest foo.nims' means to just auto-complete the NimScript file
discard
# Reload configuration from .cfg file
loadConfigs(DefaultConfig, cache, conf)
# now process command line arguments again, because some options in the
# command line can overwite the config file's settings
extccomp.initVars(conf)

View File

@@ -253,6 +253,80 @@ template depConfigFields*(fn) {.dirty.} =
fn(globalOptions)
fn(selectedGC)
proc mergeConfigs*(dest, src: ConfigRef) =
template merge[T: enum](a, b: T) =
a = b
template merge[T](a, b: set[T]) =
a = a + b
template merge(a, b: int) =
inc a, b
template merge[T](a, b: seq[T]) =
for bb in b: a.add b
template merge(a, b: string) =
a = b
template merge[T: AbsoluteFile|AbsoluteDir](a, b: T) =
if a.isEmpty and not b.isEmpty: a = b
template merge[T](a, b: HashSet[T]) =
for bb in b: a.incl b
template merge(a, b: StringTableRef) =
for k, v in b: a[k] = v
template merge[T: object](a, b: T) =
a = b
template m(field) =
merge(dest.field, src.field)
m target
m options
m globalOptions
m cmd
m selectedGC
m verbosity
m numberOfProcessors
m evalExpr
m symbolFiles
m cppDefines
m headerFile
m features
m arguments
m ideCmd
m cCompiler
m enableNotes
m disableNotes
m foreignPackageNotes
m notes
m errorCounter
m hintCounter
m warnCounter
m errorMax
m configVars
m symbols
m searchPaths
m lazyPaths
m outFile
m prefixDir
m libpath
m nimcacheDir
m dllOverrides
m moduleOverrides
m command
m commandArgs
m implicitImports
m implicitIncludes
m docSeeSrcUrl
m cIncludes
m cLibs
m cLinkedLibs
m externalToLink
m linkOptionsCmd
m compileOptionsCmd
m linkOptions
m compileOptions
m ccompilerpath
m toCompile
m cppCustomNamespace
const oldExperimentalFeatures* = {implicitDeref, dotOperators, callOperator, parallel}
const