diff options
author | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-05-29 00:23:08 +0300 |
---|---|---|
committer | arcadia-devtools <arcadia-devtools@yandex-team.ru> | 2022-05-29 00:23:08 +0300 |
commit | 5b69557e440e6ac18399a29076fef25602859f17 (patch) | |
tree | 75bd3d609a5eb8573270d0a4c56748fb271e8010 | |
parent | 5175e52843c00949dff48c28517c835aa31d3131 (diff) | |
download | ydb-5b69557e440e6ac18399a29076fef25602859f17.tar.gz |
intermediate changes
ref:eaeb7dd5351998886d7c04f997942958fa047473
-rw-r--r-- | build/scripts/clang_tidy.py | 107 |
1 files changed, 54 insertions, 53 deletions
diff --git a/build/scripts/clang_tidy.py b/build/scripts/clang_tidy.py index 467f6ceeff..982e9015cb 100644 --- a/build/scripts/clang_tidy.py +++ b/build/scripts/clang_tidy.py @@ -1,11 +1,9 @@ import argparse -import contextlib import json import os import re import shutil import sys -import tempfile import subprocess @@ -49,20 +47,6 @@ def generate_compilation_database(clang_cmd, source_root, filename, path): return compilation_database_json -@contextlib.contextmanager -def gen_tmpdir(): - path = tempfile.mkdtemp() - yield path - shutil.rmtree(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) @@ -113,51 +97,68 @@ def main(): 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 + # .pb.h files will be excluded because they are not in source_root + header_filter = r"^" + re.escape(os.path.dirname(args.testing_src)) + r".*" 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, - "-p", - compile_command_path, - "--warnings-as-errors", - "*", - "--config-file", - result_config_file, - "--header-filter", - header_filter, - "--use-color", - "--enable-check-profile", - "--store-check-profile={}".format(profile_tmpdir), - ] - 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() - out = out.replace(args.source_root, "$(SOURCE_ROOT)") - 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) + def ensure_clean_dir(path): + path = os.path.join(args.build_root, path) + if os.path.exists(path): + shutil.rmtree(path) + os.makedirs(path) + return path + + profile_tmpdir = ensure_clean_dir("profile_tmpdir") + db_tmpdir = ensure_clean_dir("db_tmpdir") + fixes_file = "fixes.txt" + config_dir = ensure_clean_dir("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, + "-p", + compile_command_path, + "--warnings-as-errors", + "*", + "--config-file", + result_config_file, + "--header-filter", + header_filter, + "--use-color", + "--enable-check-profile", + "--store-check-profile={}".format(profile_tmpdir), + ] + if args.export_fixes == "yes": + cmd += ["--export-fixes", fixes_file] + + if args.checks: + cmd += ["--checks", args.checks] + + print("cmd: {}".format(' '.join(cmd))) + res = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = res.communicate() + out = out.replace(args.source_root, "$(SOURCE_ROOT)") + 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, - "exit_code": exit_code, + "exit_code": res.returncode, "profile": profile, "stderr": err, "stdout": out, |