nimbleexecutor.nim: add debug output

This commit is contained in:
Anna “CyberTailor” 2022-07-04 14:45:59 +05:00
parent 55dadc6702
commit 86b1a530ab
Signed by: CyberTaIlor
GPG Key ID: E7B76EDC50864BB1
4 changed files with 39 additions and 7 deletions

View File

@ -4,12 +4,14 @@
* Implemented better quoting for generated NimScript and ninja.build.
* nimbleexecutor.nim (query): add debug output
* packageinfo.nim (initPackageInfo): use custom spawnX-like wrappers
to avoid spawning too much threads
2022-07-02 Anna <cyber@sysrq.in>
* 0.2.0 tagged
* 0.2.0, 0.2.1, 0.2.2, 0.2.3 tagged
* Fixed build for binaries inside subdirectories.

View File

@ -9,6 +9,7 @@
.Nd a Nim build system
.Sh SYNOPSIS
.Nm
.Op Fl Fl debug
.Op Fl Fl binDir : Ns Ar path
.Op Fl Fl nimbleDir : Ns Ar path
.Op Fl Fl nim : Ns Ar path
@ -41,12 +42,15 @@ does not support building inside the source directory and attempting to do that
.It Fl Fl binDir : Ns Ar path
Set the executable directory, where project's binaries will be installed.
.
.It Fl Fl nimbleDir : Ns Ar path
Set the Nimble directory, where project's sources will be installed.
.It Fl Fl debug
Show debugging information.
.
.It Fl Fl nim : Ns Ar path
Set the Nim executable.
.
.It Fl Fl nimbleDir : Ns Ar path
Set the Nimble directory, where project's sources will be installed.
.
.It Fl Fl url : Ns Ar url
If this options is set,
.Nm

View File

@ -1,12 +1,23 @@
# SPDX-FileCopyrightText: 2022 Anna <cyber@sysrq.in>
# SPDX-License-Identifier: BSD-3-Clause
import json, os, osproc, sequtils, strformat, strutils
import json, logging, os, osproc, sequtils, strformat, strutils, times
import options
proc query(nimbleFile, variable: string, options: Options): string =
## Return a NimScript variable as a JSON object.
proc debugFn(s: string) =
debug("[query] " & s)
stdout.flushFile()
var timeStart: float
options.initLogger()
if options.debug:
timeStart = epochTime()
debugFn(fmt"Started querying NimScript variable '{variable}'")
let cmd = (
"$# $# --eval:'import json; include \"$#\"; echo %$#'" % [
getNimBin(options).quoteShell,
@ -21,6 +32,10 @@ proc query(nimbleFile, variable: string, options: Options): string =
if exitCode != QuitSuccess:
quit(fmt"Failed to get the value of `{variable}` from {nimbleFile}")
if options.debug:
let time = epochTime() - timeStart
debugFn(fmt"Finished querying NimScript variable '{variable}' ({time:.2f} s)")
proc queryString*(nimbleFile, variable: string, options: Options): string =
result = nimbleFile.query(variable, options).parseJson().getStr()

View File

@ -9,6 +9,7 @@ import common
type
Options* = object
showHelp*: bool
debug*: bool
nimbleDir*: string
binDir*: string
nim*: string # Nim compiler location
@ -21,8 +22,8 @@ type
const
help* = """
Usage: nimbus [-h] [--nimbleDir:path] [--binDir:path] [--nim:path] [--url:url]
[nim opts...] sourceDir [buildDir]
Usage: nimbus [-h] [--debug] [--nimbleDir:path] [--binDir:path] [--nim:path]
[--url:url] [nim opts...] sourceDir [buildDir]
positional arguments:
sourceDir
@ -30,6 +31,7 @@ positional arguments:
optional arguments:
-h, --help show this help message and exit
--debug Show debugging information.
--nimbleDir:path Nimble directory (default: $1).
--binDir:path Executable directory (default: $2).
--nim:path Nim compiler (default: nim).
@ -42,9 +44,17 @@ proc writeHelp*() =
echo(help)
quit(QuitSuccess)
proc initLogger*(options: Options) =
if getHandlers().len != 0:
return
addHandler(options.logger)
if options.debug:
setLogFilter(lvlDebug)
proc setLogger*(options: var Options) =
options.logger = newConsoleLogger()
addHandler(options.logger)
options.initLogger()
func getBuildDir*(options: Options): string =
return options.buildDir
@ -145,6 +155,7 @@ func parseFlag(flag, val: string, result: var Options, kind = cmdLongOption) =
case f
of "help", "h": result.showHelp = true
of "debug": result.debug = true
of "nimbledir": result.nimbleDir = val
of "bindir": result.binDir = val
of "nim": result.nim = val