diff options
author | svidyuk <svidyuk@yandex-team.ru> | 2022-05-16 10:22:59 +0300 |
---|---|---|
committer | svidyuk <svidyuk@yandex-team.ru> | 2022-05-16 10:22:59 +0300 |
commit | d06413a56e62ba09c9a37132a896c94a441db73b (patch) | |
tree | 1fcfba20fe578e41df89eeba10839a73d289f786 /build/scripts | |
parent | 9299869d8ef58105018d583b3c404817aa719b2e (diff) | |
download | ydb-d06413a56e62ba09c9a37132a896c94a441db73b.tar.gz |
Move swg support to core conf
YMAKE-122
ref:c2fd765614ef1906c7157e643edc2e4fc4f0fa7a
Diffstat (limited to 'build/scripts')
-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 00000000000..4b2220430b1 --- /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()) |