aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsvidyuk <svidyuk@yandex-team.ru>2022-05-16 10:22:59 +0300
committersvidyuk <svidyuk@yandex-team.ru>2022-05-16 10:22:59 +0300
commitd06413a56e62ba09c9a37132a896c94a441db73b (patch)
tree1fcfba20fe578e41df89eeba10839a73d289f786
parent9299869d8ef58105018d583b3c404817aa719b2e (diff)
downloadydb-d06413a56e62ba09c9a37132a896c94a441db73b.tar.gz
Move swg support to core conf
YMAKE-122 ref:c2fd765614ef1906c7157e643edc2e4fc4f0fa7a
-rw-r--r--build/conf/java.ymake.conf24
-rw-r--r--build/conf/jbuild.ymake.conf2
-rw-r--r--build/plugins/swig.py161
-rw-r--r--build/scripts/jni_swig.py46
-rw-r--r--build/ymake.core.conf53
5 files changed, 116 insertions, 170 deletions
diff --git a/build/conf/java.ymake.conf b/build/conf/java.ymake.conf
index 39db454cda..82c25667da 100644
--- a/build/conf/java.ymake.conf
+++ b/build/conf/java.ymake.conf
@@ -155,9 +155,11 @@ multimodule JAVA_CONTRIB_PROGRAM {
}
}
-module _DLL_COMPATIBLE_JAVA_LIBRARY: EXTERNAL_JAVA_LIBRARY {
- .ARGS_PARSER=DLL
- SET(DONT_RESOLVE_INCLUDES yes)
+macro _JNI_CPP_SWIG_SRCS(Srcs...) {
+ SRCS(${ext=.cpp:Srcs} ${ext=.swg:Srcs})
+}
+macro _JNI_JAVA_SWIG_SRCS(Srcs...) {
+ SRCS(${ext=.java:Srcs} ${ext=.swg:Srcs})
}
### @usage: DLL_JAVA()
@@ -169,16 +171,22 @@ module _DLL_COMPATIBLE_JAVA_LIBRARY: EXTERNAL_JAVA_LIBRARY {
### Documentation: https://wiki.yandex-team.ru/yatool/java/#integracijascpp/pythonsborkojj
multimodule DLL_JAVA {
module JNI_DLL: DLL {
- .ALIASES=SRCS=_SWIG_LANG_FILTERED_SRCS
- SET(SWIG_LANG jni_cpp)
+ .ALIASES=SRCS=_JNI_CPP_SWIG_SRCS
.FINAL_TARGET=no
+ SWIG_LANG=jni_cpp
}
- module JAR_COMPILATION: _DLL_COMPATIBLE_JAVA_LIBRARY {
- .ALIASES=SRCS=_SWIG_LANG_FILTERED_SRCS PEERDIR=_NOOP_MACRO
+ module JAR_COMPILATION: EXTERNAL_JAVA_LIBRARY {
+ .ARGS_PARSER=DLL
+ .ALIASES=SRCS=_JNI_JAVA_SWIG_SRCS PEERDIR=_NOOP_MACRO
.PEERDIRSELF=JNI_DLL
- SET(SWIG_LANG jni_java)
PEERDIR+=build/platform/java/jdk
PEERDIR+=$JDK_RESOURCE_PEERDIR
+ SET(DONT_RESOLVE_INCLUDES yes)
.FINAL_TARGET=yes
+
+ SWIG_LANG=jni_java
+ _SWIG_CMD=$_SWIG_JNI_JAVA_CMD
+ _SWIG_ADDINCLS=$_SWIG_JNI_ADDINCLS
+ _SWIG_PEERDIR=$_SWIG_JNI_PEERDIR
}
}
diff --git a/build/conf/jbuild.ymake.conf b/build/conf/jbuild.ymake.conf
index ba9068fc27..caa1e2f31a 100644
--- a/build/conf/jbuild.ymake.conf
+++ b/build/conf/jbuild.ymake.conf
@@ -121,5 +121,5 @@ module DLL_JAVA: DLL {
PEERDIR+=$JDK_RESOURCE_PEERDIR
PROPAGATES_MANAGEABLE_PEERS=yes
- SET(SWIG_LANG java)
+ SWIG_LANG=java
}
diff --git a/build/plugins/swig.py b/build/plugins/swig.py
deleted file mode 100644
index 8c85ea213e..0000000000
--- a/build/plugins/swig.py
+++ /dev/null
@@ -1,161 +0,0 @@
-import os
-import posixpath
-import re
-
-import _import_wrapper as iw
-import _common as common
-
-
-def init():
- iw.addrule('swg', Swig)
-
-
-class Swig(iw.CustomCommand):
- def __init__(self, path, unit):
- self._tool = unit.get('SWIG_TOOL')
- self._library_dir = unit.get('SWIG_LIBRARY') or 'contrib/tools/swig/Lib'
- self._local_swig = unit.get('USE_LOCAL_SWIG') == "yes"
-
- self._path = path
- self._flags = ['-cpperraswarn']
-
- self._bindir = common.tobuilddir(unit.path())
- self._input_name = common.stripext(os.path.basename(self._path))
-
- relpath = os.path.relpath(os.path.dirname(self._path), unit.path())
-
- self._swig_lang = unit.get('SWIG_LANG')
-
- if self._swig_lang != 'jni_java':
- self._flags += ['-c++']
- self._main_out = os.path.join(
- self._bindir,
- '' if relpath == '.' else relpath.replace('..', '__'),
- self._input_name + '_wrap.swg.cpp')
-
- # lang_specific_incl_dir = 'perl5' if self._swig_lang == 'perl' else self._swig_lang
- lang_specific_incl_dir = self._swig_lang
- if self._swig_lang == 'perl':
- lang_specific_incl_dir = 'perl5'
- elif self._swig_lang in ['jni_cpp', 'jni_java']:
- lang_specific_incl_dir = 'java'
- incl_dirs = [
- "FOR", "swig",
- posixpath.join(self._library_dir, lang_specific_incl_dir),
- "FOR", "swig",
- self._library_dir
- ]
- self._incl_dirs = ['$S', '$B'] + [posixpath.join('$S', d) for d in incl_dirs]
-
- modname = unit.get('REALPRJNAME')
- self._flags.extend(['-module', modname])
-
- if not self._local_swig:
- unit.onaddincl(incl_dirs)
-
- if self._swig_lang == 'python':
- self._out_name = modname + '.py'
- self._flags.extend(['-interface', unit.get('MODULE_PREFIX') + modname])
-
- if self._swig_lang == 'perl':
- self._out_name = modname + '.pm'
- self._flags.append('-shadow')
- unit.onpeerdir(['build/platform/perl'])
-
- if self._swig_lang in ['jni_cpp', 'java']:
- self._out_header = os.path.splitext(self._main_out)[0] + '.h'
- if (not unit.get('USE_SYSTEM_JDK')) and (unit.get('OS_ANDROID') != "yes"):
- unit.onpeerdir(['contrib/libs/jdk'])
-
- self._package = 'ru.yandex.' + os.path.dirname(self._path).replace('$S/', '').replace('$B/', '').replace('/', '.').replace('-', '_')
- if self._swig_lang in ['jni_java', 'java']:
- self._out_name = os.path.splitext(os.path.basename(self._path))[0] + '.jsrc'
- elif self._swig_lang != 'jni_cpp':
- self._flags.append('-' + self._swig_lang)
-
- def descr(self):
- return 'SW', self._path, 'yellow'
-
- def flags(self):
- return self._flags
-
- def tools(self):
- return ['contrib/tools/swig'] if not self._tool else []
-
- def input(self):
- return [
- (self._path, [])
- ]
-
- def output(self):
- if self._swig_lang == 'jni_java':
- return [(common.join_intl_paths(self._bindir, self._out_name), [])]
- elif self._swig_lang == 'jni_cpp':
- return [(self._main_out, []), (self._out_header, [])]
-
- return [
- (self._main_out, []),
- (common.join_intl_paths(self._bindir, self._out_name), (['noauto', 'add_to_outs'] if self._swig_lang != 'java' else [])),
- ] + ([(self._out_header, [])] if self._swig_lang == 'java' else [])
-
- def output_includes(self):
- return [(self._out_header, [])] if self._swig_lang in ['java', 'jni_cpp'] else []
-
- def run(self, extra_args, binary):
- if self._local_swig:
- binary = self._tool
- return self.do_run_java(binary, self._path) if self._swig_lang in ['java', 'jni_cpp', 'jni_java'] else self.do_run(binary, self._path)
-
- def _incl_flags(self):
- return ['-I' + self.resolve_path(x) for x in self._incl_dirs]
-
- def do_run(self, binary, path):
- self.call([binary] + self._flags + [
- '-o', self.resolve_path(common.get(self.output, 0)),
- '-outdir', self.resolve_path(self._bindir)
- ] + self._incl_flags() + [self.resolve_path(path)])
-
- def do_run_java(self, binary, path):
- import tarfile
-
- outdir = self.resolve_path(self._bindir)
- if self._swig_lang != 'jni_cpp':
- java_srcs_dir = os.path.join(outdir, self._package.replace('.', '/'))
- if not os.path.exists(java_srcs_dir):
- os.makedirs(java_srcs_dir)
-
- flags = self._incl_flags()
- src = self.resolve_path(path)
- with open(src, 'r') as f:
- if not re.search(r'(?m)^%module\b', f.read()):
- flags += ['-module', os.path.splitext(os.path.basename(src))[0]]
-
- if self._swig_lang == 'jni_cpp':
- self.call([binary, '-c++', '-o', self._main_out, '-java', '-package', self._package] + flags + [src])
- elif self._swig_lang == 'jni_java':
- self.call([binary, '-c++', '-o', os.path.join(outdir, 'unused.cpp'), '-outdir', java_srcs_dir, '-java', '-package', self._package] + flags + [src])
- elif self._swig_lang == 'java':
- self.call([
- binary, '-c++', '-o', self._main_out, '-outdir', java_srcs_dir,
- '-java', '-package', self._package,
- ] + flags + [src])
-
- if self._swig_lang in ['jni_java', 'java']:
- with tarfile.open(os.path.join(outdir, self._out_name), 'a') as tf:
- tf.add(java_srcs_dir, arcname=self._package.replace('.', '/'))
-
- if self._swig_lang in ['jni_cpp', 'java']:
- header = os.path.splitext(self.resolve_path(self._main_out))[0] + '.h'
- if not os.path.exists(header):
- open(header, 'w').close()
-
-
-def on_swig_lang_filtered_srcs(unit, *args):
- swig_lang = unit.get('SWIG_LANG')
- allowed_exts = set()
- if swig_lang == 'jni_cpp':
- allowed_exts = set(['.cpp', '.swg'])
- if swig_lang == 'jni_java':
- allowed_exts = set(['.java', '.swg'])
- args = [arg for arg in iter(args) if allowed_exts and os.path.splitext(arg)[1] in allowed_exts]
- unit.onsrcs(args)
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())
diff --git a/build/ymake.core.conf b/build/ymake.core.conf
index 1ee6607119..fd28f422bf 100644
--- a/build/ymake.core.conf
+++ b/build/ymake.core.conf
@@ -1208,6 +1208,27 @@ module _BASE_UNIT: _BARE_UNIT {
CPP_PROTO_OUTS_SEM+=${output;main;hide;norel;nopath;noext:File.pb.h}
CPP_EV_OUTS+=${output;hide;norel:File.pb.cc} ${output;hide;norel:File.pb.h}
+ when ($SWIG_LANG == "perl") {
+ _SWIG_CMD=$_SWIG_PERL_CMD
+ _SWIG_ADDINCLS=$_SWIG_PERL_ADDINCLS
+ _SWIG_PEERDIR=$_SWIG_PERL_PEERDIR
+ }
+ elsewhen ($SWIG_LANG == "python") {
+ _SWIG_CMD=$_SWIG_PYTHON_CMD
+ _SWIG_ADDINCLS=$_SWIG_PYTHON_ADDINCLS
+ _SWIG_PEERDIR=$_SWIG_PYTHON_PEERDIR
+ }
+ elsewhen ($SWIG_LANG == "jni_cpp") {
+ _SWIG_CMD=$_SWIG_JNI_CPP_CMD
+ _SWIG_ADDINCLS=$_SWIG_JNI_ADDINCLS
+ _SWIG_PEERDIR=$_SWIG_JNI_PEERDIR
+ }
+ elsewhen ($SWIG_LANG == "java") {
+ _SWIG_CMD=$_SWIG_JNI_CMD
+ _SWIG_ADDINCLS=$_SWIG_JNI_ADDINCLS
+ _SWIG_PEERDIR=$_SWIG_JNI_PEERDIR
+ }
+
when ($PY_PROTOS_FOR == "yes") {
MACRO_ALIAS(EVLOG_CMD _PY_EVLOG_CMD)
MACRO_ALIAS(PROTO_CMD _PY_PROTO_CMD)
@@ -5672,6 +5693,38 @@ macro _SRC(EXT, SRC, SRCFLAGS...) {
# Generic macro definition for _SRC (just a placeholder, it does nothing)
}
+_SWIG_CMD=$_SWIG_PYTHON_CMD
+_SWIG_ADDINCLS=$_SWIG_PYTHON_ADDINCLS
+_SWIG_PEERDIR=$_SWIG_PYTHON_PEERDIR
+
+_SWIG_PYTHON_CMD=${_SWIG_TOOL} -module ${REALPRJNAME} -cpperraswarn -c++ -python -interface ${MODULE_PREFIX}${REALPRJNAME} -o ${output;noext;main;suf=_wrap.swg.cpp:SRC} ${output;noauto;add_to_outs;hide;tobindir;suf=.py:REALPRJNAME} -outdir ${BINDIR} ${pre=-I:_SWIG__INCLUDE} ${input:SRC} ${kv;hide:"p SW"} ${kv;hide:"pc yellow"}
+_SWIG_PYTHON_ADDINCLS=FOR swig ${_SWIG_LIBRARY}/python FOR swig ${_SWIG_LIBRARY}
+_SWIG_PYTHON_PEERDIR=
+
+_SWIG_PERL_CMD=${_SWIG_TOOL} -c++ -cpperraswarn -module ${REALPRJNAME} -shadow -perl -o ${output;noext;main;suf=_wrap.swg.cpp:SRC} ${output;noauto;add_to_outs;hide;tobindir;suf=.pm:REALPRJNAME} -outdir ${ARCADIA_BUILD_ROOT}/${MODDIR} ${pre=-I:_SWIG__INCLUDE} ${input:SRC} ${kv;hide:"p SW"} ${kv;hide:"pc yellow"}
+_SWIG_PERL_ADDINCLS=FOR swig ${_SWIG_LIBRARY}/perl5 FOR swig ${_SWIG_LIBRARY}
+_SWIG_PERL_PEERDIR=build/platform/perl
+
+_SWIG_JNI_CPP_CMD=$YMAKE_PYTHON3 ${input:"build/scripts/jni_swig.py"} --swig ${_SWIG_TOOL} --default-module ${nopath;noext:SRC} --src ${input:SRC} --out-header ${output;main;noext;suf=_wrap.swg.h:SRC} --package-by-file ru/yandex/${input;rootrel:SRC} -- ${pre=-I:_SWIG__INCLUDE} -o ${output;noext;suf=_wrap.swg.cpp:SRC} ${kv;hide:"p SW"} ${kv;hide:"pc yellow"}
+_SWIG_JNI_JAVA_CMD=$YMAKE_PYTHON3 ${input:"build/scripts/jni_swig.py"} --swig ${_SWIG_TOOL} --default-module ${nopath;noext:SRC} --src ${input:SRC} --package-by-file ru/yandex/${input;rootrel:SRC} --jsrc ${output;main;suf=.jsrc:SRC} -- ${pre=-I:_SWIG__INCLUDE} -o ${BINDIR}/unused.cpp ${kv;hide:"p SW"} ${kv;hide:"pc yellow"}
+_SWIG_JNI_CMD=$YMAKE_PYTHON3 ${input:"build/scripts/jni_swig.py"} --swig ${_SWIG_TOOL} --default-module ${nopath;noext:SRC} --src ${input:SRC} --out-header ${output;main;noext;suf=_wrap.swg.h:SRC} --package-by-file ru/yandex/${input;rootrel:SRC} --jsrc ${output;suf=.jsrc:SRC} -- ${pre=-I:_SWIG__INCLUDE} -o ${output;noext;suf=_wrap.swg.cpp:SRC} ${kv;hide:"p SW"} ${kv;hide:"pc yellow"}
+_SWIG_JNI_ADDINCLS=FOR swig ${_SWIG_LIBRARY}/java FOR swig $_SWIG_LIBRARY
+_SWIG_JNI_PEERDIR=$YMAKE_PYTHON3_PEER contrib/libs/jdk
+
+when ($USE_LOCAL_SWIG == "yes") {
+ _SWIG_JNI_ADDINCLS=
+}
+when ($USE_SYSTEM_JDK == "yes" || $OS_ANDROID == "yes") {
+ _SWIG_JNI_PEERDIR=$YMAKE_PYTHON3_PEER
+}
+
+# tag:src-processing
+macro _SRC("swg", SRC, SRCFLAGS...) {
+ .CMD=${_SWIG_CMD}
+ .ADDINCL=${_SWIG_ADDINCLS}
+ .PEERDIR=${_SWIG_PEERDIR}
+}
+
RODATA_SYMBOL_PREFIX=
when ($DARWIN == "yes" || $IOS == "yes" || ($WINDOWS == "yes" && $ARCH_TYPE_32 == "yes")) {
RODATA_SYMBOL_PREFIX=_