mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00

This commit moves common SWIG syntax to a ${libname}.i for sensor libraries. Much of the swig content was originally duplicated for each wrapper language which has lead to inconsistencies between wrappers over time. This commit moves all swig syntax to a common file. Language specific swig syntax can be added with #ifdef SWIG<LANGUAGE>. The src/CMakeLists.txt will look first for a language-specific .i file, then fall back to ${libname}.i. In this way, it's possible to override the common ${libname}.i file. If a fallback .i file does NOT exist, UPM CMake will generate a simple interface file for all languages. Example: If no src/abp/pyupm_abp.i and no src/abp/abp.i then generate ${CMAKE_CURRENT_BINARY_DIR}/abp.i When src/CMakeLists.txt uses a common ${libname}.i, it adds a -module <language>upm_${libname} to the swig command line. In the example below, a -module argument is provided for both Java and Javascript, while the python module takes all syntax from pyupm_abp.i. SWIG FILE Language CMake added SWIG args --------------- ---------- --------------------- src/abp/abp.i java -module javaupm_abp src/abp/abp.i javascript -module jsupm_abp src/abp/pyupm_abp.i python This commit removes ~4500 redundant lines for the UPM repository and helps promote uniformity for the SWIG'ed languages. Signed-off-by: Noel Eck <noel.eck@intel.com>
54 lines
1.8 KiB
Python
Executable File
54 lines
1.8 KiB
Python
Executable File
#!/usr/bin/python
|
|
|
|
import unittest as u
|
|
import re, fnmatch, os
|
|
|
|
rootDir = '../src/'
|
|
prefix = """
|
|
%pragma(java) jniclasscode=%{
|
|
static {
|
|
try {
|
|
System.loadLibrary(\""""
|
|
|
|
suffix = """\");
|
|
} catch (UnsatisfiedLinkError e) {
|
|
System.err.println("Native code library failed to load. \\n" + e);
|
|
System.exit(1);
|
|
}
|
|
}
|
|
%}"""
|
|
|
|
class AutoLoadLibrary(u.TestCase):
|
|
|
|
def test_existing_snippet(self):
|
|
broken_modules = []
|
|
|
|
for subdir, dirs, files in os.walk(rootDir):
|
|
for fileName in files:
|
|
if fnmatch.fnmatch(fileName, '*.i'):
|
|
moduleName = fileName[:-2]
|
|
snippet = prefix + moduleName + suffix
|
|
|
|
with open(os.path.join(subdir, fileName), "rU") as f:
|
|
#read in entire file
|
|
data = f.read()
|
|
#Make sure it is module
|
|
if not '%module' in data:
|
|
print "%%module not found in %s, skipping" % fileName
|
|
continue
|
|
# Check for the autoload code or the autoload macro
|
|
if (not 'JAVA_JNI_LOADLIBRARY(javaupm_' in data) and \
|
|
(not snippet in data):
|
|
broken_modules.append('%s: %s' % \
|
|
(moduleName, os.path.join(subdir, fileName)))
|
|
|
|
self.assertEqual( len(broken_modules), 0, \
|
|
"\nThe following modules do not contain the standard auto load library code:\n" + \
|
|
"\n".join(broken_modules) + \
|
|
"\nConsider adding the following snippet to the SWIG interface file:\n" + \
|
|
prefix + "<module_name>" + suffix)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
u.main()
|