Make env vars automatically grab from config
This commit is contained in:
parent
2259a51d4e
commit
e0ea3d09ac
1 changed files with 32 additions and 25 deletions
57
nimgen.nim
57
nimgen.nim
|
|
@ -43,11 +43,15 @@ proc addEnv(str: string): string =
|
||||||
try:
|
try:
|
||||||
newStr = newStr % [pair.key, pair.value.string]
|
newStr = newStr % [pair.key, pair.value.string]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
# Ignore if there are no values to replace. We
|
||||||
|
# want to continue anyway
|
||||||
discard
|
discard
|
||||||
|
|
||||||
try:
|
try:
|
||||||
newStr = newStr % ["output", gOutput]
|
newStr = newStr % ["output", gOutput]
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
# Ignore if there are no values to replace. We
|
||||||
|
# want to continue anyway
|
||||||
discard
|
discard
|
||||||
|
|
||||||
# if there are still format args, print a warning
|
# if there are still format args, print a warning
|
||||||
|
|
@ -56,6 +60,10 @@ proc addEnv(str: string): string =
|
||||||
|
|
||||||
return newStr
|
return newStr
|
||||||
|
|
||||||
|
proc `[]`(table: OrderedTableRef[string, string], key: string): string =
|
||||||
|
## Gets table values with env vars inserted
|
||||||
|
tables.`[]`(table, key).addEnv
|
||||||
|
|
||||||
proc execProc(cmd: string): string =
|
proc execProc(cmd: string): string =
|
||||||
result = ""
|
result = ""
|
||||||
var
|
var
|
||||||
|
|
@ -673,30 +681,30 @@ proc doActions(file: string, c2nimConfig: var c2nimConfigObj, cfg: OrderedTableR
|
||||||
"pipe"] and sfile != "":
|
"pipe"] and sfile != "":
|
||||||
if action == "prepend":
|
if action == "prepend":
|
||||||
if srch != "":
|
if srch != "":
|
||||||
prepend(sfile, cfg[act].addEnv(), cfg[srch].addEnv())
|
prepend(sfile, cfg[act], cfg[srch])
|
||||||
else:
|
else:
|
||||||
prepend(sfile, cfg[act].addEnv())
|
prepend(sfile, cfg[act])
|
||||||
elif action == "append":
|
elif action == "append":
|
||||||
if srch != "":
|
if srch != "":
|
||||||
append(sfile, cfg[act].addEnv(), cfg[srch].addEnv())
|
append(sfile, cfg[act], cfg[srch])
|
||||||
else:
|
else:
|
||||||
append(sfile, cfg[act].addEnv())
|
append(sfile, cfg[act])
|
||||||
elif action == "replace":
|
elif action == "replace":
|
||||||
if srch != "":
|
if srch != "":
|
||||||
freplace(sfile, cfg[srch].addEnv(), cfg[act].addEnv())
|
freplace(sfile, cfg[srch], cfg[act])
|
||||||
elif action == "comment":
|
elif action == "comment":
|
||||||
if srch != "":
|
if srch != "":
|
||||||
comment(sfile, cfg[srch].addEnv(), cfg[act].addEnv())
|
comment(sfile, cfg[srch], cfg[act])
|
||||||
elif action == "rename":
|
elif action == "rename":
|
||||||
rename(sfile, cfg[act].addEnv())
|
rename(sfile, cfg[act])
|
||||||
elif action == "compile":
|
elif action == "compile":
|
||||||
c2nimConfig.compile.add(cfg[act].addEnv())
|
c2nimConfig.compile.add(cfg[act])
|
||||||
elif action == "dynlib":
|
elif action == "dynlib":
|
||||||
c2nimConfig.dynlib.add(cfg[act].addEnv())
|
c2nimConfig.dynlib.add(cfg[act])
|
||||||
elif action == "pragma":
|
elif action == "pragma":
|
||||||
c2nimConfig.pragma.add(cfg[act].addEnv())
|
c2nimConfig.pragma.add(cfg[act])
|
||||||
elif action == "pipe":
|
elif action == "pipe":
|
||||||
pipe(sfile, cfg[act].addEnv())
|
pipe(sfile, cfg[act])
|
||||||
srch = ""
|
srch = ""
|
||||||
elif action == "search":
|
elif action == "search":
|
||||||
srch = act
|
srch = act
|
||||||
|
|
@ -734,7 +742,7 @@ proc runFile(file: string, cfgin: OrderedTableRef) =
|
||||||
if file.find(re(pat)).isSome():
|
if file.find(re(pat)).isSome():
|
||||||
echo "Appending " & file & " " & pattern
|
echo "Appending " & file & " " & pattern
|
||||||
for key in gWildcards[pattern].keys():
|
for key in gWildcards[pattern].keys():
|
||||||
cfg[key & "." & pattern] = gWildcards[pattern][key].addEnv()
|
cfg[key & "." & pattern] = gWildcards[pattern][key]
|
||||||
|
|
||||||
var
|
var
|
||||||
c2nimConfig = c2nimConfigObj(
|
c2nimConfig = c2nimConfigObj(
|
||||||
|
|
@ -766,9 +774,9 @@ proc runFile(file: string, cfgin: OrderedTableRef) =
|
||||||
elif act == "noprocess":
|
elif act == "noprocess":
|
||||||
noprocess = true
|
noprocess = true
|
||||||
elif act == "flags":
|
elif act == "flags":
|
||||||
c2nimConfig.flags = cfg[act].addEnv()
|
c2nimConfig.flags = cfg[act]
|
||||||
elif act == "ppflags":
|
elif act == "ppflags":
|
||||||
c2nimConfig.ppflags = cfg[act].addEnv()
|
c2nimConfig.ppflags = cfg[act]
|
||||||
|
|
||||||
if c2nimConfig.recurse and c2nimConfig.inline:
|
if c2nimConfig.recurse and c2nimConfig.inline:
|
||||||
raise newException(Exception, "Cannot use recurse and inline simultaneously")
|
raise newException(Exception, "Cannot use recurse and inline simultaneously")
|
||||||
|
|
@ -788,7 +796,7 @@ proc runCfg(cfg: string) =
|
||||||
|
|
||||||
if gConfig.hasKey("n.global"):
|
if gConfig.hasKey("n.global"):
|
||||||
if gConfig["n.global"].hasKey("output"):
|
if gConfig["n.global"].hasKey("output"):
|
||||||
gOutput = gConfig["n.global"]["output"].addEnv()
|
gOutput = gConfig["n.global"]["output"]
|
||||||
if dirExists(gOutput):
|
if dirExists(gOutput):
|
||||||
if "-f" in commandLineParams():
|
if "-f" in commandLineParams():
|
||||||
try:
|
try:
|
||||||
|
|
@ -804,14 +812,14 @@ proc runCfg(cfg: string) =
|
||||||
createDir(gOutput)
|
createDir(gOutput)
|
||||||
|
|
||||||
if gConfig["n.global"].hasKey("cpp_compiler"):
|
if gConfig["n.global"].hasKey("cpp_compiler"):
|
||||||
gCppCompiler = gConfig["n.global"]["cpp_compiler"].addEnv()
|
gCppCompiler = gConfig["n.global"]["cpp_compiler"]
|
||||||
if gConfig["n.global"].hasKey("c_compiler"):
|
if gConfig["n.global"].hasKey("c_compiler"):
|
||||||
gCCompiler = gConfig["n.global"]["c_compiler"].addEnv()
|
gCCompiler = gConfig["n.global"]["c_compiler"]
|
||||||
|
|
||||||
if gConfig["n.global"].hasKey("filter"):
|
if gConfig["n.global"].hasKey("filter"):
|
||||||
gFilter = gConfig["n.global"]["filter"].addEnv()
|
gFilter = gConfig["n.global"]["filter"]
|
||||||
if gConfig["n.global"].hasKey("quotes"):
|
if gConfig["n.global"].hasKey("quotes"):
|
||||||
if gConfig["n.global"]["quotes"].addEnv() == "false":
|
if gConfig["n.global"]["quotes"] == "false":
|
||||||
gQuotes = false
|
gQuotes = false
|
||||||
|
|
||||||
if gConfig.hasKey("n.include"):
|
if gConfig.hasKey("n.include"):
|
||||||
|
|
@ -826,7 +834,7 @@ proc runCfg(cfg: string) =
|
||||||
for prep in gConfig["n.prepare"].keys():
|
for prep in gConfig["n.prepare"].keys():
|
||||||
let (key, val) = getKey(prep)
|
let (key, val) = getKey(prep)
|
||||||
if val == true:
|
if val == true:
|
||||||
let prepVal = gConfig["n.prepare"][prep].addEnv()
|
let prepVal = gConfig["n.prepare"][prep]
|
||||||
if key == "download":
|
if key == "download":
|
||||||
downloadUrl(prepVal)
|
downloadUrl(prepVal)
|
||||||
elif key == "extract":
|
elif key == "extract":
|
||||||
|
|
@ -848,10 +856,10 @@ proc runCfg(cfg: string) =
|
||||||
let (key, val) = getKey(wild)
|
let (key, val) = getKey(wild)
|
||||||
if val == true:
|
if val == true:
|
||||||
if key == "wildcard":
|
if key == "wildcard":
|
||||||
wildcard = gConfig["n.wildcard"][wild].addEnv()
|
wildcard = gConfig["n.wildcard"][wild]
|
||||||
else:
|
else:
|
||||||
gWildcards.setSectionKey(wildcard, wild,
|
gWildcards.setSectionKey(wildcard, wild,
|
||||||
gConfig["n.wildcard"][wild].addEnv())
|
gConfig["n.wildcard"][wild])
|
||||||
|
|
||||||
if gConfig.hasKey("n.after"):
|
if gConfig.hasKey("n.after"):
|
||||||
var wildcard = ""
|
var wildcard = ""
|
||||||
|
|
@ -859,11 +867,10 @@ proc runCfg(cfg: string) =
|
||||||
let (key, val) = getKey(afterKey)
|
let (key, val) = getKey(afterKey)
|
||||||
if val == true:
|
if val == true:
|
||||||
if key == "wildcard":
|
if key == "wildcard":
|
||||||
wildcard = gConfig["n.after"][afterKey].addEnv()
|
wildcard = gConfig["n.after"][afterKey]
|
||||||
else:
|
else:
|
||||||
gAfter.setSectionKey(wildcard, afterKey,
|
gAfter.setSectionKey(wildcard, afterKey,
|
||||||
gConfig["n.after"][afterKey].addEnv())
|
gConfig["n.after"][afterKey])
|
||||||
|
|
||||||
|
|
||||||
for file in gConfig.keys():
|
for file in gConfig.keys():
|
||||||
if file in @["n.global", "n.include", "n.exclude", "n.prepare", "n.wildcard", "n.after"]:
|
if file in @["n.global", "n.include", "n.exclude", "n.prepare", "n.wildcard", "n.after"]:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue