Skip to content

Commit 96bffad

Browse files
genotranceAraq
authored andcommitted
Fix #9405 - cfg and nims run in sync
1 parent 73f5f1e commit 96bffad

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed

compiler/cmdlinehelper.nim

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
## Helpers for binaries that use compiler passes, eg: nim, nimsuggest, nimfix
1111

1212
import
13-
options, idents, nimconf, scriptconfig, extccomp, commands, msgs,
13+
options, idents, nimconf, extccomp, commands, msgs,
1414
lineinfos, modulegraphs, condsyms, os, pathutils
1515

1616
from strutils import normalize
@@ -43,45 +43,20 @@ proc processCmdLineAndProjectPath*(self: NimProg, conf: ConfigRef) =
4343
conf.projectPath = AbsoluteDir canonicalizePath(conf, AbsoluteFile getCurrentDir())
4444

4545
proc loadConfigsAndRunMainCommand*(self: NimProg, cache: IdentCache; conf: ConfigRef): bool =
46-
loadConfigs(DefaultConfig, cache, conf) # load all config files
4746
if self.suggestMode:
4847
conf.command = "nimsuggest"
48+
loadConfigs(DefaultConfig, cache, conf) # load all config files
4949

50-
template runNimScriptIfExists(path: AbsoluteFile) =
51-
let p = path # eval once
52-
if fileExists(p):
53-
runNimScript(cache, p, freshDefines = false, conf)
54-
55-
# Caution: make sure this stays in sync with `loadConfigs`
56-
if optSkipSystemConfigFile notin conf.globalOptions:
57-
runNimScriptIfExists(getSystemConfigPath(conf, DefaultConfigNims))
58-
59-
if optSkipUserConfigFile notin conf.globalOptions:
60-
runNimScriptIfExists(getUserConfigPath(DefaultConfigNims))
61-
62-
if optSkipParentConfigFiles notin conf.globalOptions:
63-
for dir in parentDirs(conf.projectPath.string, fromRoot = true, inclusive = false):
64-
runNimScriptIfExists(AbsoluteDir(dir) / DefaultConfigNims)
65-
66-
if optSkipProjConfigFile notin conf.globalOptions:
67-
runNimScriptIfExists(conf.projectPath / DefaultConfigNims)
6850
block:
6951
let scriptFile = conf.projectFull.changeFileExt("nims")
7052
if not self.suggestMode:
71-
runNimScriptIfExists(scriptFile)
7253
# 'nim foo.nims' means to just run the NimScript file and do nothing more:
7354
if fileExists(scriptFile) and scriptFile == conf.projectFull:
7455
if conf.command == "":
7556
conf.command = "e"
7657
return false
7758
elif conf.command.normalize == "e":
7859
return false
79-
else:
80-
if scriptFile != conf.projectFull:
81-
runNimScriptIfExists(scriptFile)
82-
else:
83-
# 'nimsuggest foo.nims' means to just auto-complete the NimScript file
84-
discard
8560

8661
# now process command line arguments again, because some options in the
8762
# command line can overwrite the config file's settings

compiler/nimconf.nim

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import
1313
llstream, commands, os, strutils, msgs, lexer,
14-
options, idents, wordrecg, strtabs, lineinfos, pathutils
14+
options, idents, wordrecg, strtabs, lineinfos, pathutils, scriptconfig
1515

1616
# ---------------- configuration file parser -----------------------------
1717
# we use Nim's scanner here to save space and work
@@ -248,17 +248,31 @@ proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef) =
248248
if readConfigFile(configPath, cache, conf):
249249
configFiles.add(configPath)
250250

251+
template runNimScriptIfExists(path: AbsoluteFile) =
252+
let p = path # eval once
253+
if fileExists(p):
254+
runNimScript(cache, p, freshDefines = false, conf)
255+
251256
if optSkipSystemConfigFile notin conf.globalOptions:
252257
readConfigFile(getSystemConfigPath(conf, cfg))
253258

259+
if cfg == DefaultConfig:
260+
runNimScriptIfExists(getSystemConfigPath(conf, DefaultConfigNims))
261+
254262
if optSkipUserConfigFile notin conf.globalOptions:
255263
readConfigFile(getUserConfigPath(cfg))
256264

265+
if cfg == DefaultConfig:
266+
runNimScriptIfExists(getUserConfigPath(DefaultConfigNims))
267+
257268
let pd = if not conf.projectPath.isEmpty: conf.projectPath else: AbsoluteDir(getCurrentDir())
258269
if optSkipParentConfigFiles notin conf.globalOptions:
259270
for dir in parentDirs(pd.string, fromRoot=true, inclusive=false):
260271
readConfigFile(AbsoluteDir(dir) / cfg)
261272

273+
if cfg == DefaultConfig:
274+
runNimScriptIfExists(AbsoluteDir(dir) / DefaultConfigNims)
275+
262276
if optSkipProjConfigFile notin conf.globalOptions:
263277
readConfigFile(pd / cfg)
264278

@@ -269,6 +283,20 @@ proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef) =
269283
projectConfig = changeFileExt(conf.projectFull, "nim.cfg")
270284
readConfigFile(projectConfig)
271285

286+
if cfg == DefaultConfig:
287+
runNimScriptIfExists(pd / DefaultConfigNims)
288+
272289
for filename in configFiles:
273290
# delayed to here so that `hintConf` is honored
274291
rawMessage(conf, hintConf, filename.string)
292+
293+
block:
294+
let scriptFile = conf.projectFull.changeFileExt("nims")
295+
if conf.command != "nimsuggest":
296+
runNimScriptIfExists(scriptFile)
297+
else:
298+
if scriptFile != conf.projectFull:
299+
runNimScriptIfExists(scriptFile)
300+
else:
301+
# 'nimsuggest foo.nims' means to just auto-complete the NimScript file
302+
discard

0 commit comments

Comments
 (0)