diff options
author | dimdim11 <dimdim11@yandex-team.com> | 2024-04-23 06:00:00 +0300 |
---|---|---|
committer | dimdim11 <dimdim11@yandex-team.com> | 2024-04-23 06:17:10 +0300 |
commit | c76106c22d7e333b13710b30d4ae3205d123bfef (patch) | |
tree | 443865ecd0f4b7bb7f20b895f0f0d5fad06fd896 /build | |
parent | fd41af07c937014fe317735d72e86df25604812c (diff) | |
download | ydb-c76106c22d7e333b13710b30d4ae3205d123bfef.tar.gz |
Remove final in cpp pb.h/cc by outputs list
Remove final in cpp pb.h/cc by outputs list
1307ef1d33bab92f478e7a4d213c08bf6691ebd5
Diffstat (limited to 'build')
-rw-r--r-- | build/conf/proto.conf | 12 | ||||
-rw-r--r-- | build/scripts/cpp_proto_wrapper.py | 43 | ||||
-rw-r--r-- | build/ymake.core.conf | 11 |
3 files changed, 56 insertions, 10 deletions
diff --git a/build/conf/proto.conf b/build/conf/proto.conf index 82f9ca5851..7c16a5cb7a 100644 --- a/build/conf/proto.conf +++ b/build/conf/proto.conf @@ -208,7 +208,7 @@ macro WITH_KOTLIN_GRPC() { # tag:proto tag:cpp-specific macro _ADD_CPP_PROTO_OUT(Suf) { .SEM=append_target_property PROTOC_EXTRA_OUTS $Suf ${output;hide;suf=.o:Suf} $_ADD_SEM_PROP_IF_NON_EMPTY(PROTO_NAMESPACE $PROTO_NAMESPACE) - SET_APPEND(CPP_PROTO_OUTS \${output;hide;norel;nopath;noext;suf=$Suf:File}) + SET_APPEND(CPP_PROTO_OUTS \${output;norel;nopath;noext;suf=$Suf:File}) # XXX fix variable expansion in plugins SET(CPP_PROTO_SUFFIXES $CPP_PROTO_SUFFIXES $Suf) @@ -390,14 +390,14 @@ _SEM_CPP_PROTO_CMD=target_proto_messages PRIVATE ${input:File} $CPP_PROTO_OUTS_S # tag:proto macro _CPP_PROTO_CMD(File) { - .CMD=$CPP_PROTO_CMDLINE $CPP_PROTO_OPTS $CPP_PROTO_OUTS ${kv;hide:"p PB"} ${kv;hide:"pc yellow"} + .CMD=$CPP_PROTO_CMDLINE $CPP_PROTO_OPTS ${kv;hide:"p PB"} ${kv;hide:"pc yellow"} .SEM=$_SEM_CPP_PROTO_CMD .PEERDIR=contrib/libs/protobuf } # tag:proto macro _CPP_VANILLA_PROTO_CMD(File) { - .CMD=$CPP_PROTO_CMDLINE $CPP_PROTO_OPTS $CPP_PROTO_OUTS ${kv;hide:"p PB"} ${kv;hide:"pc yellow"} + .CMD=$CPP_PROTO_CMDLINE $CPP_PROTO_OPTS ${kv;hide:"p PB"} ${kv;hide:"pc yellow"} .PEERDIR=contrib/libs/protobuf_std } @@ -408,7 +408,7 @@ _SEM_CPP_EV_CMD=target_ev_messages PRIVATE ${input:File} $CPP_EV_OUTS_SEM ${outp # tag:proto macro _CPP_EVLOG_CMD(File) { - .CMD=$CPP_PROTO_CMDLINE $CPP_EV_OPTS $CPP_EV_OUTS ${kv;hide:"p EV"} ${kv;hide:"pc yellow"} + .CMD=$CPP_EV_CMDLINE $CPP_EV_OPTS ${kv;hide:"p EV"} ${kv;hide:"pc yellow"} .SEM=$_SEM_CPP_EV_CMD .PEERDIR=library/cpp/eventlog contrib/libs/protobuf } @@ -416,14 +416,14 @@ macro _CPP_EVLOG_CMD(File) { # tag:proto macro _CPP_PROTO_EVLOG_CMD(File) { # process .proto as .ev - .CMD=$CPP_PROTO_CMDLINE $CPP_EV_OPTS $CPP_PROTO_OUTS ${kv;hide:"p PB"} ${kv;hide:"pc yellow"} + .CMD=$CPP_PROTO_CMDLINE $CPP_EV_OPTS ${kv;hide:"p PB"} ${kv;hide:"pc yellow"} .PEERDIR=library/cpp/eventlog contrib/libs/protobuf } # tag:proto macro _CPP_CFGPROTO_CMD(File) { # keep extension in output just as in EV: this is hard-coded behaviour of protoc for non-.proto extensions - .CMD=$CPP_PROTO_CMDLINE --plugin=protoc-gen-config=${tool:"library/cpp/proto_config/plugin"} --config_out=$ARCADIA_BUILD_ROOT/$PROTO_NAMESPACE $CPP_EV_OUTS ${kv;hide:"p PB"} ${kv;hide:"pc yellow"} + .CMD=$CPP_EV_CMDLINE --plugin=protoc-gen-config=${tool:"library/cpp/proto_config/plugin"} --config_out=$ARCADIA_BUILD_ROOT/$PROTO_NAMESPACE ${kv;hide:"p PB"} ${kv;hide:"pc yellow"} .PEERDIR=library/cpp/proto_config/codegen library/cpp/proto_config/protos contrib/libs/protobuf } diff --git a/build/scripts/cpp_proto_wrapper.py b/build/scripts/cpp_proto_wrapper.py new file mode 100644 index 0000000000..8cc4ccc1be --- /dev/null +++ b/build/scripts/cpp_proto_wrapper.py @@ -0,0 +1,43 @@ +import sys +import os +import subprocess +import re +import argparse + + +FROM_RE = re.compile("((?:struct|class)\s+\S+\s+)final\s*:") +TO_RE = "\\1:" + + +def parse_args() -> argparse.Namespace: + parser = argparse.ArgumentParser() + parser.add_argument('--outputs', nargs='+', required=True) + parser.add_argument('subcommand', nargs='+') + return parser.parse_args() + + +def patch_proto_file(text: str) -> tuple[str, int]: + return re.subn(FROM_RE, TO_RE, text) + + +def main(namespace: argparse.Namespace) -> int: + try: + subprocess.check_output(namespace.subcommand, stdin=None, stderr=subprocess.STDOUT) + 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')) + ) + return e.returncode + + for output in namespace.outputs: + with open(output, 'r') as f: + patched_text, num_patches = patch_proto_file(f.read()) + if num_patches: + with open(output, 'w') as f: + f.write(patched_text) + + return 0 + + +if __name__ == '__main__': + sys.exit(main(parse_args())) diff --git a/build/ymake.core.conf b/build/ymake.core.conf index 025d3ae1f9..133c9f7eca 100644 --- a/build/ymake.core.conf +++ b/build/ymake.core.conf @@ -594,10 +594,13 @@ module _BASE_UNIT: _BARE_UNIT { PEERDIR_TAGS=CPP_PROTO CPP_FBS CPP_ROS H_IDL PY2 PY2_NATIVE YQL_UDF_STATIC __EMPTY__ RESOURCE_LIB DLL_LIB - CPP_PROTO_CMDLINE=${cwd;rootdir;input:File} $PROTOC -I=./$PROTO_NAMESPACE -I=$ARCADIA_ROOT/$PROTO_NAMESPACE ${pre=-I=:_PROTO__INCLUDE} -I=$ARCADIA_BUILD_ROOT -I=$PROTOBUF_PATH --cpp_out=${CPP_PROTO_PLUGINS}$ARCADIA_BUILD_ROOT/$PROTO_NAMESPACE $_PROTOC_FLAGS $PROTOC_STYLEGUIDE_OUT $PROTOC_PLUGIN_STYLEGUIDE ${input;rootrel:File} ${hide:PROTO_FAKEID} - CPP_PROTO_OUTS+=${hide;output;norel;nopath;noext:File.pb.cc} ${output;main;hide;norel;nopath;noext:File.pb.h} + _CPP_PROTO_WRAPPER_BASE=$YMAKE_PYTHON3 ${input:"build/scripts/cpp_proto_wrapper.py"} + _CPP_PROTO_CMDLINE_BASE=${cwd;rootdir;input:File} $PROTOC -I=./$PROTO_NAMESPACE -I=$ARCADIA_ROOT/$PROTO_NAMESPACE ${pre=-I=:_PROTO__INCLUDE} -I=$ARCADIA_BUILD_ROOT -I=$PROTOBUF_PATH --cpp_out=${CPP_PROTO_PLUGINS}$ARCADIA_BUILD_ROOT/$PROTO_NAMESPACE $_PROTOC_FLAGS $PROTOC_STYLEGUIDE_OUT $PROTOC_PLUGIN_STYLEGUIDE ${hide:PROTO_FAKEID} ${input;rootrel:File} + CPP_PROTO_CMDLINE=$_CPP_PROTO_WRAPPER_BASE --outputs $CPP_PROTO_OUTS -- $_CPP_PROTO_CMDLINE_BASE + CPP_PROTO_OUTS+=${output;norel;nopath;noext:File.pb.cc} ${output;main;norel;nopath;noext:File.pb.h} CPP_PROTO_OUTS_SEM+=${output;main;hide;norel;nopath;noext:File.pb.h} - CPP_EV_OUTS+=${hide;output;norel:File.pb.cc} ${hide;output;norel:File.pb.h} + CPP_EV_CMDLINE=$_CPP_PROTO_WRAPPER_BASE --outputs $CPP_EV_OUTS -- $_CPP_PROTO_CMDLINE_BASE + CPP_EV_OUTS+=${output;norel:File.pb.cc} ${output;norel:File.pb.h} CPP_EV_OUTS_SEM+=${hide;output;norel:File.pb.h} when ($SWIG_LANG == "perl") { @@ -639,7 +642,7 @@ module _BASE_UNIT: _BARE_UNIT { } when ($PROTOC_TRANSITIVE_HEADERS == "no") { CPP_PROTO_PLUGINS=transitive_pb_h=false:${CPP_PROTO_PLUGINS} - CPP_PROTO_OUTS+=${output;main;hide;norel;nopath;noext:File.deps.pb.h} + CPP_PROTO_OUTS+=${output;main;norel;nopath;noext:File.deps.pb.h} } } |