aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralevitskii <alevitskii@yandex-team.com>2024-11-14 09:02:30 +0300
committeralevitskii <alevitskii@yandex-team.com>2024-11-14 09:14:07 +0300
commit14559389ace814f895db4ee116d884ae70bc7469 (patch)
tree5a8647173c6438875441a01e63593cd4ef708c88
parent8d4c37b7de13075dfe40beb41c1f807d4754de00 (diff)
downloadydb-14559389ace814f895db4ee116d884ae70bc7469.tar.gz
Add external autoincludes.json
Add external autoincludes.json commit_hash:1b3de1732fee590582ae5620570facc2c0987390
-rw-r--r--build/conf/autoincludes.json5
-rw-r--r--build/conf/settings.conf2
-rw-r--r--library/python/testing/custom_linter_util/linter_params.py81
-rw-r--r--library/python/testing/custom_linter_util/reporter.py39
-rw-r--r--library/python/testing/custom_linter_util/ya.make12
-rw-r--r--tools/cpp_style_checker/__main__.py63
-rw-r--r--tools/cpp_style_checker/ya.make13
-rw-r--r--util/ya.common3
8 files changed, 218 insertions, 0 deletions
diff --git a/build/conf/autoincludes.json b/build/conf/autoincludes.json
new file mode 100644
index 0000000000..b1ee3b4358
--- /dev/null
+++ b/build/conf/autoincludes.json
@@ -0,0 +1,5 @@
+[
+ "library/cpp/geo",
+ "util"
+]
+
diff --git a/build/conf/settings.conf b/build/conf/settings.conf
index ef90bb9fc3..40fa804104 100644
--- a/build/conf/settings.conf
+++ b/build/conf/settings.conf
@@ -125,3 +125,5 @@ _FOLDABLE_VARS=\
ARCADIA_TEST_ROOT=../arcadia_tests_data/
DEFAULT_REQUIREMENTS=network:restricted cpu:1 ram:32
+
+AUTOINCLUDE_PATHS=build/conf/autoincludes.json
diff --git a/library/python/testing/custom_linter_util/linter_params.py b/library/python/testing/custom_linter_util/linter_params.py
new file mode 100644
index 0000000000..522e6da9ed
--- /dev/null
+++ b/library/python/testing/custom_linter_util/linter_params.py
@@ -0,0 +1,81 @@
+import argparse
+import json
+from dataclasses import dataclass
+from typing import Optional
+
+
+@dataclass
+class LinterArgs:
+ source_root: str
+ project_path: str
+ output_path: str
+ lint_name: str
+ depends: dict[str, str]
+ global_resources: dict[str, str]
+ configs: list[str]
+ extra_params: dict[str, str]
+ report_file: str
+ files: list[str]
+
+
+def get_params(raw_args: Optional[list[str]] = None) -> LinterArgs:
+ parser = argparse.ArgumentParser()
+ parser.add_argument("--params")
+ parser.add_argument("--source-root")
+ parser.add_argument("--project-path")
+ parser.add_argument("--output-path")
+ parser.add_argument("--lint-name", default="")
+ parser.add_argument("--depends", action="append")
+ parser.add_argument("--global-resource", action="append", dest="global_resources")
+ parser.add_argument("--config", action="append", dest="configs")
+ parser.add_argument("--extra-param", action="append", dest="extra_params")
+ parser.add_argument("--report-file", default="-")
+ parser.add_argument("files", nargs="*")
+ args = parser.parse_args(raw_args)
+
+ if args.params:
+ with open(args.params) as f:
+ params = json.load(f)
+ source_root = params["source_root"]
+ project_path = params["project_path"]
+ output_path = params["output_path"]
+ lint_name = params.get("lint_name", "")
+ depends = params.get("depends", {})
+ global_resources = params.get("global_resources", {})
+ configs = params.get("configs", [])
+ extra_params = params.get("extra_params", {})
+ report_file = params["report_file"]
+ files = params["files"]
+ else:
+ source_root = args.source_root
+ project_path = args.project_path
+ output_path = args.output_path
+ lint_name = args.lint_name
+ depends = _parse_kv_arg(args.depends, ":")
+ global_resources = _parse_kv_arg(args.global_resources, ":")
+ configs = args.configs if args.configs else []
+ extra_params = _parse_kv_arg(args.extra_params, "=")
+ report_file = args.report_file
+ files = args.files
+
+ return LinterArgs(
+ source_root=source_root,
+ project_path=project_path,
+ output_path=output_path,
+ lint_name=lint_name,
+ depends=depends,
+ global_resources=global_resources,
+ configs=configs,
+ extra_params=extra_params,
+ report_file=report_file,
+ files=files,
+ )
+
+
+def _parse_kv_arg(arg, sep):
+ result = {}
+ if arg:
+ for item in arg:
+ var, val = item.split(sep, 1)
+ result[var] = val
+ return result
diff --git a/library/python/testing/custom_linter_util/reporter.py b/library/python/testing/custom_linter_util/reporter.py
new file mode 100644
index 0000000000..8ae559bca0
--- /dev/null
+++ b/library/python/testing/custom_linter_util/reporter.py
@@ -0,0 +1,39 @@
+import json
+import sys
+from enum import Enum
+from typing import Optional
+
+
+class LintStatus(Enum):
+ GOOD = "GOOD"
+ FAIL = "FAIL"
+ SKIPPED = "SKIPPED"
+
+
+class LintReport():
+ def __init__(self):
+ self._report = {}
+
+ def add(self, file_name: str, status: LintStatus, message: str = "", elapsed: float = 0.0):
+ self._report[file_name] = {
+ "status": status.value,
+ "message": message,
+ "elapsed": elapsed,
+ }
+
+ def dump(self, report_file, pretty: Optional[bool] = None):
+ data = {
+ "report": self._report,
+ }
+ if report_file == "-":
+ if pretty is None:
+ pretty = True
+ self._do_dump(sys.stdout, data, pretty)
+ else:
+ with open(report_file, "w") as f:
+ self._do_dump(f, data, pretty)
+
+ @staticmethod
+ def _do_dump(dest, data, pretty):
+ indent = 4 if pretty else None
+ json.dump(data, dest, indent=indent)
diff --git a/library/python/testing/custom_linter_util/ya.make b/library/python/testing/custom_linter_util/ya.make
new file mode 100644
index 0000000000..c761b09afc
--- /dev/null
+++ b/library/python/testing/custom_linter_util/ya.make
@@ -0,0 +1,12 @@
+PY3_LIBRARY()
+
+PY_SRCS(
+ linter_params.py
+ reporter.py
+)
+
+END()
+
+RECURSE_FOR_TESTS(
+ tests
+)
diff --git a/tools/cpp_style_checker/__main__.py b/tools/cpp_style_checker/__main__.py
new file mode 100644
index 0000000000..f318bb4417
--- /dev/null
+++ b/tools/cpp_style_checker/__main__.py
@@ -0,0 +1,63 @@
+import difflib
+import json
+import subprocess
+import time
+import yaml
+
+from library.python.testing.custom_linter_util import linter_params, reporter
+from library.python.testing.style import rules
+
+
+def main():
+ params = linter_params.get_params()
+
+ clang_format_binary = params.depends["contrib/libs/clang16/tools/clang-format/clang-format"]
+ style_config_path = params.configs[0]
+
+ with open(style_config_path) as f:
+ style_config = yaml.safe_load(f)
+ style_config_json = json.dumps(style_config)
+
+ report = reporter.LintReport()
+ for file_name in params.files:
+ start_time = time.time()
+ status, message = check_file(clang_format_binary, style_config_json, file_name)
+ elapsed = time.time() - start_time
+ report.add(file_name, status, message, elapsed=elapsed)
+
+ report.dump(params.report_file)
+
+
+def check_file(clang_format_binary, style_config_json, filename):
+ with open(filename, "rb") as f:
+ actual_source = f.read()
+
+ skip_reason = rules.get_skip_reason(filename, actual_source, skip_links=False)
+ if skip_reason:
+ return reporter.LintStatus.SKIPPED, "Style check is omitted: {}".format(skip_reason)
+
+ command = [clang_format_binary, '-assume-filename=' + filename, '-style=' + style_config_json]
+ styled_source = subprocess.check_output(command, input=actual_source)
+
+ if styled_source == actual_source:
+ return reporter.LintStatus.GOOD, ""
+ else:
+ diff = make_diff(actual_source, styled_source)
+ return reporter.LintStatus.FAIL, diff
+
+
+def make_diff(left, right):
+ result = ""
+ for line in difflib.unified_diff(left.decode().splitlines(), right.decode().splitlines(), fromfile='L', tofile='R'):
+ line = line.rstrip("\n")
+ if line:
+ if line[0] == "-":
+ line = "[[bad]]" + line + "[[rst]]"
+ elif line[0] == "+":
+ line = "[[good]]" + line + "[[rst]]"
+ result += line + "\n"
+ return result
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tools/cpp_style_checker/ya.make b/tools/cpp_style_checker/ya.make
new file mode 100644
index 0000000000..b25a270045
--- /dev/null
+++ b/tools/cpp_style_checker/ya.make
@@ -0,0 +1,13 @@
+PY3_PROGRAM()
+
+PEERDIR(
+ contrib/python/PyYAML
+ library/python/testing/custom_linter_util
+ library/python/testing/style
+)
+
+PY_SRCS(
+ __main__.py
+)
+
+END()
diff --git a/util/ya.common b/util/ya.common
new file mode 100644
index 0000000000..55dc0c103c
--- /dev/null
+++ b/util/ya.common
@@ -0,0 +1,3 @@
+IF (NOT USE_SYSTEM_PYTHON)
+ STYLE_CPP()
+ENDIF()