diff options
author | alexv-smirnov <alex@ydb.tech> | 2023-06-13 11:05:01 +0300 |
---|---|---|
committer | alexv-smirnov <alex@ydb.tech> | 2023-06-13 11:05:01 +0300 |
commit | bf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0 (patch) | |
tree | 1d1df72c0541a59a81439842f46d95396d3e7189 /build/scripts/jni_swig.py | |
parent | 8bfdfa9a9bd19bddbc58d888e180fbd1218681be (diff) | |
download | ydb-bf0f13dd39ee3e65092ba3572bb5b1fcd125dcd0.tar.gz |
add ymake export to ydb
Diffstat (limited to 'build/scripts/jni_swig.py')
-rw-r--r-- | build/scripts/jni_swig.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/build/scripts/jni_swig.py b/build/scripts/jni_swig.py new file mode 100644 index 0000000000..4b2220430b --- /dev/null +++ b/build/scripts/jni_swig.py @@ -0,0 +1,46 @@ +import argparse +import subprocess +import re +import os +import tarfile + +def parse_args(): + parser = argparse.ArgumentParser(description='Wrapper script to invoke swig.') + parser.add_argument('--swig', help='path to the swig executable') + parser.add_argument('--default-module', type=str, help='swig -module argument value for inputs without %module statement') + parser.add_argument('--package-by-file', help='path to file which dir must be converted to swig -package argument') + parser.add_argument('--jsrc', help='jsrc output archive filename') + parser.add_argument('--src', help='input .swg file path') + parser.add_argument('--out-header', help='header file which must exist even if it was not generated by swig') + parser.add_argument('args', nargs="*", help='regular swig arguments') + + return parser.parse_args() + + +def path2pkg(path): + return path.replace('/', '.').replace('-', '_') + + +def main(args): + package = path2pkg(os.path.dirname(args.package_by_file)) + outdir = None + if args.jsrc: + outdir = package.replace('.', '/') + outdir_abs = os.path.join(os.path.dirname(args.jsrc), outdir) + if not os.path.exists(outdir_abs): + os.makedirs(outdir_abs) + cmd = [args.swig, '-c++', '-java', '-package', package] + (['-outdir', outdir_abs] if outdir is not None else []) + args.args + if '-module' not in args.args and args.default_module: + with open(args.src, 'r') as f: + if not re.search(r'(?m)^%module\b', f.read()): + cmd += ['-module', args.default_module] + subprocess.check_call(cmd + [args.src]) + if args.out_header and not os.path.exists(args.out_header): + open(args.out_header, 'w').close() + if args.jsrc: + with tarfile.open(args.jsrc, 'a') as tf: + tf.add(outdir_abs, arcname=outdir) + + +if __name__ == '__main__': + main(parse_args()) |