aboutsummaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorspreis <spreis@yandex-team.com>2024-03-29 14:18:43 +0300
committerspreis <spreis@yandex-team.com>2024-03-29 14:31:49 +0300
commitf39261a434c46274b5eaef0927ee3b2e0d95b41a (patch)
treee64c68742b1a7423d8b2809a5ca938f5ddbed2e2 /build
parent9334caaba1f032fa294d74e7a74157e3fb263a3e (diff)
downloadydb-f39261a434c46274b5eaef0927ee3b2e0d95b41a.tar.gz
Re-enable separation of protobufs for Python 2 and Python 3
Это откат коммита https://a.yandex-team.ru/arcadia/commit/rXXXXXX И соответственно возврат коммитов https://a.yandex-team.ru/arcadia/commit/rXXXXXX и https://a.yandex-team.ru/arcadia/commit/rXXXXXX Починка причины отката влилась здесь: https://a.yandex-team.ru/arcadia/commit/rXXXXXX ae529e54d3ef7992b0e9f152373bc300061c1293
Diffstat (limited to 'build')
-rw-r--r--build/plugins/pybuild.py3
-rw-r--r--build/scripts/link_exe.py88
2 files changed, 90 insertions, 1 deletions
diff --git a/build/plugins/pybuild.py b/build/plugins/pybuild.py
index 03377d72f7..b7b28359f4 100644
--- a/build/plugins/pybuild.py
+++ b/build/plugins/pybuild.py
@@ -651,7 +651,8 @@ def onpy_srcs(unit, *args):
if protos:
if not upath.startswith(py_runtime_path) and not upath.startswith(builtin_proto_path):
- unit.onpeerdir(py_runtime_path)
+ if 'protobuf_old' not in upath:
+ unit.onpeerdir(py_runtime_path)
unit.onpeerdir(unit.get("PY_PROTO_DEPS").split())
diff --git a/build/scripts/link_exe.py b/build/scripts/link_exe.py
index 9ad94f23bf..0d28343116 100644
--- a/build/scripts/link_exe.py
+++ b/build/scripts/link_exe.py
@@ -302,11 +302,99 @@ def parse_args():
return parser.parse_args()
+def run(*args):
+ # print >>sys.stderr, args
+ return subprocess.check_output(list(args), shell=False).strip()
+
+
+def gen_renames_1(d):
+ for l in d.split('\n'):
+ l = l.strip()
+
+ if ' ' in l:
+ yield l.split(' ')[-1]
+
+def gen_renames_2(p, d):
+ for s in gen_renames_1(d):
+ yield s + ' ' + p + s
+
+def gen_renames(p, d):
+ return '\n'.join(gen_renames_2(p, d)).strip() + '\n'
+
+def rename_syms(where, ret, libs):
+ p = 'py2_'
+
+ # join libs
+ run(where + 'llvm-ar', 'qL', ret, *libs)
+
+ # find symbols to rename
+ syms = run(where + 'llvm-nm', '--extern-only', '--defined-only', '-A', ret)
+
+ # prepare rename plan
+ renames = gen_renames(p, syms)
+
+ with open('syms', 'w') as f:
+ f.write(renames)
+
+ # rename symbols
+ run(where + 'llvm-objcopy', '--redefine-syms=syms', ret)
+
+ # back-rename some symbols
+ args = [
+ where + 'llvm-objcopy',
+ '--redefine-sym',
+ p + 'init_api_implementation=init6google8protobuf8internal19_api_implementation',
+ '--redefine-sym',
+ p + 'init_message=init6google8protobuf5pyext8_message',
+ '--redefine-sym',
+ p + 'init6google8protobuf8internal19_api_implementation=init6google8protobuf8internal19_api_implementation',
+ '--redefine-sym',
+ p + 'init6google8protobuf5pyext8_message=init6google8protobuf5pyext8_message',
+ '--redefine-sym',
+ p + '_init6google8protobuf8internal19_api_implementation=_init6google8protobuf8internal19_api_implementation',
+ '--redefine-sym',
+ p + '_init6google8protobuf5pyext8_message=_init6google8protobuf5pyext8_message',
+ ret
+ ]
+
+ run(*args)
+
+ return ret
+
+
+def fix_py2(cmd):
+ if 'protobuf_old' not in str(cmd):
+ return cmd
+
+ def my(x):
+ for v in ['libcontrib-libs-protobuf_old.a', 'libpypython-protobuf-py2.a']:
+ if v in x:
+ return True
+
+ return False
+
+ old = []
+ lib = []
+
+ where = ''
+
+ for x in cmd:
+ if '/clang++' in x:
+ where = os.path.dirname(x) + '/'
+
+ if my(x):
+ lib.append(x)
+ else:
+ old.append(x)
+
+ return old + [rename_syms(where, 'libprotoherobora.a', lib)]
+
if __name__ == '__main__':
opts, args = parse_args()
args = pcf.skip_markers(args)
cmd = fix_blas_resolving(args)
+ cmd = fix_py2(cmd)
cmd = remove_excessive_flags(cmd)
if opts.musl:
cmd = fix_cmd_for_musl(cmd)