diff options
author | alexv-smirnov <alex@ydb.tech> | 2022-08-18 16:52:30 +0300 |
---|---|---|
committer | alexv-smirnov <alex@ydb.tech> | 2022-08-18 16:52:30 +0300 |
commit | c140abc954b61ab7d86af80bdeced01482d9971a (patch) | |
tree | c47d70fa3213240d5e0eb59787a5325782a360de /build/scripts/cgo1_wrapper.py | |
parent | 0ce07b9705ed20e3fce2759eae41496014ca4c33 (diff) | |
download | ydb-c140abc954b61ab7d86af80bdeced01482d9971a.tar.gz |
temp fix ydb oss sync config to unlock sync on /vendor dependency
Diffstat (limited to 'build/scripts/cgo1_wrapper.py')
-rw-r--r-- | build/scripts/cgo1_wrapper.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/build/scripts/cgo1_wrapper.py b/build/scripts/cgo1_wrapper.py new file mode 100644 index 0000000000..986082f7e9 --- /dev/null +++ b/build/scripts/cgo1_wrapper.py @@ -0,0 +1,45 @@ +import argparse +import shutil +import subprocess +import sys + + +CGO1_SUFFIX='.cgo1.go' + + +def call(cmd, cwd, env=None): + # sys.stderr.write('{}\n'.format(' '.join(cmd))) + return subprocess.call(cmd, stdin=None, stderr=sys.stderr, stdout=sys.stdout, cwd=cwd, env=env) + + +def process_file(source_root, source_prefix, build_root, build_prefix, src_path, comment_prefix): + dst_path = '{}.tmp'.format(src_path) + with open(src_path, 'r') as src_file, open(dst_path, 'w') as dst_file: + for line in src_file: + if line.startswith(comment_prefix): + dst_file.write(line.replace(source_root, source_prefix).replace(build_root, build_prefix)) + else: + dst_file.write(line) + shutil.move(dst_path, src_path) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument('--build-prefix', default='__ARCADIA_BUILD_ROOT_PREFIX__') + parser.add_argument('--build-root', required=True) + parser.add_argument('--cgo1-files', nargs='+', required=True) + parser.add_argument('--cgo2-files', nargs='+', required=True) + parser.add_argument('--source-prefix', default='__ARCADIA_SOURCE_ROOT_PREFIX__') + parser.add_argument('--source-root', required=True) + parser.add_argument('cgo1_cmd', nargs='*') + args = parser.parse_args() + + exit_code = call(args.cgo1_cmd, args.source_root) + if exit_code != 0: + sys.exit(exit_code) + + for src_path in args.cgo1_files: + process_file(args.source_root, args.source_prefix, args.build_root, args.build_prefix, src_path, '//') + + for src_path in args.cgo2_files: + process_file(args.source_root, args.source_prefix, args.build_root, args.build_prefix, src_path, '#line') |