Skip to content

Commit 1d456eb

Browse files
committed
Add script to fetch impact-db impacts data
1 parent 9d0f901 commit 1d456eb

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ PYTHON=python
1313
MAVEN=mvn
1414
BUILD_DIR=/undefined
1515
LKQL_DIR=$(BUILD_DIR)/lkql
16+
IMPACTDB_DIR=/undefined
1617
GPRBUILD=gprbuild -j$(PROCS) -p -XBUILD_MODE=$(BUILD_MODE)
1718
GPRINSTALL=gprinstall --prefix=$(PREFIX) -p -XBUILD_MODE=$(BUILD_MODE)
1819
BUILD_FOR_JIT=false
@@ -36,6 +37,9 @@ doc: build_lkql_native_jit
3637
cd user_manual && make clean html
3738
cd lkql_checker/doc && make generate html-all
3839

40+
impacts:
41+
PYTHONPATH=$(IMPACTDB_DIR) ./utils/impact-db_impacts_gen.py $(IMPACTDB_DIR)
42+
3943
format:
4044
$(MAVEN) -f lkql_jit spotless:apply
4145

utils/impact-db_impacts_gen.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python3
2+
3+
# This script should be run at the top level of the langkit-query-language with
4+
# PYTHONPATH set to the impact-db repository path. The impact-db repository path
5+
# should also be passed as first argument:
6+
#
7+
# $ PYTHONPATH=/path/to/impact-db ./impact-db_impacts_gen.py /path/to/impact-db
8+
9+
import glob
10+
import json
11+
import sys
12+
from pathlib import Path
13+
from impactdb import db
14+
15+
impactdb_dir = sys.argv[1]
16+
res = {}
17+
18+
19+
def format_impacts(impacts: [str]) -> str:
20+
gnat = list(db.config["gnat"].keys())
21+
return ",".join(list(map(lambda i: i + ".*" if i in gnat else i, impacts)))
22+
23+
24+
def format_name(name: str) -> str:
25+
return "kp_" + name.lower().replace("-", "_")
26+
27+
28+
def list_impacts(issues: [str]) -> None:
29+
entries = [e for e in db.load(impactdb_dir + "/entries") if e.type == "kp"]
30+
for e in entries:
31+
if e.name in issues:
32+
res.update({format_name(e.name): format_impacts(e.impacts)})
33+
elif e.origin in issues:
34+
res.update({format_name(e.origin): format_impacts(e.impacts)})
35+
36+
37+
kps = [kp for kp in glob.glob("./lkql_checker/share/lkql/kp/KP-*")]
38+
ids = [Path(id).stem[3:] for id in kps]
39+
list_impacts(ids)
40+
41+
impacts = {"impacts": res}
42+
impacts.update({"gnat": list(db.config["gnat"].keys())})
43+
44+
with open("./lkql_checker/share/lkql/kp/kp.json", "w", encoding="utf-8") as f:
45+
json.dump(impacts, f, ensure_ascii=False, indent=4)
46+
47+
with open("./lkql_checker/share/lkql/kp/kp.json", "a", encoding="utf-8") as f:
48+
f.write("\n")

0 commit comments

Comments
 (0)