summary refs log tree commit diff stats
path: root/compiler/nimconf.nim
diff options
context:
space:
mode:
authorZahary Karadjov <zahary@gmail.com>2011-11-25 17:19:01 +0200
committerZahary Karadjov <zahary@gmail.com>2011-11-25 17:29:55 +0200
commitc617479c6848e07f25f92fd33b3397d65683812e (patch)
tree8d147e84c3f7e424c542bc444d8bb0d1d1bd0d78 /compiler/nimconf.nim
parented9c7761c4e37ec22ebd81acf16e3137d064cfc9 (diff)
downloadNim-c617479c6848e07f25f92fd33b3397d65683812e.tar.gz
New algorithm for locating and loading nimrod config files.
Some new options added to the compiler (see news.txt for details)
Diffstat (limited to 'compiler/nimconf.nim')
-rwxr-xr-xcompiler/nimconf.nim38
1 files changed, 20 insertions, 18 deletions
diff --git a/compiler/nimconf.nim b/compiler/nimconf.nim
index baffe350c..18bbe6cb4 100755
--- a/compiler/nimconf.nim
+++ b/compiler/nimconf.nim
@@ -204,21 +204,17 @@ proc readConfigFile(filename: string) =
     if len(condStack) > 0: lexMessage(L, errTokenExpected, "@end")
     closeLexer(L)
     if gVerbosity >= 1: rawMessage(hintConf, filename)
-  
-proc getConfigPath(filename: string): string = 
-  # try local configuration file:
+
+proc getUserConfigPath(filename: string): string =
   result = joinPath(getConfigDir(), filename)
-  if not ExistsFile(result): 
-    # try standard configuration file (installation did not distribute files
-    # the UNIX way)
-    result = joinPath([getPrefixDir(), "config", filename])
-    if not ExistsFile(result): result = "/etc/" & filename
 
-proc LoadSpecialConfig*(configfilename: string) = 
-  if optSkipConfigFile notin gGlobalOptions:
-    readConfigFile(getConfigPath(configfilename))
-  
-proc LoadConfig*(project: string) = 
+proc getSystemConfigPath(filename: string): string =
+  # try standard configuration file (installation did not distribute files
+  # the UNIX way)
+  result = joinPath([getPrefixDir(), "config", filename])
+  if not ExistsFile(result): result = "/etc/" & filename
+
+proc LoadConfigs*(cfg = "nimrod.cfg") =
   # set default value (can be overwritten):
   if libpath == "": 
     # choose default libpath:
@@ -226,8 +222,14 @@ proc LoadConfig*(project: string) =
     if (prefix == "/usr"): libpath = "/usr/lib/nimrod"
     elif (prefix == "/usr/local"): libpath = "/usr/local/lib/nimrod"
     else: libpath = joinPath(prefix, "lib")
-  LoadSpecialConfig("nimrod.cfg") # read project config file:
-  if optSkipProjConfigFile notin gGlobalOptions and project != "": 
-    var conffile = changeFileExt(project, "cfg")
-    if existsFile(conffile): readConfigFile(conffile)
-  
+
+  if optSkipConfigFile notin gGlobalOptions:
+    readConfigFile getSystemConfigPath(cfg)
+
+  if optSkipUserConfigFile notin gGlobalOptions:
+    readConfigFile getUserConfigPath(cfg)
+
+  if optSkipProjConfigFile notin gGlobalOptions and projectPath != "":
+    for dir in parentDirs(projectPath, fromRoot = true):
+      readConfigFile(dir/cfg)
+