refactoring: removed cmdlinehelper.mainCommand callback
This commit is contained in:
parent
c2c7f60259
commit
3492178494
5 changed files with 32 additions and 32 deletions
|
|
@ -34,7 +34,6 @@ type
|
||||||
suggestMode*: bool
|
suggestMode*: bool
|
||||||
supportsStdinFile*: bool
|
supportsStdinFile*: bool
|
||||||
processCmdLine*: proc(pass: TCmdLinePass, cmd: string; config: ConfigRef)
|
processCmdLine*: proc(pass: TCmdLinePass, cmd: string; config: ConfigRef)
|
||||||
mainCommand*: proc(graph: ModuleGraph)
|
|
||||||
|
|
||||||
proc initDefinesProg*(self: NimProg, conf: ConfigRef, name: string) =
|
proc initDefinesProg*(self: NimProg, conf: ConfigRef, name: string) =
|
||||||
condsyms.initDefines(conf.symbols)
|
condsyms.initDefines(conf.symbols)
|
||||||
|
|
@ -56,21 +55,21 @@ proc processCmdLineAndProjectPath*(self: NimProg, conf: ConfigRef) =
|
||||||
else:
|
else:
|
||||||
conf.projectPath = AbsoluteDir canonicalizePath(conf, AbsoluteFile getCurrentDir())
|
conf.projectPath = AbsoluteDir canonicalizePath(conf, AbsoluteFile getCurrentDir())
|
||||||
|
|
||||||
proc loadConfigsAndRunMainCommand*(self: NimProg, cache: IdentCache; conf: ConfigRef): bool =
|
proc loadConfigsAndRunMainCommand*(self: NimProg, cache: IdentCache; conf: ConfigRef;
|
||||||
|
graph: ModuleGraph): bool =
|
||||||
if self.suggestMode:
|
if self.suggestMode:
|
||||||
conf.command = "nimsuggest"
|
conf.command = "nimsuggest"
|
||||||
loadConfigs(DefaultConfig, cache, conf) # load all config files
|
loadConfigs(DefaultConfig, cache, conf) # load all config files
|
||||||
|
|
||||||
block:
|
if not self.suggestMode:
|
||||||
let scriptFile = conf.projectFull.changeFileExt("nims")
|
let scriptFile = conf.projectFull.changeFileExt("nims")
|
||||||
if not self.suggestMode:
|
# 'nim foo.nims' means to just run the NimScript file and do nothing more:
|
||||||
# 'nim foo.nims' means to just run the NimScript file and do nothing more:
|
if fileExists(scriptFile) and scriptFile == conf.projectFull:
|
||||||
if fileExists(scriptFile) and scriptFile == conf.projectFull:
|
if conf.command == "":
|
||||||
if conf.command == "":
|
conf.command = "e"
|
||||||
conf.command = "e"
|
return false
|
||||||
return false
|
elif conf.command.normalize == "e":
|
||||||
elif conf.command.normalize == "e":
|
return false
|
||||||
return false
|
|
||||||
|
|
||||||
# now process command line arguments again, because some options in the
|
# now process command line arguments again, because some options in the
|
||||||
# command line can overwrite the config file's settings
|
# command line can overwrite the config file's settings
|
||||||
|
|
@ -79,7 +78,5 @@ proc loadConfigsAndRunMainCommand*(self: NimProg, cache: IdentCache; conf: Confi
|
||||||
if conf.command == "":
|
if conf.command == "":
|
||||||
rawMessage(conf, errGenerated, "command missing")
|
rawMessage(conf, errGenerated, "command missing")
|
||||||
|
|
||||||
let graph = newModuleGraph(cache, conf)
|
|
||||||
graph.suggestMode = self.suggestMode
|
graph.suggestMode = self.suggestMode
|
||||||
self.mainCommand(graph)
|
|
||||||
return true
|
return true
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import
|
||||||
commands, options, msgs,
|
commands, options, msgs,
|
||||||
extccomp, strutils, os, main, parseopt,
|
extccomp, strutils, os, main, parseopt,
|
||||||
idents, lineinfos, cmdlinehelper,
|
idents, lineinfos, cmdlinehelper,
|
||||||
pathutils
|
pathutils, modulegraphs
|
||||||
|
|
||||||
from std/browsers import openDefaultBrowser
|
from std/browsers import openDefaultBrowser
|
||||||
from nodejs import findNodeJs
|
from nodejs import findNodeJs
|
||||||
|
|
@ -70,8 +70,7 @@ proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
|
||||||
proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
||||||
let self = NimProg(
|
let self = NimProg(
|
||||||
supportsStdinFile: true,
|
supportsStdinFile: true,
|
||||||
processCmdLine: processCmdLine,
|
processCmdLine: processCmdLine
|
||||||
mainCommand: mainCommand
|
|
||||||
)
|
)
|
||||||
self.initDefinesProg(conf, "nim_compiler")
|
self.initDefinesProg(conf, "nim_compiler")
|
||||||
if paramCount() == 0:
|
if paramCount() == 0:
|
||||||
|
|
@ -79,7 +78,9 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
||||||
return
|
return
|
||||||
|
|
||||||
self.processCmdLineAndProjectPath(conf)
|
self.processCmdLineAndProjectPath(conf)
|
||||||
if not self.loadConfigsAndRunMainCommand(cache, conf): return
|
var graph = newModuleGraph(cache, conf)
|
||||||
|
if not self.loadConfigsAndRunMainCommand(cache, conf, graph): return
|
||||||
|
mainCommand(graph)
|
||||||
if conf.hasHint(hintGCStats): echo(GC_getStatistics())
|
if conf.hasHint(hintGCStats): echo(GC_getStatistics())
|
||||||
#echo(GC_getStatistics())
|
#echo(GC_getStatistics())
|
||||||
if conf.errorCounter != 0: return
|
if conf.errorCounter != 0: return
|
||||||
|
|
|
||||||
|
|
@ -1209,15 +1209,13 @@ proc mainCommand(graph: ModuleGraph) =
|
||||||
else: "Debug"
|
else: "Debug"
|
||||||
let sec = formatFloat(epochTime() - conf.lastCmdTime, ffDecimal, 3)
|
let sec = formatFloat(epochTime() - conf.lastCmdTime, ffDecimal, 3)
|
||||||
let project = if optListFullPaths in conf.globalOptions: $conf.projectFull else: $conf.projectName
|
let project = if optListFullPaths in conf.globalOptions: $conf.projectFull else: $conf.projectName
|
||||||
var output = $conf.absOutFile
|
|
||||||
if optListFullPaths notin conf.globalOptions: output = output.AbsoluteFile.extractFilename
|
|
||||||
rawMessage(conf, hintSuccessX, [
|
rawMessage(conf, hintSuccessX, [
|
||||||
"loc", loc,
|
"loc", loc,
|
||||||
"sec", sec,
|
"sec", sec,
|
||||||
"mem", mem,
|
"mem", mem,
|
||||||
"build", build,
|
"build", build,
|
||||||
"project", project,
|
"project", project,
|
||||||
"output", output,
|
"output", ""
|
||||||
])
|
])
|
||||||
|
|
||||||
proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
|
proc processCmdLine(pass: TCmdLinePass, cmd: string; config: ConfigRef) =
|
||||||
|
|
@ -1262,8 +1260,7 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
||||||
incl conf.options, optStaticBoundsCheck
|
incl conf.options, optStaticBoundsCheck
|
||||||
let self = NimProg(
|
let self = NimProg(
|
||||||
supportsStdinFile: true,
|
supportsStdinFile: true,
|
||||||
processCmdLine: processCmdLine,
|
processCmdLine: processCmdLine
|
||||||
mainCommand: mainCommand
|
|
||||||
)
|
)
|
||||||
self.initDefinesProg(conf, "drnim")
|
self.initDefinesProg(conf, "drnim")
|
||||||
if paramCount() == 0:
|
if paramCount() == 0:
|
||||||
|
|
@ -1271,7 +1268,9 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
||||||
return
|
return
|
||||||
|
|
||||||
self.processCmdLineAndProjectPath(conf)
|
self.processCmdLineAndProjectPath(conf)
|
||||||
if not self.loadConfigsAndRunMainCommand(cache, conf): return
|
var graph = newModuleGraph(cache, conf)
|
||||||
|
if not self.loadConfigsAndRunMainCommand(cache, conf, graph): return
|
||||||
|
mainCommand(graph)
|
||||||
if conf.hasHint(hintGCStats): echo(GC_getStatistics())
|
if conf.hasHint(hintGCStats): echo(GC_getStatistics())
|
||||||
|
|
||||||
when compileOption("gc", "v2") or compileOption("gc", "refc"):
|
when compileOption("gc", "v2") or compileOption("gc", "refc"):
|
||||||
|
|
|
||||||
|
|
@ -619,8 +619,7 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string; conf: ConfigRef) =
|
||||||
proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
||||||
let self = NimProg(
|
let self = NimProg(
|
||||||
suggestMode: true,
|
suggestMode: true,
|
||||||
processCmdLine: processCmdLine,
|
processCmdLine: processCmdLine
|
||||||
mainCommand: mainCommand
|
|
||||||
)
|
)
|
||||||
self.initDefinesProg(conf, "nimsuggest")
|
self.initDefinesProg(conf, "nimsuggest")
|
||||||
|
|
||||||
|
|
@ -644,7 +643,9 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
||||||
#msgs.writelnHook = proc (line: string) = log(line)
|
#msgs.writelnHook = proc (line: string) = log(line)
|
||||||
myLog("START " & conf.projectFull.string)
|
myLog("START " & conf.projectFull.string)
|
||||||
|
|
||||||
discard self.loadConfigsAndRunMainCommand(cache, conf)
|
var graph = newModuleGraph(cache, conf)
|
||||||
|
if self.loadConfigsAndRunMainCommand(cache, conf, graph):
|
||||||
|
mainCommand(graph)
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
handleCmdLine(newIdentCache(), newConfigRef())
|
handleCmdLine(newIdentCache(), newConfigRef())
|
||||||
|
|
@ -698,8 +699,7 @@ else:
|
||||||
conf = newConfigRef()
|
conf = newConfigRef()
|
||||||
self = NimProg(
|
self = NimProg(
|
||||||
suggestMode: true,
|
suggestMode: true,
|
||||||
processCmdLine: mockCmdLine,
|
processCmdLine: mockCmdLine
|
||||||
mainCommand: mockCommand
|
|
||||||
)
|
)
|
||||||
self.initDefinesProg(conf, "nimsuggest")
|
self.initDefinesProg(conf, "nimsuggest")
|
||||||
|
|
||||||
|
|
@ -722,7 +722,9 @@ else:
|
||||||
#msgs.writelnHook = proc (line: string) = log(line)
|
#msgs.writelnHook = proc (line: string) = log(line)
|
||||||
myLog("START " & conf.projectFull.string)
|
myLog("START " & conf.projectFull.string)
|
||||||
|
|
||||||
discard self.loadConfigsAndRunMainCommand(cache, conf)
|
var graph = newModuleGraph(cache, conf)
|
||||||
|
if self.loadConfigsAndRunMainCommand(cache, conf, graph):
|
||||||
|
mockCommand(graph)
|
||||||
if gLogging:
|
if gLogging:
|
||||||
for it in conf.searchPaths:
|
for it in conf.searchPaths:
|
||||||
log(it.string)
|
log(it.string)
|
||||||
|
|
|
||||||
|
|
@ -208,8 +208,7 @@ proc processCmdLine*(pass: TCmdLinePass, cmd: string; conf: ConfigRef) =
|
||||||
proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
||||||
let self = NimProg(
|
let self = NimProg(
|
||||||
suggestMode: true,
|
suggestMode: true,
|
||||||
processCmdLine: processCmdLine,
|
processCmdLine: processCmdLine
|
||||||
mainCommand: mainCommand
|
|
||||||
)
|
)
|
||||||
self.initDefinesProg(conf, "nimfind")
|
self.initDefinesProg(conf, "nimfind")
|
||||||
|
|
||||||
|
|
@ -228,6 +227,8 @@ proc handleCmdLine(cache: IdentCache; conf: ConfigRef) =
|
||||||
if not dirExists(conf.prefixDir / RelativeDir"lib"):
|
if not dirExists(conf.prefixDir / RelativeDir"lib"):
|
||||||
conf.prefixDir = AbsoluteDir""
|
conf.prefixDir = AbsoluteDir""
|
||||||
|
|
||||||
discard self.loadConfigsAndRunMainCommand(cache, conf)
|
var graph = newModuleGraph(cache, conf)
|
||||||
|
if self.loadConfigsAndRunMainCommand(cache, conf, graph):
|
||||||
|
mainCommand(graph)
|
||||||
|
|
||||||
handleCmdLine(newIdentCache(), newConfigRef())
|
handleCmdLine(newIdentCache(), newConfigRef())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue