diff options
author | denisk <denisk@yandex-team.ru> | 2022-02-10 16:48:13 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:13 +0300 |
commit | a02ea31d51f94b7edb98c6ab1322bf26ca04beb5 (patch) | |
tree | b222e5ac2e2e98872661c51ccceee5da0d291e13 /build/plugins | |
parent | a3e40d22cc86312046f69a10ea401b78e9efb746 (diff) | |
download | ydb-a02ea31d51f94b7edb98c6ab1322bf26ca04beb5.tar.gz |
Restoring authorship annotation for <denisk@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'build/plugins')
-rw-r--r-- | build/plugins/code_generator.py | 84 | ||||
-rw-r--r-- | build/plugins/tests/test_code_generator.py | 32 | ||||
-rw-r--r-- | build/plugins/tests/ya.make | 2 | ||||
-rw-r--r-- | build/plugins/ya.make | 2 |
4 files changed, 60 insertions, 60 deletions
diff --git a/build/plugins/code_generator.py b/build/plugins/code_generator.py index 0e876c21f7..ca8bb18c15 100644 --- a/build/plugins/code_generator.py +++ b/build/plugins/code_generator.py @@ -1,45 +1,45 @@ -import re -import os - -import _import_wrapper as iw - +import re +import os + +import _import_wrapper as iw + pattern = re.compile(r"#include\s*[<\"](?P<INDUCED>[^>\"]+)[>\"]|(?:@|{@)\s*(?:import|include|from)\s*[\"'](?P<INCLUDE>[^\"']+)[\"']") - - -class CodeGeneratorTemplateParser(object): - def __init__(self, path, unit): - self._path = path + + +class CodeGeneratorTemplateParser(object): + def __init__(self, path, unit): + self._path = path retargeted = os.path.join(unit.path(), os.path.relpath(path, unit.resolve(unit.path()))) - with open(path, 'rb') as f: - includes, induced = CodeGeneratorTemplateParser.parse_includes(f.readlines()) - self._includes = unit.resolve_include([retargeted] + includes) if includes else [] - self._induced = unit.resolve_include([retargeted] + induced) if induced else [] - - @staticmethod - def parse_includes(lines): - includes = [] - induced = [] - - for line in lines: - for match in pattern.finditer(line): - type = match.lastgroup - if type == 'INCLUDE': - includes.append(match.group(type)) - elif type == 'INDUCED': - induced.append(match.group(type)) - else: - raise Exception("Unexpected match! Perhaps it is a result of an error in pattern.") - return (includes, induced) - - def includes(self): - return self._includes - - def induced_deps(self): - return { - 'h+cpp': self._induced - } - - -def init(): + with open(path, 'rb') as f: + includes, induced = CodeGeneratorTemplateParser.parse_includes(f.readlines()) + self._includes = unit.resolve_include([retargeted] + includes) if includes else [] + self._induced = unit.resolve_include([retargeted] + induced) if induced else [] + + @staticmethod + def parse_includes(lines): + includes = [] + induced = [] + + for line in lines: + for match in pattern.finditer(line): + type = match.lastgroup + if type == 'INCLUDE': + includes.append(match.group(type)) + elif type == 'INDUCED': + induced.append(match.group(type)) + else: + raise Exception("Unexpected match! Perhaps it is a result of an error in pattern.") + return (includes, induced) + + def includes(self): + return self._includes + + def induced_deps(self): + return { + 'h+cpp': self._induced + } + + +def init(): iw.addparser('markettemplate', CodeGeneratorTemplateParser) - iw.addparser('macro', CodeGeneratorTemplateParser) + iw.addparser('macro', CodeGeneratorTemplateParser) diff --git a/build/plugins/tests/test_code_generator.py b/build/plugins/tests/test_code_generator.py index b9ef68bc0f..a675d9068c 100644 --- a/build/plugins/tests/test_code_generator.py +++ b/build/plugins/tests/test_code_generator.py @@ -1,16 +1,16 @@ -from build.plugins import code_generator - - -def test_include_parser(): - template_file = """ - @ from 'util/namespace.macro' import namespace, change_namespace, close_namespaces - @ import 'market/tools/code_generator/templates/serialization/json.macro' as json - @ import 'market/tools/code_generator/templates/serialization/request_parameters.macro' as rp - #include <sss/abcdefg.h> - #include<fff/asd> - #include "hhh/quququ.h" - """ - - includes, induced = code_generator.CodeGeneratorTemplateParser.parse_includes(template_file.split('\n')) - assert includes == ['util/namespace.macro', 'market/tools/code_generator/templates/serialization/json.macro', 'market/tools/code_generator/templates/serialization/request_parameters.macro'] - assert induced == ['sss/abcdefg.h', 'fff/asd', 'hhh/quququ.h'] +from build.plugins import code_generator + + +def test_include_parser(): + template_file = """ + @ from 'util/namespace.macro' import namespace, change_namespace, close_namespaces + @ import 'market/tools/code_generator/templates/serialization/json.macro' as json + @ import 'market/tools/code_generator/templates/serialization/request_parameters.macro' as rp + #include <sss/abcdefg.h> + #include<fff/asd> + #include "hhh/quququ.h" + """ + + includes, induced = code_generator.CodeGeneratorTemplateParser.parse_includes(template_file.split('\n')) + assert includes == ['util/namespace.macro', 'market/tools/code_generator/templates/serialization/json.macro', 'market/tools/code_generator/templates/serialization/request_parameters.macro'] + assert induced == ['sss/abcdefg.h', 'fff/asd', 'hhh/quququ.h'] diff --git a/build/plugins/tests/ya.make b/build/plugins/tests/ya.make index 856b7ceb9a..87228b98df 100644 --- a/build/plugins/tests/ya.make +++ b/build/plugins/tests/ya.make @@ -7,7 +7,7 @@ PEERDIR( ) TEST_SRCS( - test_code_generator.py + test_code_generator.py test_common.py test_requirements.py test_ssqls.py diff --git a/build/plugins/ya.make b/build/plugins/ya.make index 06e94b9c92..4ad5f5988e 100644 --- a/build/plugins/ya.make +++ b/build/plugins/ya.make @@ -3,7 +3,7 @@ OWNER(g:ymake) PY2_LIBRARY() PY_SRCS( - code_generator.py + code_generator.py ssqls.py swig.py |