aboutsummaryrefslogtreecommitdiffstats
path: root/build/scripts/cgo1_wrapper.py
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /build/scripts/cgo1_wrapper.py
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'build/scripts/cgo1_wrapper.py')
-rw-r--r--build/scripts/cgo1_wrapper.py45
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 00000000000..986082f7e94
--- /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')