diff options
author | Araq <rumpf_a@web.de> | 2018-12-14 09:56:59 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2018-12-14 09:56:59 +0100 |
commit | f551b72fba30cb70bddfebad9d1398031b5ef620 (patch) | |
tree | da0e96e4bc35a479f4dc3e4cf2c1e3123ede00b7 | |
parent | 359a4b5fac53af35b499dfa3e484b131af6b0d19 (diff) | |
download | Nim-f551b72fba30cb70bddfebad9d1398031b5ef620.tar.gz |
fixes #9965
-rw-r--r-- | compiler/cmdlinehelper.nim | 35 | ||||
-rw-r--r-- | compiler/options.nim | 74 |
2 files changed, 94 insertions, 15 deletions
diff --git a/compiler/cmdlinehelper.nim b/compiler/cmdlinehelper.nim index 9fbf4a0b0..7656a11f9 100644 --- a/compiler/cmdlinehelper.nim +++ b/compiler/cmdlinehelper.nim @@ -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") - - # bug #9120 - conf.globalOptions.excl(optTaintMode) - - proc runNimScriptIfExists(path: AbsoluteFile)= - if fileExists(path): - runNimScript(cache, path, freshDefines = false, conf) + 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) + + 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) diff --git a/compiler/options.nim b/compiler/options.nim index 80d665d62..52c7d88cd 100644 --- a/compiler/options.nim +++ b/compiler/options.nim @@ -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 |