From a1da039ef66fd6448faff86ea53eecf3f946b1a2 Mon Sep 17 00:00:00 2001 From: segoon Date: Fri, 2 Aug 2024 20:11:56 +0300 Subject: [PATCH] feat c35: configs-variables 3f0c7868293ea4f2818bd62ab58e215e3aec8251 --- chaotic/chaotic/compilers/dynamic_config.py | 66 ++++++++++++++------- 1 file changed, 45 insertions(+), 21 deletions(-) diff --git a/chaotic/chaotic/compilers/dynamic_config.py b/chaotic/chaotic/compilers/dynamic_config.py index c42387295e22..913d3dd6b8d6 100644 --- a/chaotic/chaotic/compilers/dynamic_config.py +++ b/chaotic/chaotic/compilers/dynamic_config.py @@ -216,6 +216,27 @@ def _generate_types( ) return schemas, types + def variables_includes_hpp(self, name: str) -> List[str]: + types = self._variables_types[name] + includes: List[str] = [] + for type_ in types.values(): + includes += type_.declaration_includes() + + return sorted(set(includes)) + + def variables_includes_cpp(self, name: str) -> List[str]: + types = self._variables_types[name] + includes: List[str] = [] + for type_ in types.values(): + includes += type_.definition_includes() + return sorted(set(includes)) + + def variables_external_includes_hpp(self, name: str) -> List[str]: + types = self._variables_types[name] + return self.renderer_for_variable( + name, False, + ).extract_external_includes(types, '') + def _read_default(self, filepath: str) -> Any: with open(filepath, 'r') as ifile: content = yaml.load(ifile, Loader=yaml.CLoader) @@ -229,32 +250,35 @@ def create_aliases( ) -> List[Tuple[str, str]]: return [] + def renderer_for_variable( + self, name: str, parse_extra_formats: bool, + ) -> renderer.OneToOneFileRenderer: + return renderer.OneToOneFileRenderer( + relative_to='/', + vfilepath_to_relfilepath={ + name: f'taxi_config/variables/{name}.types.hpp', + **{ + name: ( + 'taxi_config/definitions/' + f'{name.split(".")[0].replace("/", "_")}.hpp' + ) + for name in self._definitions + }, + }, + clang_format_bin=get_clang_format_bin(), + parse_extra_formats=parse_extra_formats, + generate_serializer=parse_extra_formats, + ) + # TODO: move jinja files to arcadia_compiler def generate_variable( self, name: str, output_dir: str, parse_extra_formats: bool, ) -> None: types = self._variables_types[name] - outputs = ( - renderer.OneToOneFileRenderer( - relative_to='/', - vfilepath_to_relfilepath={ - name: f'taxi_config/variables/{name}.types.hpp', - **{ - name: ( - 'taxi_config/definitions/' - f'{name.split(".")[0].replace("/", "_")}.hpp' - ) - for name in self._definitions - }, - }, - clang_format_bin=get_clang_format_bin(), - parse_extra_formats=parse_extra_formats, - generate_serializer=parse_extra_formats, - ).render( - types, - local_pair_header=False, - # pair_header=f'taxi_config/variables/{name}.types.hpp', - ) + outputs = self.renderer_for_variable(name, parse_extra_formats).render( + types, + local_pair_header=False, + # pair_header=f'taxi_config/variables/{name}.types.hpp', ) name_lower = self.format_ns_name(name)