summaryrefslogtreecommitdiff
path: root/hack/graphql_to_header.py
blob: c4eaa5fd1fe5e7ad33e6fd8c5f06a29177dee029 (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
import sys
from pathlib import Path

input_path = Path(sys.argv[1])
output_path = Path(sys.argv[2])
var_name = sys.argv[3]

with input_path.open() as f:
    lines = f.readlines()

output_path.parent.mkdir(parents=True, exist_ok=True)
with output_path.open("w") as f:
    f.write(
        f'''#ifndef QUERIES_{var_name.upper()}_H
#define QUERIES_{var_name.upper()}_H

'''
    )
    f.write(f'const char *{var_name} =\n')
    for line in lines:
        escaped = line.rstrip('\n').replace('\\', '\\\\').replace('"', '\\"')
        f.write(f'    "{escaped}\\n"\n')
    f.write(';\n')
    f.write(
        f'''
#endif // QUERIES_{var_name.upper()}_H
''')