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

View file

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

View file

@ -253,6 +253,80 @@ template depConfigFields*(fn) {.dirty.} =
fn(globalOptions) fn(globalOptions)
fn(selectedGC) 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 oldExperimentalFeatures* = {implicitDeref, dotOperators, callOperator, parallel}
const const