diff options
author | nechda <nechda@yandex-team.com> | 2024-09-10 22:57:12 +0300 |
---|---|---|
committer | nechda <nechda@yandex-team.com> | 2024-09-10 23:11:56 +0300 |
commit | d6722c76399d9b6813119aed315a69529f8d2193 (patch) | |
tree | eb58a502fb2cfe375bed4e27a43d5d3b976122e0 | |
parent | b949747c779320edae2654274dbffc7d17539717 (diff) | |
download | ydb-d6722c76399d9b6813119aed315a69529f8d2193.tar.gz |
Fix transitive includes
94b36f1500126afc596f281469a94124efa9cda4
5 files changed, 70 insertions, 20 deletions
diff --git a/build/prebuilt/contrib/tools/protoc/plugins/cpp_styleguide/resources.json b/build/prebuilt/contrib/tools/protoc/plugins/cpp_styleguide/resources.json index 11afd79c76..5d58384e1f 100644 --- a/build/prebuilt/contrib/tools/protoc/plugins/cpp_styleguide/resources.json +++ b/build/prebuilt/contrib/tools/protoc/plugins/cpp_styleguide/resources.json @@ -1,16 +1,16 @@ { "by_platform": { - "darwin-arm64": { - "uri": "sbr:3519867173" + "darwin": { + "uri": "sbr:7041923114" }, - "darwin-x86_64": { - "uri": "sbr:3519867173" + "darwin-arm64": { + "uri": "sbr:7041925436" }, - "linux-x86_64": { - "uri": "sbr:3519867841" + "linux": { + "uri": "sbr:7041926554" }, - "win32-x86_64": { - "uri": "sbr:3519866587" + "win32": { + "uri": "sbr:7041924289" } } -}
\ No newline at end of file +} diff --git a/build/scripts/cpp_proto_wrapper.py b/build/scripts/cpp_proto_wrapper.py index c29ca53a1d..33806bafae 100644 --- a/build/scripts/cpp_proto_wrapper.py +++ b/build/scripts/cpp_proto_wrapper.py @@ -3,7 +3,7 @@ import os import subprocess import re import argparse - +import shutil FROM_RE = re.compile(r"((?:struct|class)\s+\S+\s+)final\s*:") TO_RE = r"\1:" @@ -17,18 +17,67 @@ def parse_args() -> argparse.Namespace: def patch_proto_file(text: str) -> tuple[str, int]: - return re.subn(FROM_RE, TO_RE, text) + num_patches = 0 + patches = [ + (re.compile(r"((?:struct|class)\s+\S+\s+)final\s*:"), r"\1:"), + (re.compile(r'(#include.*?)(\.proto\.h)"'), r'\1.pb.h"') + ] + for from_re, to_re in patches: + text, n = re.subn(from_re, to_re, text) + num_patches += n + return text, num_patches + + +def strip_file_ext(path: str) -> str: + dirname, filename = os.path.dirname(path), os.path.basename(path) + filename = filename.split('.')[0] + return os.path.join(dirname, filename) + + +def change_file_ext(path: str, change_map: dict[str, str]) -> str: + dirname, filename = os.path.dirname(path), os.path.basename(path) + filename = filename.split('.') + filename, ext = filename[0], '.' + '.'.join(filename[1:]) + if not change_map.get(ext): + return + new_ext = change_map[ext] + old = os.path.join(dirname, filename + ext) + new = os.path.join(dirname, filename + new_ext) + shutil.move(old, new) + return new def main(namespace: argparse.Namespace) -> int: + lite_protobuf_headers = any(out.endswith('.deps.pb.h') for out in namespace.outputs) + ev_proto = any(out.endswith('.ev.pb.h') for out in namespace.outputs) + if ev_proto: + pattern = re.compile(r'proto_h=true:') + disable_lite_headers = lambda s: re.sub(pattern, '', s) + namespace.subcommand = [disable_lite_headers(argv) for argv in namespace.subcommand] try: - subprocess.check_output(namespace.subcommand, stdin=None, stderr=subprocess.STDOUT) + env = os.environ.copy() + if lite_protobuf_headers: + env['PROTOC_PLUGINS_LITE_HEADERS']='1' + subprocess.check_output(namespace.subcommand, stdin=None, stderr=subprocess.STDOUT, env=env) except subprocess.CalledProcessError as e: sys.stderr.write( '{} returned non-zero exit code {}.\n{}\n'.format(' '.join(e.cmd), e.returncode, e.output.decode('utf-8', errors='ignore')) ) return e.returncode + if lite_protobuf_headers: + paths = [strip_file_ext(out) for out in namespace.outputs if out.endswith('.deps.pb.h')] + proto_h_files = [out + '.proto.h' for out in paths] + pb_h_files = [out + '.pb.h' for out in paths] + + change_map = { + '.proto.h': '.pb.h', + '.pb.h': '.deps.pb.h', + } + [change_file_ext(out, change_map) for out in pb_h_files] + [change_file_ext(out, change_map) for out in proto_h_files] + + for output in namespace.outputs: with open(output, 'rt', encoding="utf-8") as f: patched_text, num_patches = patch_proto_file(f.read()) diff --git a/build/ymake.core.conf b/build/ymake.core.conf index 91e985344c..059aa790be 100644 --- a/build/ymake.core.conf +++ b/build/ymake.core.conf @@ -626,10 +626,10 @@ module _BASE_UNIT: _BARE_UNIT { PROTOBUF_INCLUDE_PATH=${ARCADIA_ROOT}/contrib/libs/protobuf_std/src _PROTO_CMDLINE=$_CPP_VANILLA_PROTO_CMDLINE } - #when ($PROTOC_TRANSITIVE_HEADERS == "no") { - # CPP_PROTO_PLUGINS=transitive_pb_h=false:${CPP_PROTO_PLUGINS} - # CPP_PROTO_OUTS+=${output;main;norel;nopath;noext:File.deps.pb.h} - #} + when ($PROTOC_TRANSITIVE_HEADERS == "no") { + CPP_PROTO_PLUGINS=proto_h=true:${CPP_PROTO_PLUGINS} + CPP_PROTO_OUTS+=${output;main;norel;nopath;noext:File.deps.pb.h} + } } SANITIZER_DEFINED=no diff --git a/contrib/libs/protoc/src/google/protobuf/compiler/cpp/file.cc b/contrib/libs/protoc/src/google/protobuf/compiler/cpp/file.cc index bb024eb59f..68be3e5670 100644 --- a/contrib/libs/protoc/src/google/protobuf/compiler/cpp/file.cc +++ b/contrib/libs/protoc/src/google/protobuf/compiler/cpp/file.cc @@ -285,7 +285,7 @@ void FileGenerator::GenerateProtoHeader(io::Printer* p, } if (IsBootstrapProto(options_, file_)) { p->Emit({{"name", StripProto(file_->name())}}, R"cc( - // IWYU pragma: private, include "$name$.proto.h" + // IWYU pragma: private, include "$name$.pb.h" )cc"); } @@ -297,7 +297,7 @@ void FileGenerator::GenerateProtoHeader(io::Printer* p, for (int i = 0; i < file_->public_dependency_count(); ++i) { const FileDescriptor* dep = file_->public_dependency(i); p->Emit({{"name", StripProto(dep->name())}}, R"( - #include "$name$.proto.h" + #)" R"(include "$name$.pb.h" )"); } }}, @@ -485,7 +485,7 @@ void FileGenerator::GenerateSourceIncludes(io::Printer* p) { GetBootstrapBasename(options_, basename, &basename); } p->Emit({{"name", basename}}, R"( - #include "$name$.proto.h" + #)" R"(include "$name$.pb.h" )"); } } diff --git a/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp b/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp index c6a633a811..900ec3d64f 100644 --- a/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp +++ b/contrib/tools/protoc/plugins/cpp_styleguide/cpp_styleguide.cpp @@ -40,7 +40,8 @@ namespace NPlugins { TProtoStringType HeaderFileName(const FileDescriptor* file) { TProtoStringType basename = compiler::StripProto(file->name()); - return basename.append(".pb.h"); + bool use_proto_h = !!getenv("PROTOC_PLUGINS_LITE_HEADERS"); + return use_proto_h ? basename.append(".proto.h") : basename.append(".pb.h"); } TProtoStringType SourceFileName(const FileDescriptor* file) { |