Skip to content

Commit 80cc6bc

Browse files
author
amgudym
committed
init style_json linter
RELATES:(https://nda.ya.ru/t/Gkkktkfd7L5yye commit_hash:406bc77fb0202da33e48738e0e32a1d5271d9b6a
1 parent 3a0a7b8 commit 80cc6bc

File tree

5 files changed

+111
-0
lines changed

5 files changed

+111
-0
lines changed

build/conf/custom_lint.conf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
JSON_LINTER_DEFAULT_CONFIGS=build/config/tests/json_style/default_configs.json
2+
3+
4+
# tag:lint tag:internal
5+
macro _CUSTOM_LINT_FILES(GLOB_VAR, EXT, DIRS[], DIRS_RECURSE[]) {
6+
_GLOB(${GLOB_VAR} ${suf=/*.(${EXT}):DIRS} ${suf=/**/*.(${EXT}):DIRS_RECURSE} ${suf=/**/ya.make:DIRS_RECURSE} ${suf=/ya.make:DIRS} EXCLUDE ya.make)
7+
}
8+
9+
# tag: internal
10+
macro _ADD_JSON_EXPLICIT_LINTER_CHECK(Args...) {
11+
SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${ARCADIA_ROOT}/${JSON_LINTER_DEFAULT_CONFIGS})
12+
}
13+
14+
# tag:lint tag:test
15+
### @usage: STYLE_JSON([DIRS dirs] [DIRS_RECURSE dirs_recurse])
16+
macro STYLE_JSON(DIRS[], DIRS_RECURSE[]) {
17+
# XXX: _MAKEFILE_INCLUDE_LIKE_DEPS is extended to get linter wrapper exported to opensource
18+
SET_APPEND(_MAKEFILE_INCLUDE_LIKE_DEPS ${ARCADIA_ROOT}/tools/clang_format_json_linter/wrapper.py)
19+
SET(_VAR_JSON_LINT_FILES_SALT __DIRS__ ${DIRS} __DIRS_RECURSE__ ${DIRS_RECURSE})
20+
SET(_CUSTOM_JSON_LINT_FILES_GLOB uniq_json_lint_files_${hash:_VAR_JSON_LINT_FILES_SALT})
21+
_CUSTOM_LINT_FILES(${_CUSTOM_JSON_LINT_FILES_GLOB} json DIRS .${pre=/:DIRS} DIRS_RECURSE $DIRS_RECURSE)
22+
_ADD_JSON_EXPLICIT_LINTER_CHECK(NAME clang_format_json WRAPPER_SCRIPT tools/clang_format_json_linter/wrapper.py CONFIGS $JSON_LINTER_DEFAULT_CONFIGS FILES ${${_CUSTOM_JSON_LINT_FILES_GLOB}})
23+
}

build/plugins/_dart_fields.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,19 @@ def cpp_configs(cls, unit, flat_args, spec_args):
673673
assert_file_exists(unit, config)
674674
return serialize_list([config])
675675

676+
@classmethod
677+
def custom_explicit_configs(cls, unit, flat_args, spec_args):
678+
# default global config only
679+
linter_name = spec_args['NAME'][0]
680+
default_configs_path = spec_args.get('CONFIGS')[0]
681+
assert_file_exists(unit, default_configs_path)
682+
config = get_linter_configs(unit, default_configs_path).get(linter_name)
683+
if not config:
684+
message = f"Default config in {default_configs_path} can't be found for a linter {linter_name}"
685+
raise DartValueError(message)
686+
assert_file_exists(unit, config)
687+
return serialize_list([config])
688+
676689

677690
class LintExtraParams:
678691
KEY = 'LINT-EXTRA-PARAMS'
@@ -1222,6 +1235,9 @@ class TestFiles:
12221235
'maps/b2bgeo/mvrp_solver/aws_docker',
12231236
)
12241237

1238+
# XXX: this is a temporarty fence allowing only taxi to use STYLE_JSON macro
1239+
_TAXI_JSON_PREFIX = 'taxi'
1240+
12251241
@classmethod
12261242
def value(cls, unit, flat_args, spec_args):
12271243
data_re = re.compile(r"sbr:/?/?(\d+)=?.*")
@@ -1339,6 +1355,31 @@ def cpp_linter_files(cls, unit, flat_args, spec_args):
13391355
files_dart = _reference_group_var("ALL_SRCS", consts.STYLE_CPP_ALL_EXTS)
13401356
return files_dart
13411357

1358+
@classmethod
1359+
def from_macro_args(cls, unit, flat_args, spec_args):
1360+
files = spec_args.get('FILES', [])
1361+
if not files:
1362+
raise HaltDartConstruction()
1363+
else:
1364+
upath = unit.path()[3:]
1365+
lint_name = spec_args['NAME'][0]
1366+
1367+
if lint_name == 'clang_format_json' and not upath.startswith(cls._TAXI_JSON_PREFIX):
1368+
raise DartValueError("Presently only projects in taxi/ are allowed with STYLE_JSON")
1369+
resolved_files = []
1370+
for path in files:
1371+
if path.endswith('ya.make'):
1372+
raise DartValueError("Can't have ya.make in collected files")
1373+
resolved = _common.resolve_common_const(path) # files can come from glob
1374+
if resolved.startswith(SOURCE_ROOT_SHORT):
1375+
resolved_files.append(resolved)
1376+
else:
1377+
resolved = unit.resolve_arc_path([path])
1378+
if resolved.startswith(SOURCE_ROOT_SHORT):
1379+
resolved_files.append(resolved)
1380+
test_files = serialize_list(resolved_files)
1381+
return test_files
1382+
13421383

13431384
class TestEnv:
13441385
KEY = 'TEST-ENV'

build/plugins/lib/test_const/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,14 @@ class CppLinterName(Enum):
463463
ClangFormat18Vanilla = "clang_format_18_vanilla"
464464

465465

466+
class CustomExplicitLinterName(Enum):
467+
ClangFormatJson = "clang_format_json"
468+
469+
466470
class DefaultLinterConfig(Enum):
467471
Cpp = "build/config/tests/cpp_style/default_configs.json"
468472
Python = "build/config/tests/py_style/default_configs.json"
473+
Json = "build/config/tests/json_style/default_configs.json"
469474

470475

471476
class LinterConfigsValidationRules(Enum):
@@ -479,13 +484,15 @@ class LinterConfigsValidationRules(Enum):
479484
PythonLinterName.Flake8: (('build/external_resources/flake8_py3', FLAKE8_PY3_RESOURCE),),
480485
PythonLinterName.Py2Flake8: (('build/external_resources/flake8_py2', FLAKE8_PY2_RESOURCE),),
481486
CppLinterName.ClangFormat: (('build/platform/clang/clang-format', CLANG_FORMAT_RESOURCE),),
487+
CustomExplicitLinterName.ClangFormatJson: (('build/platform/clang/clang-format', CLANG_FORMAT_RESOURCE),),
482488
}
483489

484490
# XXX: if a new linter is added to this mapping respective path to default config file must be available in the json
485491
LINTER_TO_DEFAULT_CONFIGS = {
486492
CppLinterName.ClangFormat: DefaultLinterConfig.Cpp,
487493
PythonLinterName.Black: DefaultLinterConfig.Python,
488494
PythonLinterName.Ruff: DefaultLinterConfig.Python,
495+
CustomExplicitLinterName.ClangFormatJson: DefaultLinterConfig.Json,
489496
}
490497

491498
# Fill up like
@@ -504,6 +511,7 @@ class LinterConfigsValidationRules(Enum):
504511
CppLinterName.ClangFormatYT: (".clang-format",),
505512
PythonLinterName.Black: ("pyproject.toml",),
506513
PythonLinterName.Ruff: ("pyproject.toml", "ruff.toml"),
514+
CustomExplicitLinterName.ClangFormatJson: (".clang-format",),
507515
}
508516

509517
AUTOINCLUDE_PATHS = (

build/plugins/ytest.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,6 +1119,44 @@ def on_add_py_linter_check(fields, unit, *args):
11191119
unit.set_property(["DART_DATA", data])
11201120

11211121

1122+
@df.with_fields(
1123+
(
1124+
df.TestFiles.from_macro_args,
1125+
df.LintConfigs.custom_explicit_configs,
1126+
)
1127+
+ LINTER_FIELDS_BASE
1128+
)
1129+
def on_add_json_explicit_linter_check(fields, unit, *args):
1130+
if unit.get("TIDY") == "yes":
1131+
return
1132+
no_lint_value = _common.get_no_lint_value(unit)
1133+
if no_lint_value in ("none", "none_internal"):
1134+
return
1135+
unlimited = -1
1136+
keywords = {
1137+
"NAME": 1,
1138+
"WRAPPER_SCRIPT": 1,
1139+
"FILES": unlimited,
1140+
"DEPENDS": unlimited,
1141+
"FILE_PROCESSING_TIME": 1,
1142+
"EXTRA_PARAMS": unlimited,
1143+
"CONFIGS": 1,
1144+
"GLOBAL_RESOURCES": unlimited,
1145+
}
1146+
_, spec_args = _common.sort_by_keywords(keywords, args)
1147+
name = spec_args['NAME'][0]
1148+
global_resources = consts.LINTER_TO_GLOBAL_RESOURCES.get(name, ())
1149+
for resource, _ in global_resources:
1150+
unit.onpeerdir(resource)
1151+
dart_record = create_dart_record(fields, unit, (), spec_args)
1152+
if not dart_record:
1153+
return
1154+
dart_record[df.ScriptRelPath.KEY] = 'custom_lint'
1155+
data = dump_test(unit, dart_record)
1156+
if data:
1157+
unit.set_property(["DART_DATA", data])
1158+
1159+
11221160
@df.with_fields(
11231161
YTEST_FIELDS_BASE
11241162
+ (

build/ymake.core.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ when ($LOCAL && $XCODE) {
9292
@import "${CONF_ROOT}/conf/proto.conf"
9393
@import "${CONF_ROOT}/conf/fbs.conf"
9494
@import "${CONF_ROOT}/conf/ts/ts.conf"
95+
@import "${CONF_ROOT}/conf/custom_lint.conf"
9596

9697
@import "${CONF_ROOT}/conf/project_specific/other.conf"
9798
@import "${CONF_ROOT}/conf/project_specific/yt.conf"

0 commit comments

Comments
 (0)