Skip to content

Sync dbschemes #12849

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions config/dbscheme-fragments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"files": [
"java/ql/lib/config/semmlecode.dbscheme",
"javascript/ql/lib/semmlecode.javascript.dbscheme",
"cpp/ql/lib/semmlecode.cpp.dbscheme",
"python/ql/lib/semmlecode.python.dbscheme",
"ruby/ql/lib/ruby.dbscheme",
"go/ql/lib/go.dbscheme",
"swift/prefix.dbscheme",
"swift/ql/lib/swift.dbscheme",
"csharp/ql/lib/semmlecode.csharp.dbscheme",
"ql/ql/src/ql.dbscheme"
],
"fragments": [
"/*- Files and folders -*/",
"/*- Compilations -*/",
"/*- Compilations (Java) -*/",
"/*- Diagnostic messages -*/",
"/*- Duplicate code -*/",
"/*- External data -*/",
"/*- External packages -*/",
"/*- External defects and metrics -*/",
"/*- Source location prefix -*/",
"/*- Lines of code -*/",
"/*- Snapshot date -*/",
"/*- Version control data -*/",
"/*- YAML -*/",
"/*- XML Files -*/",
"/*- SMAP -*/",
"/*- Java -*/",
"/*- configuration files with key value pairs -*/",
"/*- Kotlin -*/",
"/*- JavaScript-specific part -*/",
"/*- Ruby-specific part -*/",
"/*- ERB-specific part -*/",
"/*- GO-specific part -*/",
"/*- QL-specific part -*/",
"/*- Swift-specific part -*/",
"/*- C# dbscheme -*/",
"/*- C++ dbscheme -*/",
"/*- Python dbscheme -*/"
]
}
59 changes: 59 additions & 0 deletions config/sync-dbscheme-fragments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python3

import json
import os
import re
import itertools

def make_groups(blocks):
groups = {}
for block in blocks:
groups.setdefault("".join(block["lines"]), []).append(block)
return list(groups.values())

def validate_fragments(fragments):
for header, blocks in fragments.items():
groups = make_groups(blocks)
if len(groups) > 1:
print("Warning: '{}' fragments are different for {}".format(header, ["{}:{}:{}".format(group[0]["file"], group[0]["start"], group[0]["end"]) for group in groups]))

def main():
script_dir = os.path.dirname(os.path.realpath(__file__))

with open(os.path.join(script_dir, "dbscheme-fragments.json"), "r") as f:
config = json.load(f)

fragment_headers = set(config["fragments"])
fragments = {}
for file in config["files"]:
with open(os.path.join(os.path.dirname(script_dir), file), "r") as dbscheme:
header = None
line_number = 1
block = { "file": file, "start": line_number, "end": None, "lines": [] }
def end_block():
nonlocal header, block, line_number, fragments
block["end"] = line_number - 1
if len(block["lines"]) > 0:
if header is None:
if re.match(r'(?m)^//.*$|/\*(\**[^\*])*\*+/', "".join(block["lines"])):
# Ignore comments at the beginning of the file
pass
else:
print("Warning: fragment without header: {}:{}:{}".format(block["file"], block["start"], block["end"]))
else:
fragments.setdefault(header, []).append(block)
for line in dbscheme:
m = re.match(r"^\/\*-.*-\*\/$", line)
if m:
end_block()
header = line.strip()
if header not in fragment_headers:
print("Warning: unknown fragment header: {}: {}:{}".format(header, file, line_number))
block = { "file": file, "start": line_number, "end": None, "lines": [] }
block["lines"].append(line)
line_number += 1
end_block()
validate_fragments(fragments)

if __name__ == "__main__":
main()
Loading