Browse Source

Lookup CPP custom linter configs

Lookup custom linter config
commit_hash:43ad16d363652673970beb4e755b5e045618607e
alevitskii 3 months ago
parent
commit
b0c2229a8d

+ 29 - 7
build/plugins/_dart_fields.py

@@ -611,15 +611,37 @@ class LintConfigs:
     def cpp_configs(cls, unit, flat_args, spec_args):
         custom_config = spec_args.get('CUSTOM_CONFIG')
         if custom_config:
+            # TODO delete CUSTOM_CONFIG, it's used only by arc
             config = custom_config[0]
             assert_file_exists(unit, config)
-        else:
-            # file with default configs
-            config = spec_args.get('CONFIGS')[0]
-            assert_file_exists(unit, config)
-            name = spec_args['NAME'][0]
-            config = get_linter_configs(unit, config)[name]
-            assert_file_exists(unit, config)
+            return {cls.KEY: serialize_list([config])}
+        linter_name = spec_args['NAME'][0]
+        if config_type := spec_args.get('CONFIG_TYPE'):
+            config_type = config_type[0]
+            if config_type not in consts.LINTER_CONFIG_TYPES[linter_name]:
+                message = "Unknown CPP linter config type: {}. Allowed types: {}".format(
+                    config_type, ', '.join(consts.LINTER_CONFIG_TYPES[linter_name])
+                )
+                ymake.report_configure_error(message)
+                raise DartValueError()
+            if common_configs_dir := unit.get('MODULE_COMMON_CONFIGS_DIR'):
+                config = os.path.join(common_configs_dir, config_type)
+                path = unit.resolve(config)
+                if os.path.exists(path):
+                    config = _common.strip_roots(config)
+                    return {cls.KEY: serialize_list([config])}
+                message = "File not found: {}".format(path)
+                ymake.report_configure_error(message)
+                raise DartValueError()
+            else:
+                message = "Config type specifier is only allowed with autoincludes"
+                ymake.report_configure_error(message)
+                raise DartValueError()
+        # default config
+        config = spec_args.get('CONFIGS')[0]
+        assert_file_exists(unit, config)
+        config = get_linter_configs(unit, config)[linter_name]
+        assert_file_exists(unit, config)
         return {cls.KEY: serialize_list([config])}
 
 

+ 1 - 0
build/plugins/lib/test_const/__init__.py

@@ -437,6 +437,7 @@ class ServiceTags(Enum):
     AnyTag = "ya:anytag"
 
 
+# Linter names must match `NAME` set in `_ADD_*_LINTER_CHECK`
 class PythonLinterName(Enum):
     Black = "black"
     DummyLinter = "dummy_linter"

+ 1 - 0
build/plugins/ytest.py

@@ -1014,6 +1014,7 @@ def on_add_cpp_linter_check(fields, unit, *args):
         "GLOBAL_RESOURCES": unlimited,
         "FILE_PROCESSING_TIME": 1,
         "EXTRA_PARAMS": unlimited,
+        "CONFIG_TYPE": 1,
     }
     _, spec_args = _common.sort_by_keywords(keywords, args)
 

+ 4 - 4
build/ymake.core.conf

@@ -5854,7 +5854,7 @@ macro _STYLE_CPP(CONFIG...) {
 }
 
 # tag:internal
-### @usage: _ADD_CPP_LINTER_CHECK(NAME name LINTER linter [DEPENDS deps] CONFIGS configs_file [GLOBAL_RESOURCES gr] [FILE_PROCESSING_TIME fpt] [EXTRA_PARAMS params] [CUSTOM_CONFIG cc])
+### @usage: _ADD_CPP_LINTER_CHECK(NAME name LINTER linter [DEPENDS deps] CONFIGS configs_file [GLOBAL_RESOURCES gr] [FILE_PROCESSING_TIME fpt] [EXTRA_PARAMS params] [CUSTOM_CONFIG cc] [CONFIG_TYPE ct])
 ###
 ### Triggers respective plugin
 macro _ADD_CPP_LINTER_CHECK(Args...) {
@@ -5864,12 +5864,12 @@ macro _ADD_CPP_LINTER_CHECK(Args...) {
 }
 
 # tag:test
-### @usage STYLE_CPP()
+### @usage STYLE_CPP([CONFIG_TYPE config_type])
 ###
 ### Run 'ya tool clang-format' test on all cpp sources and headers of the current module
-macro STYLE_CPP() {
+macro STYLE_CPP(CONFIG_TYPE="") {
     .ALLOWED_IN_COMMON=yes
-    _ADD_CPP_LINTER_CHECK(NAME clang_format LINTER tools/cpp_style_checker/cpp_style_checker GLOBAL_RESOURCES build/platform/clang/clang-format CONFIGS $CPP_LINTERS_DEFAULT_CONFIGS)
+    _ADD_CPP_LINTER_CHECK(NAME clang_format LINTER tools/cpp_style_checker/cpp_style_checker GLOBAL_RESOURCES build/platform/clang/clang-format CONFIGS $CPP_LINTERS_DEFAULT_CONFIGS CONFIG_TYPE $CONFIG_TYPE)
 }
 
 ### @usage: HEADERS(<Dirs...> [EXCLUDE patterns...])