Skip to content

Commit a96ada7

Browse files
committed
init
1 parent 79ddb7d commit a96ada7

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

compiler/commands.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,10 @@ proc pathRelativeToConfig(arg: string, pass: TCmdLinePass, conf: ConfigRef): str
631631

632632
proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
633633
conf: ConfigRef) =
634+
if conf.skipParentDetectionMode:
635+
if switch.normalize == "skipparentcfg":
636+
processOnOffSwitchG(conf, {optSkipParentConfigFiles}, arg, pass, info)
637+
return
634638
var key = ""
635639
var val = ""
636640
case switch.normalize

compiler/nimconf.nim

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,28 +128,32 @@ proc parseDirective(L: var Lexer, tok: var Token; config: ConfigRef; condStack:
128128
of wEnd: doEnd(L, tok, condStack)
129129
of wWrite:
130130
ppGetTok(L, tok)
131-
msgs.msgWriteln(config, strtabs.`%`($tok, config.configVars,
132-
{useEnvironment, useKey}))
131+
if not config.skipParentDetectionMode:
132+
msgs.msgWriteln(config, strtabs.`%`($tok, config.configVars,
133+
{useEnvironment, useKey}))
133134
ppGetTok(L, tok)
134135
else:
135136
case tok.ident.s.normalize
136137
of "putenv":
137138
ppGetTok(L, tok)
138139
var key = $tok
139140
ppGetTok(L, tok)
140-
os.putEnv(key, $tok)
141+
if not config.skipParentDetectionMode:
142+
os.putEnv(key, $tok)
141143
ppGetTok(L, tok)
142144
of "prependenv":
143145
ppGetTok(L, tok)
144146
var key = $tok
145147
ppGetTok(L, tok)
146-
os.putEnv(key, $tok & os.getEnv(key))
148+
if not config.skipParentDetectionMode:
149+
os.putEnv(key, $tok & os.getEnv(key))
147150
ppGetTok(L, tok)
148151
of "appendenv":
149152
ppGetTok(L, tok)
150153
var key = $tok
151154
ppGetTok(L, tok)
152-
os.putEnv(key, os.getEnv(key) & $tok)
155+
if not config.skipParentDetectionMode:
156+
os.putEnv(key, os.getEnv(key) & $tok)
153157
ppGetTok(L, tok)
154158
else:
155159
lexMessage(L, errGenerated, "invalid directive: '$1'" % $tok)
@@ -244,6 +248,21 @@ proc getSystemConfigPath*(conf: ConfigRef; filename: RelativeFile): AbsoluteFile
244248
if not fileExists(result): result = p / RelativeDir"etc/nim" / filename
245249
if not fileExists(result): result = AbsoluteDir"/etc/nim" / filename
246250

251+
proc configEnablesSkipParent(conf: ConfigRef; cache: IdentCache;
252+
cfgPath: AbsoluteFile): bool =
253+
let prevMode = conf.skipParentDetectionMode
254+
let prevSkip = optSkipParentConfigFiles in conf.globalOptions
255+
conf.skipParentDetectionMode = true
256+
try:
257+
result = readConfigFile(cfgPath, cache, conf) and
258+
optSkipParentConfigFiles in conf.globalOptions
259+
finally:
260+
conf.skipParentDetectionMode = prevMode
261+
if prevSkip:
262+
incl(conf.globalOptions, optSkipParentConfigFiles)
263+
else:
264+
excl(conf.globalOptions, optSkipParentConfigFiles)
265+
247266
proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef; idgen: IdGenerator) =
248267
setDefaultLibpath(conf)
249268
template readConfigFile(path) =
@@ -277,12 +296,24 @@ proc loadConfigs*(cfg: RelativeFile; cache: IdentCache; conf: ConfigRef; idgen:
277296
runNimScriptIfExists(getUserConfigPath(DefaultConfigNims))
278297

279298
let pd = if not conf.projectPath.isEmpty: conf.projectPath else: AbsoluteDir(getCurrentDir())
280-
if optSkipParentConfigFiles notin conf.globalOptions:
281-
for dir in parentDirs(pd.string, fromRoot=true, inclusive=false):
282-
readConfigFile(AbsoluteDir(dir) / cfg)
299+
if optSkipParentConfigFiles notin conf.globalOptions and not configEnablesSkipParent(conf, cache, pd / cfg):
300+
var parentDirsSeq: seq[AbsoluteDir] = @[]
301+
for dir in parentDirs(pd.string, inclusive=false):
302+
let
303+
adir = AbsoluteDir(dir)
304+
cfgPath = adir / cfg
305+
if not fileExists(cfgPath):
306+
continue
307+
parentDirsSeq.add adir
308+
if configEnablesSkipParent(conf, cache, cfgPath):
309+
break
310+
311+
for i in countdown(parentDirsSeq.len - 1, 0):
312+
let parentDir = parentDirsSeq[i]
313+
readConfigFile(parentDir / cfg)
283314

284315
if cfg == DefaultConfig:
285-
runNimScriptIfExists(AbsoluteDir(dir) / DefaultConfigNims)
316+
runNimScriptIfExists(parentDir / DefaultConfigNims)
286317

287318
if optSkipProjConfigFile notin conf.globalOptions:
288319
readConfigFile(pd / cfg)

compiler/options.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ type
453453
expandPosition*: TLineInfo
454454

455455
currentConfigDir*: string # used for passPP only; absolute dir
456+
skipParentDetectionMode*: bool # true while probing configs for skipParentCfg
456457
clientProcessId*: int
457458

458459

0 commit comments

Comments
 (0)