Browse Source

py2/py3
480434cd022569bd885a5446b39f15db14f8a6fe

snermolaev 11 months ago
parent
commit
96aeada1ca
4 changed files with 16 additions and 10 deletions
  1. 4 4
      build/conf/proto.conf
  2. 7 2
      build/conf/python.conf
  3. 3 3
      build/plugins/pybuild.py
  4. 2 1
      build/scripts/gen_py_protos.py

+ 4 - 4
build/conf/proto.conf

@@ -20,7 +20,7 @@ BUILD_PROTO_AS_EVLOG=no
 PROTO_NAMESPACE=
 
 # tag:proto tag:python-specific
-GEN_PY_PROTOS=$YMAKE_PYTHON ${input:"build/scripts/gen_py_protos.py"}
+GEN_PY_PROTOS=$YMAKE_PYTHON ${input:"build/scripts/gen_py_protos.py"} --py_ver ${_PYTHON_VER}
 
 # tag:proto tag:cpp-specific
 PROTO_HEADER_EXTS=.pb.h
@@ -136,7 +136,7 @@ macro _PROTO_PLUGIN_ARGS_BASE(Name, Tool, OutParm...) {
 # tag:proto tag:python-specific
 macro _ADD_PY_PROTO_OUT(Suf) {
     SET_APPEND(PY_PROTO_OUTS \${output;hide;noauto;norel;nopath;noext;suf=$Suf:File})
-    SET_APPEND(PY_PROTO_OUTS_INTERNAL \${output;hide;noauto;norel;nopath;noext;suf=__int__$Suf:File} \${hide;kv:"ext_out_name_for_\${nopath;noext;suf=__int__$Suf:File} \${nopath;noext;suf=$Suf:File}"})
+    SET_APPEND(PY_PROTO_OUTS_INTERNAL \${output;hide;noauto;norel;nopath;noext;suf=__int${_PYTHON_VER}__$Suf:File} \${hide;kv:"ext_out_name_for_\${nopath;noext;suf=__int${_PYTHON_VER}__$Suf:File} \${nopath;noext;suf=$Suf:File}"})
     # XXX fix variable expansion in plugins
     SET(PY_PROTO_SUFFIXES $PY_PROTO_SUFFIXES $Suf)
 }
@@ -441,7 +441,7 @@ macro _PY_PROTO_CMD(File) {
 
 # tag:proto tag:python-specific
 macro _PY_PROTO_CMD_INTERNAL(File) {
-    .CMD=${cwd;rootdir;input:File} $GEN_PY_PROTOS --suffixes $PY_PROTO_SUFFIXES $PY_PROTO_MYPY_SUFFIX --input ${input;rootrel:File} --ns /$PROTO_NAMESPACE -- $_PY_PROTO_CMD_BASE($File __int___pb2.py $PY_PROTO_OPTS $PY_PROTO_OUTS_INTERNAL ${hide;kv:"ext_out_name_for_${nopath;noext;suf=__int___pb2.py:File} ${nopath;noext;suf=_pb2.py:File}"} $PY_PROTO_MYPY_PLUGIN_INTERNAL)
+    .CMD=${cwd;rootdir;input:File} $GEN_PY_PROTOS --suffixes $PY_PROTO_SUFFIXES $PY_PROTO_MYPY_SUFFIX --input ${input;rootrel:File} --ns /$PROTO_NAMESPACE -- $_PY_PROTO_CMD_BASE($File __int${_PYTHON_VER}___pb2.py $PY_PROTO_OPTS $PY_PROTO_OUTS_INTERNAL ${hide;kv:"ext_out_name_for_${nopath;noext;suf=__int${_PYTHON_VER}___pb2.py:File} ${nopath;noext;suf=_pb2.py:File}"} $PY_PROTO_MYPY_PLUGIN_INTERNAL)
 }
 
 # tag:proto tag:java-specific
@@ -512,7 +512,7 @@ macro _PY_EVLOG_CMD(File) {
 
 # tag:python-specific tag:proto
 macro _PY_EVLOG_CMD_INTERNAL(File) {
-    .CMD=${cwd;rootdir;input:File} $GEN_PY_PROTOS --suffixes $PY_EVLOG_SUFFIXES --input ${input;rootrel:File} --ns /$PROTO_NAMESPACE -- $_PY_EVLOG_CMD_BASE($File __int___ev_pb2.py ${hide;kv:"ext_out_name_for_${nopath;noext;suf=__int___ev_pb2.py:File} ${nopath;noext;suf=_ev_pb2.py:File}"})
+    .CMD=${cwd;rootdir;input:File} $GEN_PY_PROTOS --suffixes $PY_EVLOG_SUFFIXES --input ${input;rootrel:File} --ns /$PROTO_NAMESPACE -- $_PY_EVLOG_CMD_BASE($File __int${_PYTHON_VER}___ev_pb2.py ${hide;kv:"ext_out_name_for_${nopath;noext;suf=__int${_PYTHON_VER}___ev_pb2.py:File} ${nopath;noext;suf=_ev_pb2.py:File}"})
 }
 
 # tag:java-specific tag:proto

+ 7 - 2
build/conf/python.conf

@@ -144,6 +144,9 @@ when ($OPENSOURCE) {
 PYTHON2=no
 PYTHON3=no
 
+# tag:python-specific
+_PYTHON_VER=py2
+
 # tag:python-specific
 PYTHON_IMPORT_TRACING=yes
 
@@ -545,7 +548,7 @@ module PY2_LIBRARY: _LIBRARY {
     when ($PY_PROTO_MYPY_ENABLED == "yes") {
         PY_PROTO_MYPY_SUFFIX=_pb2.pyi
         PY_PROTO_MYPY_PLUGIN=$PY_PROTO_MYPY_PLUGIN_BASE ${output;hide;noauto;norel;nopath;noext;suf=_pb2.pyi:File}
-        PY_PROTO_MYPY_PLUGIN_INTERNAL=$PY_PROTO_MYPY_PLUGIN_BASE ${output;hide;noauto;norel;nopath;noext;suf=__int___pb2.pyi:File} ${hide;kv:"ext_out_name_for_${nopath;noext;suf=__int___pb2.pyi:File} ${nopath;noext;suf=_pb2.pyi:File}"})
+        PY_PROTO_MYPY_PLUGIN_INTERNAL=$PY_PROTO_MYPY_PLUGIN_BASE ${output;hide;noauto;norel;nopath;noext;suf=__intpy2___pb2.pyi:File} ${hide;kv:"ext_out_name_for_${nopath;noext;suf=__intpy2___pb2.pyi:File} ${nopath;noext;suf=_pb2.pyi:File}"})
     }
     SET(MODULE_LANG PY2)
     ADD_CLANG_TIDY()
@@ -586,7 +589,7 @@ module PY3_LIBRARY: _LIBRARY {
     when ($PY_PROTO_MYPY_ENABLED == "yes") {
         PY_PROTO_MYPY_SUFFIX=_pb2.pyi
         PY_PROTO_MYPY_PLUGIN=$PY_PROTO_MYPY_PLUGIN_BASE ${output;hide;noauto;norel;nopath;noext;suf=_pb2.pyi:File}
-        PY_PROTO_MYPY_PLUGIN_INTERNAL=$PY_PROTO_MYPY_PLUGIN_BASE ${output;hide;noauto;norel;nopath;noext;suf=__int___pb2.pyi:File} ${hide;kv:"ext_out_name_for_${nopath;noext;suf=__int___pb2.pyi:File} ${nopath;noext;suf=_pb2.pyi:File}"})
+        PY_PROTO_MYPY_PLUGIN_INTERNAL=$PY_PROTO_MYPY_PLUGIN_BASE ${output;hide;noauto;norel;nopath;noext;suf=__intpy3___pb2.pyi:File} ${hide;kv:"ext_out_name_for_${nopath;noext;suf=__intpy3___pb2.pyi:File} ${nopath;noext;suf=_pb2.pyi:File}"})
     }
     SET(MODULE_LANG PY3)
     ADD_CLANG_TIDY()
@@ -768,6 +771,7 @@ macro _ARCADIA_PYTHON_ADDINCL() {
 macro _PYTHON_ADDINCL() {
     SET(PYTHON2 yes)
     SET(PYTHON3 no)
+    SET(_PYTHON_VER py2)
     when ($USE_ARCADIA_PYTHON == "yes") {
         ADDINCL+=GLOBAL contrib/libs/python/Include
         CFLAGS+=-DARCADIA_PYTHON_UNICODE_SIZE=$ARCADIA_PYTHON_UNICODE_SIZE
@@ -817,6 +821,7 @@ macro _ARCADIA_PYTHON3_ADDINCL() {
 macro _PYTHON3_ADDINCL() {
     SET(PYTHON3 yes)
     SET(PYTHON2 no)
+    SET(_PYTHON_VER py3)
     when ($USE_ARCADIA_PYTHON == "yes") {
         CFLAGS+=-DUSE_PYTHON3
         ADDINCL+=GLOBAL contrib/libs/python/Include

+ 3 - 3
build/plugins/pybuild.py

@@ -56,8 +56,8 @@ def uniq_suffix(path, unit):
 
 
 def pb2_arg(suf, path, mod, unit):
-    return '{path}__int__{suf}={mod}{modsuf}'.format(
-        path=stripext(to_build_root(path, unit)), suf=suf, mod=mod, modsuf=stripext(suf)
+    return '{path}__int{py_ver}__{suf}={mod}{modsuf}'.format(
+        path=stripext(to_build_root(path, unit)), suf=suf, mod=mod, modsuf=stripext(suf), py_ver=unit.get('_PYTHON_VER')
     )
 
 
@@ -74,7 +74,7 @@ def ev_cc_arg(path, unit):
 
 
 def ev_arg(path, mod, unit):
-    return '{}__int___ev_pb2.py={}_ev_pb2'.format(stripext(to_build_root(path, unit)), mod)
+    return '{}__int{}___ev_pb2.py={}_ev_pb2'.format(stripext(to_build_root(path, unit)), unit.get('_PYTHON_VER'), mod)
 
 
 def mangle(name):

+ 2 - 1
build/scripts/gen_py_protos.py

@@ -19,6 +19,7 @@ def main():
     parser.add_argument("--suffixes", nargs="*", default=[])
     parser.add_argument("--input")
     parser.add_argument("--ns")
+    parser.add_argument("--py_ver")
     parser.add_argument("protoc_args", nargs=argparse.REMAINDER)
     script_args = parser.parse_args()
 
@@ -72,7 +73,7 @@ def main():
         temp_file_name = path.join(temp_name, temp_base_name + suf)
         assert path.exists(temp_file_name)
 
-        orig_file_name = path.join(orig_name, orig_base_name + '__int__' + suf)
+        orig_file_name = path.join(orig_name, orig_base_name + '__int{}__'.format(script_args.py_ver) + suf)
         os.rename(temp_file_name, orig_file_name)
 
     shutil.rmtree(out_dir_temp)