@@ -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+
247266proc 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)
0 commit comments