| 1 |
|
| 2 |
|
| 3 |
import argparse |
| 4 |
import itertools |
| 5 |
import jinja2 |
| 6 |
import os |
| 7 |
import re |
| 8 |
import sys |
| 9 |
|
| 10 |
def semver(v): |
| 11 |
if not re.fullmatch(r'\d+\.\d+\.\d+', v): |
| 12 |
raise ValueError |
| 13 |
return v |
| 14 |
|
| 15 |
if __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 |
|
| 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) |