• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2
3import argparse
4import itertools
5import jinja2
6import os
7import re
8import sys
9
10def semver(v):
11    if not re.fullmatch(r'\d+\.\d+\.\d+', v):
12        raise ValueError
13    return v
14
15if __name__ == '__main__':
16    parser = argparse.ArgumentParser()
17    parser.add_argument('--version', required=True, type=semver, help='Library version number')
18    parser.add_argument('output', help='Output directory for nlohmann_json.natvis')
19    args = parser.parse_args()
20
21    namespaces = ['nlohmann']
22    abi_prefix = 'json_abi'
23    abi_tags = ['_diag', '_ldvcmp']
24    version = '_v' + args.version.replace('.', '_')
25    inline_namespaces = []
26
27    # generate all combinations of inline namespace names
28    for n in range(0, len(abi_tags) + 1):
29        for tags in itertools.combinations(abi_tags, n):
30            ns = abi_prefix + ''.join(tags)
31            inline_namespaces += [ns, ns + version]
32
33    namespaces += [f'{namespaces[0]}::{ns}' for ns in inline_namespaces]
34
35    env = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath=sys.path[0]), autoescape=True, trim_blocks=True,
36                                                            lstrip_blocks=True, keep_trailing_newline=True)
37    template = env.get_template('nlohmann_json.natvis.j2')
38    natvis = template.render(namespaces=namespaces)
39
40    with open(os.path.join(args.output, 'nlohmann_json.natvis'), 'w') as f:
41        f.write(natvis)
42