diff options
Diffstat (limited to 'compiler/nimconf.nim')
-rw-r--r-- | compiler/nimconf.nim | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim index 93cc21573..df1ceb610 100644 --- a/compiler/nimconf.nim +++ b/compiler/nimconf.nim @@ -11,7 +11,7 @@ import llstream, commands, os, strutils, msgs, lexer, - options, idents, wordrecg, strtabs, lineinfos, pathutils + options, idents, wordrecg, strtabs, lineinfos, pathutils, scriptconfig # ---------------- configuration file parser ----------------------------- # we use Nim's scanner here to save space and work @@ -248,17 +248,31 @@ proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef) = if readConfigFile(configPath, cache, conf): configFiles.add(configPath) + template runNimScriptIfExists(path: AbsoluteFile) = + let p = path # eval once + if fileExists(p): + runNimScript(cache, p, freshDefines = false, conf) + if optSkipSystemConfigFile notin conf.globalOptions: readConfigFile(getSystemConfigPath(conf, cfg)) + if cfg == DefaultConfig: + runNimScriptIfExists(getSystemConfigPath(conf, DefaultConfigNims)) + if optSkipUserConfigFile notin conf.globalOptions: readConfigFile(getUserConfigPath(cfg)) + if cfg == DefaultConfig: + runNimScriptIfExists(getUserConfigPath(DefaultConfigNims)) + let pd = if not conf.projectPath.isEmpty: conf.projectPath else: AbsoluteDir(getCurrentDir()) if optSkipParentConfigFiles notin conf.globalOptions: for dir in parentDirs(pd.string, fromRoot=true, inclusive=false): readConfigFile(AbsoluteDir(dir) / cfg) + if cfg == DefaultConfig: + runNimScriptIfExists(AbsoluteDir(dir) / DefaultConfigNims) + if optSkipProjConfigFile notin conf.globalOptions: readConfigFile(pd / cfg) @@ -269,6 +283,20 @@ proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef) = projectConfig = changeFileExt(conf.projectFull, "nim.cfg") readConfigFile(projectConfig) + if cfg == DefaultConfig: + runNimScriptIfExists(pd / DefaultConfigNims) + for filename in configFiles: # delayed to here so that `hintConf` is honored rawMessage(conf, hintConf, filename.string) + + block: + let scriptFile = conf.projectFull.changeFileExt("nims") + if conf.command != "nimsuggest": + runNimScriptIfExists(scriptFile) + else: + if scriptFile != conf.projectFull: + runNimScriptIfExists(scriptFile) + else: + # 'nimsuggest foo.nims' means to just auto-complete the NimScript file + discard |