-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andrey Zak
committed
Jul 14, 2017
1 parent
2dad6b8
commit 4d49925
Showing
14 changed files
with
220 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import tables | ||
|
||
type TaskContext* = ref object | ||
caption*: string | ||
timing*: int64 | ||
info*: seq[string] | ||
warn*: seq[string] | ||
err*: seq[string] | ||
skipped*: bool | ||
|
||
type GlobalContext* = ref object | ||
stop*:bool | ||
timing*: int64 | ||
tasks*: OrderedTable[string, TaskContext] | ||
completed*: OrderedTable[string, TaskContext] | ||
|
||
var | ||
context = GlobalContext() | ||
|
||
context.tasks = initOrderedTable[string, TaskContext]() | ||
|
||
proc globalContext*(): GlobalContext = | ||
return context | ||
|
||
proc getOrAddContext*(name: string): var TaskContext = | ||
if not context.tasks.contains(name): | ||
let newContext = TaskContext(caption: name, info: @[], err: @[], skipped: true) | ||
context.tasks.add(name, newContext) | ||
return context.tasks[name] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
template assemblyinfoOf*(body: untyped) = | ||
proc `assemblyinfoOf Task`*() = | ||
when not declaredInScope(outputPath): | ||
var outputPath {.inject.}: string | ||
var asmversion {.inject.}: Version | ||
var copyright {.inject.}: string | ||
import ../contexts | ||
import version | ||
|
||
template assemblyinfoOf*(context: TaskContext; body: untyped) = | ||
when not declaredInScope(outputPath): | ||
var outputPath {.inject.}: string | ||
var asmversion {.inject.}: Version | ||
var copyright {.inject.}: string | ||
proc `assemblyinfoOf Task`*() = | ||
proc `assemblyinfoOf Body`() = body | ||
`assemblyinfoOf Body`() | ||
context.info.add("detected assembly version $1" % [$asmversion]) | ||
var buffer = "" | ||
buffer.add("using System.Reflection;\n\c") | ||
buffer.add("using System.Runtime.InteropServices;\n\c") | ||
buffer.add("[assembly: AssemblyVersion(\"$1\")]\n\c" % [asmversion.short()]) | ||
buffer.add("[assembly: AssemblyFileVersion(\"$1\")]\n\c" % [asmversion.short()]) | ||
buffer.add("[assembly: AssemblyInformationalVersionAttribute(\"$1\")]\n\c" % [asmversion.shortWithDirty()]) | ||
buffer.add("[assembly: AssemblyCopyrightAttribute(\"$1\")]\n\c" % [copyright]) | ||
writeFile(outputPath / "SolutionVersion.cs", buffer) | ||
writeFile(outputPath / "SolutionVersion.cs", buffer) | ||
context.info.add("file SolutionVersion.cs put in $1" % [outputPath]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import ../contexts | ||
import strutils | ||
|
||
template cleanBuildFolder*(context: TaskContext; body: untyped) = | ||
when not declaredInScope(buildFolder): | ||
var buildFolder {.inject.}: string | ||
proc `cleanBuildFolder Task`*() = | ||
proc `cleanBuildFolder Body`() = body | ||
`cleanBuildFolder Body`() | ||
removeDir(buildFolder, context.warn) | ||
makeDir(buildFolder, context.err) | ||
context.info.add("cleaned folder $1" % [buildFolder]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import ../contexts | ||
import ../tools/runner | ||
|
||
template dotnetbuild*(context: TaskContext; body: untyped) = | ||
when not declaredInScope(slnFile): | ||
var slnFile {.inject.}: string | ||
proc `dotnetbuild Task`*() = | ||
proc `dotnetbuild Body`() = body | ||
`dotnetbuild Body`() | ||
var output = runAbs("dotnet restore " & slnFile.toAbsolutePath, context.err) | ||
context.info.add(output) | ||
output = runAbs("dotnet build " & slnFile.toAbsolutePath, context.err) | ||
context.info.add(output) | ||
|
||
template dotnettest*(context: TaskContext; body: untyped) = | ||
when not declaredInScope(testsProject): | ||
var testsProject {.inject.}: string | ||
proc `dotnettest Task`*() = | ||
proc `dotnettest Body`() = body | ||
`dotnettest Body`() | ||
var output = runAbs("dotnet test " & testsProject, context.err) | ||
context.info.add(output) | ||
|
||
template dotnetgcfix*(context: TaskContext; body: untyped) = | ||
# specify server gc manually in *.config file | ||
when not declaredInScope(targetConfig): | ||
var targetConfig {.inject.}: string | ||
proc `dotnetgcfix Task`*() = | ||
proc `dotnetgcfix Body`() = body | ||
`dotnetgcfix Body`() | ||
var config = targetConfig.readFile() | ||
config = config.replace(" <runtime>", " <runtime>\r\n <gcServer enabled=\"true\" />") | ||
targetConfig.writeFile(config) | ||
context.info.add("dotnet gc fix was written to $1" % [targetConfig]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,30 @@ | ||
import strutils | ||
|
||
proc removeDir*(dir: string) = | ||
echo "test" | ||
proc removeDirSafe(dir: string) = | ||
echo "removed $1" % [dir] | ||
let dirs = listDirs(dir) | ||
proc removeDir*(dir: string; errors: var seq[string]) = | ||
let dirs = listDirs(dir) | ||
|
||
for dir in dirs: | ||
try: | ||
removeDirSafe(dir) | ||
rmDir(dir) | ||
except: continue | ||
for dir in dirs: | ||
try: | ||
removeDir(dir, errors) | ||
rmDir(dir) | ||
except: | ||
errors.add("can't remove $1" % [dir]) | ||
continue | ||
|
||
let files = listFiles(dir) | ||
let files = listFiles(dir) | ||
|
||
for file in files: | ||
try: | ||
rmFile(file) | ||
except: continue | ||
for file in files: | ||
try: | ||
rmFile(file) | ||
except: | ||
errors.add("can't remove $1" % [file]) | ||
continue | ||
|
||
removeDirSafe(dir) | ||
|
||
proc makeDir*(dir: string) = | ||
proc makeDir*(dir: string; errors: var seq[string]) = | ||
if existsDir(dir): | ||
echo "dir $1 already exists" % [dir] | ||
return | ||
|
||
try: | ||
mkDir dir | ||
echo "created dir $1" % [dir] | ||
except: | ||
echo "can't create $1 dir" % [dir] | ||
errors.add("can't create $1 dir" % [dir]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,33 @@ | ||
template call*(name: untyped) = | ||
`name Task`() | ||
import system | ||
import strutils | ||
import tables | ||
import ../contexts | ||
import ../tools/time | ||
import ../tools/prettyreport | ||
|
||
template getContext(name: untyped): TaskContext = | ||
let taskName = astToStr(name) | ||
getOrAddContext(taskName) | ||
|
||
template call*(name: untyped) = | ||
if not globalContext().stop: | ||
var taskContext = getContext(name) | ||
let before = getTicks() | ||
`name Task`() | ||
let delta = getTicks() - before | ||
taskContext.timing = delta | ||
taskContext.skipped = false | ||
if taskContext.err.len > 0: | ||
globalContext().stop = true | ||
|
||
template nimbTask*(name: untyped; body: untyped): untyped = | ||
var taskContext = getContext(name) | ||
`name`(taskContext, body) | ||
|
||
template nimbExecute*(actions: untyped): untyped = | ||
task build, "": | ||
let before = getTicks() | ||
actions | ||
let delta = getTicks() - before | ||
globalContext().timing = delta | ||
prettyReport(globalContext()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import ../contexts | ||
import strutils | ||
import tables | ||
import time | ||
|
||
proc prettyReport*(context: GlobalContext) = | ||
echo "nimb report" | ||
|
||
for task in context.tasks.values: | ||
if task.skipped: | ||
continue | ||
|
||
echo task.caption.indent(1, "\t") | ||
for line in task.info: | ||
echo line.indent(2, "\t") | ||
|
||
if task.warn.len > 0: | ||
echo "warnings: $1".indent(2, "\t") % [$task.warn.len] | ||
for line in task.warn: | ||
echo line.indent(3, "\t") | ||
|
||
if task.err.len > 0: | ||
echo "errors: $1".indent(2, "\t") % [$task.err.len] | ||
for line in task.err: | ||
echo line.indent(3, "\t") | ||
|
||
echo "executed tasks:" | ||
for task in context.tasks.values: | ||
if task.skipped: | ||
continue | ||
let taskTiming = float(task.timing) * 0.001 | ||
let taskTimingStr = "$1 ms" % [$taskTiming] | ||
let line = "$1 $2" % [task.caption, taskTimingStr] | ||
echo line.indent(1, "\t") | ||
|
||
let globalTiming = float(context.timing) * 0.001 | ||
echo "nimb done in $1 ms" % [$globalTiming] |
Oops, something went wrong.