Skip to content

Commit 6561469

Browse files
committed
Synchronize identical dbscheme fragments
1 parent f1246af commit 6561469

File tree

12 files changed

+1185
-726
lines changed

12 files changed

+1185
-726
lines changed

Diff for: config/dbscheme-fragments.json

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"files": [
3+
"java/ql/lib/config/semmlecode.dbscheme",
4+
"javascript/ql/lib/semmlecode.javascript.dbscheme",
5+
"cpp/ql/lib/semmlecode.cpp.dbscheme",
6+
"python/ql/lib/semmlecode.python.dbscheme",
7+
"ruby/ql/lib/ruby.dbscheme",
8+
"go/ql/lib/go.dbscheme",
9+
"swift/prefix.dbscheme",
10+
"swift/ql/lib/swift.dbscheme",
11+
"csharp/ql/lib/semmlecode.csharp.dbscheme",
12+
"ql/ql/src/ql.dbscheme"
13+
],
14+
"fragments": [
15+
"/*- Files and folders -*/",
16+
"/*- Compilations -*/",
17+
"/*- Compilations (Java) -*/",
18+
"/*- Diagnostic messages -*/",
19+
"/*- Duplicate code -*/",
20+
"/*- External data -*/",
21+
"/*- External packages -*/",
22+
"/*- External defects and metrics -*/",
23+
"/*- Source location prefix -*/",
24+
"/*- Lines of code -*/",
25+
"/*- Snapshot date -*/",
26+
"/*- Version control data -*/",
27+
"/*- YAML -*/",
28+
"/*- XML Files -*/",
29+
"/*- SMAP -*/",
30+
"/*- Java -*/",
31+
"/*- configuration files with key value pairs -*/",
32+
"/*- Kotlin -*/",
33+
"/*- JavaScript-specific part -*/",
34+
"/*- Ruby-specific part -*/",
35+
"/*- ERB-specific part -*/",
36+
"/*- GO-specific part -*/",
37+
"/*- QL-specific part -*/",
38+
"/*- Swift-specific part -*/",
39+
"/*- C# dbscheme -*/",
40+
"/*- C++ dbscheme -*/",
41+
"/*- Python dbscheme -*/"
42+
]
43+
}

Diff for: config/sync-dbscheme-fragments.py

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env python3
2+
3+
import json
4+
import os
5+
import re
6+
import itertools
7+
8+
def make_groups(blocks):
9+
groups = {}
10+
for block in blocks:
11+
groups.setdefault("".join(block["lines"]), []).append(block)
12+
return list(groups.values())
13+
14+
def validate_fragments(fragments):
15+
for header, blocks in fragments.items():
16+
groups = make_groups(blocks)
17+
if len(groups) > 1:
18+
print("Warning: '{}' fragments are different for {}".format(header, ["{}:{}:{}".format(group[0]["file"], group[0]["start"], group[0]["end"]) for group in groups]))
19+
20+
def main():
21+
script_dir = os.path.dirname(os.path.realpath(__file__))
22+
23+
with open(os.path.join(script_dir, "dbscheme-fragments.json"), "r") as f:
24+
config = json.load(f)
25+
26+
fragment_headers = set(config["fragments"])
27+
fragments = {}
28+
for file in config["files"]:
29+
with open(os.path.join(os.path.dirname(script_dir), file), "r") as dbscheme:
30+
header = None
31+
line_number = 1
32+
block = { "file": file, "start": line_number, "end": None, "lines": [] }
33+
def end_block():
34+
nonlocal header, block, line_number, fragments
35+
block["end"] = line_number - 1
36+
if len(block["lines"]) > 0:
37+
if header is None:
38+
if re.match(r'(?m)^//.*$|/\*(\**[^\*])*\*+/', "".join(block["lines"])):
39+
# Ignore comments at the beginning of the file
40+
pass
41+
else:
42+
print("Warning: fragment without header: {}:{}:{}".format(block["file"], block["start"], block["end"]))
43+
else:
44+
fragments.setdefault(header, []).append(block)
45+
for line in dbscheme:
46+
m = re.match(r"^\/\*-.*-\*\/$", line)
47+
if m:
48+
end_block()
49+
header = line.strip()
50+
if header not in fragment_headers:
51+
print("Warning: unknown fragment header: {}: {}:{}".format(header, file, line_number))
52+
block = { "file": file, "start": line_number, "end": None, "lines": [] }
53+
block["lines"].append(line)
54+
line_number += 1
55+
end_block()
56+
validate_fragments(fragments)
57+
58+
if __name__ == "__main__":
59+
main()

0 commit comments

Comments
 (0)