diff options
author | pg <pg@yandex-team.com> | 2024-03-27 20:45:52 +0300 |
---|---|---|
committer | pg <pg@yandex-team.com> | 2024-03-27 20:59:16 +0300 |
commit | 0a9f70229b9ddccbd4a09d389642ddafcbe8fd57 (patch) | |
tree | 31883a3cee60b7c9c373dbdf745490574788b2b0 /build | |
parent | 01e2f64ea9b0a11884d483b296278f0811c33d92 (diff) | |
download | ydb-0a9f70229b9ddccbd4a09d389642ddafcbe8fd57.tar.gz |
2594c64e637fd7028000c2f6e9c69b8554b86a5b
Diffstat (limited to 'build')
-rw-r--r-- | build/plugins/pybuild.py | 3 | ||||
-rw-r--r-- | build/scripts/link_exe.py | 88 |
2 files changed, 90 insertions, 1 deletions
diff --git a/build/plugins/pybuild.py b/build/plugins/pybuild.py index 526f98b3cf..ccb6d5b98f 100644 --- a/build/plugins/pybuild.py +++ b/build/plugins/pybuild.py @@ -655,7 +655,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) |