diff options
author | iaz1607 <iaz1607@yandex-team.ru> | 2022-02-10 16:45:37 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:37 +0300 |
commit | e5437feb4ac2d2dc044e1090b9312dde5ef197e0 (patch) | |
tree | f5a238c69dd20a1fa2092127a31b8aff25020f7d /build/scripts | |
parent | f4945d0a44b8770f0801de3056aa41639b0b7bd2 (diff) | |
download | ydb-e5437feb4ac2d2dc044e1090b9312dde5ef197e0.tar.gz |
Restoring authorship annotation for <iaz1607@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'build/scripts')
-rw-r--r-- | build/scripts/clang_tidy.py | 204 | ||||
-rw-r--r-- | build/scripts/clang_tidy_arch.py | 66 |
2 files changed, 135 insertions, 135 deletions
diff --git a/build/scripts/clang_tidy.py b/build/scripts/clang_tidy.py index eb1b690ee9..80c97743a8 100644 --- a/build/scripts/clang_tidy.py +++ b/build/scripts/clang_tidy.py @@ -1,54 +1,54 @@ -import argparse +import argparse import contextlib -import json +import json import os import re import shutil -import sys +import sys import tempfile - -import subprocess - -import yaml - - -def setup_script(args): - global tidy_config_validation - sys.path.append(os.path.dirname(args.config_validation_script)) - import tidy_config_validation - - -def parse_args(): - parser = argparse.ArgumentParser() + +import subprocess + +import yaml + + +def setup_script(args): + global tidy_config_validation + sys.path.append(os.path.dirname(args.config_validation_script)) + import tidy_config_validation + + +def parse_args(): + parser = argparse.ArgumentParser() parser.add_argument("--testing-src", required=True) parser.add_argument("--clang-tidy-bin", required=True) - parser.add_argument("--config-validation-script", required=True) - parser.add_argument("--ymake-python", required=True) + parser.add_argument("--config-validation-script", required=True) + parser.add_argument("--ymake-python", required=True) parser.add_argument("--tidy-json", required=True) parser.add_argument("--source-root", required=True) - parser.add_argument("--build-root", required=True) - parser.add_argument("--default-config-file", required=True) - parser.add_argument("--project-config-file", required=True) - parser.add_argument("--export-fixes", required=True) - parser.add_argument("--checks", required=False, default="") - parser.add_argument("--header-filter", required=False, default=None) - return parser.parse_known_args() - - + parser.add_argument("--build-root", required=True) + parser.add_argument("--default-config-file", required=True) + parser.add_argument("--project-config-file", required=True) + parser.add_argument("--export-fixes", required=True) + parser.add_argument("--checks", required=False, default="") + parser.add_argument("--header-filter", required=False, default=None) + return parser.parse_known_args() + + def generate_compilation_database(clang_cmd, source_root, filename, path): compile_database = [ { "file": filename, - "command": subprocess.list2cmdline(clang_cmd), + "command": subprocess.list2cmdline(clang_cmd), "directory": source_root, } ] compilation_database_json = os.path.join(path, "compile_commands.json") with open(compilation_database_json, "w") as afile: - json.dump(compile_database, afile) - return compilation_database_json - - + json.dump(compile_database, afile) + return compilation_database_json + + @contextlib.contextmanager def gen_tmpdir(): path = tempfile.mkdtemp() @@ -56,13 +56,13 @@ def gen_tmpdir(): shutil.rmtree(path) -@contextlib.contextmanager -def gen_tmpfile(): - _, path = tempfile.mkstemp() - yield path - os.remove(path) - - +@contextlib.contextmanager +def gen_tmpfile(): + _, path = tempfile.mkstemp() + yield path + os.remove(path) + + def load_profile(path): if os.path.exists(path): files = os.listdir(path) @@ -78,53 +78,53 @@ def load_profile(path): } -def load_fixes(path): - if os.path.exists(path): - with open(path, 'r') as afile: - return afile.read() - else: - return "" - - -def is_generated(testing_src, build_root): - return testing_src.startswith(build_root) - - -def generate_outputs(output_json): - output_obj = os.path.splitext(output_json)[0] + ".o" - open(output_obj, "w").close() - open(output_json, "w").close() - - -def filter_configs(result_config, filtered_config): - with open(result_config, 'r') as afile: - input_config = yaml.safe_load(afile) - result_config = tidy_config_validation.filter_config(input_config) - with open(filtered_config, 'w') as afile: - yaml.safe_dump(result_config, afile) - - -def main(): - args, clang_cmd = parse_args() - setup_script(args) - clang_tidy_bin = args.clang_tidy_bin - output_json = args.tidy_json - generate_outputs(output_json) - if is_generated(args.testing_src, args.build_root): - return - if args.header_filter is None: - header_filter = r"^" + re.escape(os.path.dirname(args.testing_src)) + r".*" # .pb.h files will be excluded because they are not in source_root - else: - header_filter = r"^(" + args.header_filter + r").*" - - with gen_tmpdir() as profile_tmpdir, gen_tmpdir() as db_tmpdir, gen_tmpfile() as fixes_file, gen_tmpdir() as config_dir: - result_config_file = args.default_config_file - if args.project_config_file != args.default_config_file: - result_config = os.path.join(config_dir, "result_tidy_config.yaml") - filtered_config = os.path.join(config_dir, "filtered_tidy_config.yaml") - filter_configs(args.project_config_file, filtered_config) - result_config_file = tidy_config_validation.merge_tidy_configs(base_config_path=args.default_config_file, additional_config_path=filtered_config, result_config_path=result_config) - compile_command_path = generate_compilation_database(clang_cmd, args.source_root, args.testing_src, db_tmpdir) +def load_fixes(path): + if os.path.exists(path): + with open(path, 'r') as afile: + return afile.read() + else: + return "" + + +def is_generated(testing_src, build_root): + return testing_src.startswith(build_root) + + +def generate_outputs(output_json): + output_obj = os.path.splitext(output_json)[0] + ".o" + open(output_obj, "w").close() + open(output_json, "w").close() + + +def filter_configs(result_config, filtered_config): + with open(result_config, 'r') as afile: + input_config = yaml.safe_load(afile) + result_config = tidy_config_validation.filter_config(input_config) + with open(filtered_config, 'w') as afile: + yaml.safe_dump(result_config, afile) + + +def main(): + args, clang_cmd = parse_args() + setup_script(args) + clang_tidy_bin = args.clang_tidy_bin + output_json = args.tidy_json + generate_outputs(output_json) + if is_generated(args.testing_src, args.build_root): + return + if args.header_filter is None: + header_filter = r"^" + re.escape(os.path.dirname(args.testing_src)) + r".*" # .pb.h files will be excluded because they are not in source_root + else: + header_filter = r"^(" + args.header_filter + r").*" + + with gen_tmpdir() as profile_tmpdir, gen_tmpdir() as db_tmpdir, gen_tmpfile() as fixes_file, gen_tmpdir() as config_dir: + result_config_file = args.default_config_file + if args.project_config_file != args.default_config_file: + result_config = os.path.join(config_dir, "result_tidy_config.yaml") + filtered_config = os.path.join(config_dir, "filtered_tidy_config.yaml") + filter_configs(args.project_config_file, filtered_config) + result_config_file = tidy_config_validation.merge_tidy_configs(base_config_path=args.default_config_file, additional_config_path=filtered_config, result_config_path=result_config) + compile_command_path = generate_compilation_database(clang_cmd, args.source_root, args.testing_src, db_tmpdir) cmd = [ clang_tidy_bin, args.testing_src, @@ -133,38 +133,38 @@ def main(): "--warnings-as-errors", "*", "--config-file", - result_config_file, + result_config_file, "--header-filter", header_filter, "--use-color", "--enable-check-profile", - "--store-check-profile={}".format(profile_tmpdir), + "--store-check-profile={}".format(profile_tmpdir), ] - if args.export_fixes == "yes": - cmd += ["--export-fixes", fixes_file] - - if args.checks: - cmd += ["--checks", args.checks] + if args.export_fixes == "yes": + cmd += ["--export-fixes", fixes_file] + + if args.checks: + cmd += ["--checks", args.checks] res = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = res.communicate() exit_code = res.returncode - profile = load_profile(profile_tmpdir) - testing_src = os.path.relpath(args.testing_src, args.source_root) - tidy_fixes = load_fixes(fixes_file) + profile = load_profile(profile_tmpdir) + testing_src = os.path.relpath(args.testing_src, args.source_root) + tidy_fixes = load_fixes(fixes_file) with open(output_json, "wb") as afile: json.dump( { - "file": testing_src, + "file": testing_src, "exit_code": exit_code, "profile": profile, "stderr": err, "stdout": out, - "fixes": tidy_fixes, + "fixes": tidy_fixes, }, afile, ) - -if __name__ == "__main__": - main() + +if __name__ == "__main__": + main() diff --git a/build/scripts/clang_tidy_arch.py b/build/scripts/clang_tidy_arch.py index 7caf623a3d..b142a8d48a 100644 --- a/build/scripts/clang_tidy_arch.py +++ b/build/scripts/clang_tidy_arch.py @@ -1,33 +1,33 @@ -import os -import argparse -import json - - -def parse_args(): - parser = argparse.ArgumentParser() - parser.add_argument("--output-file") - parser.add_argument("--build-root") - parser.add_argument("--source-root") - return parser.parse_known_args() - - -def main(): - args, unknown_args = parse_args() - inputs = unknown_args - result_json = {} - for inp in inputs: - if os.path.exists(inp) and inp.endswith("tidyjson"): - with open(inp, 'r') as afile: - file_content = afile.read().strip() - if not file_content: - continue - errors = json.loads(file_content) - testing_src = errors["file"] - result_json[testing_src] = errors - - with open(args.output_file, 'w') as afile: - json.dump(result_json, afile, indent=4) # TODO remove indent - - -if __name__ == "__main__": - main() +import os +import argparse +import json + + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument("--output-file") + parser.add_argument("--build-root") + parser.add_argument("--source-root") + return parser.parse_known_args() + + +def main(): + args, unknown_args = parse_args() + inputs = unknown_args + result_json = {} + for inp in inputs: + if os.path.exists(inp) and inp.endswith("tidyjson"): + with open(inp, 'r') as afile: + file_content = afile.read().strip() + if not file_content: + continue + errors = json.loads(file_content) + testing_src = errors["file"] + result_json[testing_src] = errors + + with open(args.output_file, 'w') as afile: + json.dump(result_json, afile, indent=4) # TODO remove indent + + +if __name__ == "__main__": + main() |