-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathgenerate_modules.py
52 lines (46 loc) · 1.42 KB
/
generate_modules.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from bs4 import BeautifulSoup
import requests
import re
from functools import reduce
import json
from pathlib import Path
from jinja2 import Environment, FileSystemLoader
from sys import exit
generate_modules_home = Path(__file__).resolve().parent
common_codingstandards_home = generate_modules_home.parent.parent.joinpath(
'cpp', 'common', 'src', 'codingstandards', 'cpp')
env = Environment(
loader=FileSystemLoader(generate_modules_home.joinpath('templates')),
trim_blocks=True,
lstrip_blocks=True
)
modules = [
{
"name": "Naming",
"sources": [
{
"name": "macros",
"file": "cxx14-stdlib-macros.json"
},
{
"name": "objects",
"file": "cxx14-stdlib-objects.json"
},
{
"name": "functions",
"file": "cxx14-stdlib-functions.json"
}
]
}
]
def load_spec(spec_file):
with spec_file.open() as f:
return json.load(f)
for module in modules:
print(f"Generating module {module['name']}")
sources = {source["name"]: load_spec(generate_modules_home.joinpath(source["file"]))[
"#select"]["tuples"] for source in module['sources']}
template = env.get_template(f"{module['name']}.qll.template")
template.stream(sources).dump(
str(common_codingstandards_home.joinpath(f"{module['name']}.qll")))
print("Done")