diff options
Diffstat (limited to 'src/version.nim')
-rw-r--r-- | src/version.nim | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/version.nim b/src/version.nim new file mode 100644 index 00000000..407b974a --- /dev/null +++ b/src/version.nim @@ -0,0 +1,29 @@ +{.used.} + +import macros + +template imp(x: untyped) = import x + +macro tryImport(x: untyped, name: static string) = + let vs = ident(name & "Version") + quote do: + when not compiles(imp `x`): + static: + error("Cannot find submodule " & `name` & ".\n" & + "Please run `make submodule` to fetch the required submodules.") + import `x` as `vs` + +macro checkVersion(xs: static string, major, minor, patch: int) = + let x = ident(xs & "Version") + quote do: + when `x`.Major < `major` or `x`.Minor < `minor` or `x`.Patch < `patch`: + var es = $`major` & "." & $`minor` & "." & $`patch` + var gs = $`x`.Major & "." & $`x`.Minor & "." & $`x`.Patch + error("Version of " & `xs` & " too low (expected " & es & ", got " & + gs & ").\n" & + "Please run `make submodule` to update.") + +tryImport chakasu/version, "chakasu" + +static: + checkVersion("chakasu", 0, 1, 2) |