about summary refs log tree commit diff stats
path: root/src/version.nim
blob: 1e4a80c02ae38e4baa7f6242d9122a25a9fca791 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{.used.}

import std/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` &
          ". 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, `x`.Minor, `x`.Patch) < (`major`, `minor`, `patch`):
      var es = $`major` & "." & $`minor` & "." & $`patch`
      var gs = $`x`.Major & "." & $`x`.Minor & "." & $`x`.Patch
      error("Version of " & `xs` & " too low (expected " & es & ", got " &
        gs & "). Please run `make submodule` to update.")

tryImport chagashi/version, "chagashi"
tryImport chame/version, "chame"
tryImport monoucha/version, "monoucha"

static:
  checkVersion("chagashi", 0, 5, 2)
  checkVersion("chame", 1, 0, 0)
  checkVersion("monoucha", 0, 2, 0)