Fix #9405 - cfg and nims run in sync
This commit is contained in:
parent
73f5f1e80c
commit
96bffadf60
2 changed files with 31 additions and 28 deletions
|
|
@ -10,7 +10,7 @@
|
||||||
## Helpers for binaries that use compiler passes, eg: nim, nimsuggest, nimfix
|
## Helpers for binaries that use compiler passes, eg: nim, nimsuggest, nimfix
|
||||||
|
|
||||||
import
|
import
|
||||||
options, idents, nimconf, scriptconfig, extccomp, commands, msgs,
|
options, idents, nimconf, extccomp, commands, msgs,
|
||||||
lineinfos, modulegraphs, condsyms, os, pathutils
|
lineinfos, modulegraphs, condsyms, os, pathutils
|
||||||
|
|
||||||
from strutils import normalize
|
from strutils import normalize
|
||||||
|
|
@ -43,32 +43,13 @@ proc processCmdLineAndProjectPath*(self: NimProg, conf: ConfigRef) =
|
||||||
conf.projectPath = AbsoluteDir canonicalizePath(conf, AbsoluteFile getCurrentDir())
|
conf.projectPath = AbsoluteDir canonicalizePath(conf, AbsoluteFile getCurrentDir())
|
||||||
|
|
||||||
proc loadConfigsAndRunMainCommand*(self: NimProg, cache: IdentCache; conf: ConfigRef): bool =
|
proc loadConfigsAndRunMainCommand*(self: NimProg, cache: IdentCache; conf: ConfigRef): bool =
|
||||||
loadConfigs(DefaultConfig, cache, conf) # load all config files
|
|
||||||
if self.suggestMode:
|
if self.suggestMode:
|
||||||
conf.command = "nimsuggest"
|
conf.command = "nimsuggest"
|
||||||
|
loadConfigs(DefaultConfig, cache, conf) # load all config files
|
||||||
|
|
||||||
template runNimScriptIfExists(path: AbsoluteFile) =
|
|
||||||
let p = path # eval once
|
|
||||||
if fileExists(p):
|
|
||||||
runNimScript(cache, p, freshDefines = false, conf)
|
|
||||||
|
|
||||||
# Caution: make sure this stays in sync with `loadConfigs`
|
|
||||||
if optSkipSystemConfigFile notin conf.globalOptions:
|
|
||||||
runNimScriptIfExists(getSystemConfigPath(conf, DefaultConfigNims))
|
|
||||||
|
|
||||||
if optSkipUserConfigFile notin conf.globalOptions:
|
|
||||||
runNimScriptIfExists(getUserConfigPath(DefaultConfigNims))
|
|
||||||
|
|
||||||
if optSkipParentConfigFiles notin conf.globalOptions:
|
|
||||||
for dir in parentDirs(conf.projectPath.string, fromRoot = true, inclusive = false):
|
|
||||||
runNimScriptIfExists(AbsoluteDir(dir) / DefaultConfigNims)
|
|
||||||
|
|
||||||
if optSkipProjConfigFile notin conf.globalOptions:
|
|
||||||
runNimScriptIfExists(conf.projectPath / DefaultConfigNims)
|
|
||||||
block:
|
block:
|
||||||
let scriptFile = conf.projectFull.changeFileExt("nims")
|
let scriptFile = conf.projectFull.changeFileExt("nims")
|
||||||
if not self.suggestMode:
|
if not self.suggestMode:
|
||||||
runNimScriptIfExists(scriptFile)
|
|
||||||
# 'nim foo.nims' means to just run the NimScript file and do nothing more:
|
# 'nim foo.nims' means to just run the NimScript file and do nothing more:
|
||||||
if fileExists(scriptFile) and scriptFile == conf.projectFull:
|
if fileExists(scriptFile) and scriptFile == conf.projectFull:
|
||||||
if conf.command == "":
|
if conf.command == "":
|
||||||
|
|
@ -76,12 +57,6 @@ proc loadConfigsAndRunMainCommand*(self: NimProg, cache: IdentCache; conf: Confi
|
||||||
return false
|
return false
|
||||||
elif conf.command.normalize == "e":
|
elif conf.command.normalize == "e":
|
||||||
return false
|
return false
|
||||||
else:
|
|
||||||
if scriptFile != conf.projectFull:
|
|
||||||
runNimScriptIfExists(scriptFile)
|
|
||||||
else:
|
|
||||||
# 'nimsuggest foo.nims' means to just auto-complete the NimScript file
|
|
||||||
discard
|
|
||||||
|
|
||||||
# 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 overwrite the config file's settings
|
# command line can overwrite the config file's settings
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
llstream, commands, os, strutils, msgs, lexer,
|
llstream, commands, os, strutils, msgs, lexer,
|
||||||
options, idents, wordrecg, strtabs, lineinfos, pathutils
|
options, idents, wordrecg, strtabs, lineinfos, pathutils, scriptconfig
|
||||||
|
|
||||||
# ---------------- configuration file parser -----------------------------
|
# ---------------- configuration file parser -----------------------------
|
||||||
# we use Nim's scanner here to save space and work
|
# 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):
|
if readConfigFile(configPath, cache, conf):
|
||||||
configFiles.add(configPath)
|
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:
|
if optSkipSystemConfigFile notin conf.globalOptions:
|
||||||
readConfigFile(getSystemConfigPath(conf, cfg))
|
readConfigFile(getSystemConfigPath(conf, cfg))
|
||||||
|
|
||||||
|
if cfg == DefaultConfig:
|
||||||
|
runNimScriptIfExists(getSystemConfigPath(conf, DefaultConfigNims))
|
||||||
|
|
||||||
if optSkipUserConfigFile notin conf.globalOptions:
|
if optSkipUserConfigFile notin conf.globalOptions:
|
||||||
readConfigFile(getUserConfigPath(cfg))
|
readConfigFile(getUserConfigPath(cfg))
|
||||||
|
|
||||||
|
if cfg == DefaultConfig:
|
||||||
|
runNimScriptIfExists(getUserConfigPath(DefaultConfigNims))
|
||||||
|
|
||||||
let pd = if not conf.projectPath.isEmpty: conf.projectPath else: AbsoluteDir(getCurrentDir())
|
let pd = if not conf.projectPath.isEmpty: conf.projectPath else: AbsoluteDir(getCurrentDir())
|
||||||
if optSkipParentConfigFiles notin conf.globalOptions:
|
if optSkipParentConfigFiles notin conf.globalOptions:
|
||||||
for dir in parentDirs(pd.string, fromRoot=true, inclusive=false):
|
for dir in parentDirs(pd.string, fromRoot=true, inclusive=false):
|
||||||
readConfigFile(AbsoluteDir(dir) / cfg)
|
readConfigFile(AbsoluteDir(dir) / cfg)
|
||||||
|
|
||||||
|
if cfg == DefaultConfig:
|
||||||
|
runNimScriptIfExists(AbsoluteDir(dir) / DefaultConfigNims)
|
||||||
|
|
||||||
if optSkipProjConfigFile notin conf.globalOptions:
|
if optSkipProjConfigFile notin conf.globalOptions:
|
||||||
readConfigFile(pd / cfg)
|
readConfigFile(pd / cfg)
|
||||||
|
|
||||||
|
|
@ -269,6 +283,20 @@ proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef) =
|
||||||
projectConfig = changeFileExt(conf.projectFull, "nim.cfg")
|
projectConfig = changeFileExt(conf.projectFull, "nim.cfg")
|
||||||
readConfigFile(projectConfig)
|
readConfigFile(projectConfig)
|
||||||
|
|
||||||
|
if cfg == DefaultConfig:
|
||||||
|
runNimScriptIfExists(pd / DefaultConfigNims)
|
||||||
|
|
||||||
for filename in configFiles:
|
for filename in configFiles:
|
||||||
# delayed to here so that `hintConf` is honored
|
# delayed to here so that `hintConf` is honored
|
||||||
rawMessage(conf, hintConf, filename.string)
|
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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue