Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: base/android/jni_generator/jni_generator.py

Issue 851503003: Update from https://crrev.com/311076 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Extracts native methods from a Java file and generates the JNI bindings. 6 """Extracts native methods from a Java file and generates the JNI bindings.
7 If you change this, please run and update the tests.""" 7 If you change this, please run and update the tests."""
8 8
9 import collections 9 import collections
10 import errno 10 import errno
(...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 JavaDataTypeToCForCalledByNativeParam(param.datatype) + ' ' + 1030 JavaDataTypeToCForCalledByNativeParam(param.datatype) + ' ' +
1031 param.name 1031 param.name
1032 for param in called_by_native.params]) 1032 for param in called_by_native.params])
1033 1033
1034 def GetForwardDeclaration(self, native): 1034 def GetForwardDeclaration(self, native):
1035 template_str = """ 1035 template_str = """
1036 static ${RETURN} ${NAME}(JNIEnv* env, ${PARAMS}); 1036 static ${RETURN} ${NAME}(JNIEnv* env, ${PARAMS});
1037 """ 1037 """
1038 if self.options.native_exports: 1038 if self.options.native_exports:
1039 template_str += """ 1039 template_str += """
1040 __attribute__((visibility("default"))) 1040 __attribute__((visibility("default"), alias("${NAME}")))
1041 ${RETURN} Java_${JAVA_NAME}_native${NAME}(JNIEnv* env, ${PARAMS}) { 1041 ${RETURN} Java_${JAVA_NAME}_native${NAME}(JNIEnv* env, ${PARAMS});
1042 return ${NAME}(${PARAMS_IN_CALL});
1043 }
1044 """ 1042 """
1045 template = Template(template_str) 1043 template = Template(template_str)
1046 params_in_call = [] 1044 params_in_call = []
1047 if not self.options.pure_native_methods: 1045 if not self.options.pure_native_methods:
1048 params_in_call = ['env', 'jcaller'] 1046 params_in_call = ['env', 'jcaller']
1049 params_in_call = ', '.join(params_in_call + [p.name for p in native.params]) 1047 params_in_call = ', '.join(params_in_call + [p.name for p in native.params])
1050 1048
1051 java_name = JniParams.RemapClassName(self.fully_qualified_class) 1049 java_name = JniParams.RemapClassName(self.fully_qualified_class)
1052 java_name = java_name.replace('_', '_1').replace('/', '_') 1050 java_name = java_name.replace('_', '_1').replace('/', '_')
1053 if native.java_class_name: 1051 if native.java_class_name:
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 'JAVA_CLASS': clazz, 1258 'JAVA_CLASS': clazz,
1261 'JNI_CLASS_PATH': JniParams.RemapClassName(all_classes[clazz]), 1259 'JNI_CLASS_PATH': JniParams.RemapClassName(all_classes[clazz]),
1262 } 1260 }
1263 ret += [template.substitute(values)] 1261 ret += [template.substitute(values)]
1264 ret += '' 1262 ret += ''
1265 1263
1266 class_getter_methods = [] 1264 class_getter_methods = []
1267 if self.options.native_exports: 1265 if self.options.native_exports:
1268 template = Template("""\ 1266 template = Template("""\
1269 // Leaking this jclass as we cannot use LazyInstance from some threads. 1267 // Leaking this jclass as we cannot use LazyInstance from some threads.
1270 base::subtle::AtomicWord g_${JAVA_CLASS}_clazz = 0; 1268 base::subtle::AtomicWord g_${JAVA_CLASS}_clazz __attribute__((unused)) = 0;
1271 #define ${JAVA_CLASS}_clazz(env) \ 1269 #define ${JAVA_CLASS}_clazz(env) \
1272 base::android::LazyGetClass(env, k${JAVA_CLASS}ClassPath, \ 1270 base::android::LazyGetClass(env, k${JAVA_CLASS}ClassPath, \
1273 &g_${JAVA_CLASS}_clazz)""") 1271 &g_${JAVA_CLASS}_clazz)""")
1274 else: 1272 else:
1275 template = Template("""\ 1273 template = Template("""\
1276 // Leaking this jclass as we cannot use LazyInstance from some threads. 1274 // Leaking this jclass as we cannot use LazyInstance from some threads.
1277 jclass g_${JAVA_CLASS}_clazz = NULL; 1275 jclass g_${JAVA_CLASS}_clazz = NULL;
1278 #define ${JAVA_CLASS}_clazz(env) g_${JAVA_CLASS}_clazz""") 1276 #define ${JAVA_CLASS}_clazz(env) g_${JAVA_CLASS}_clazz""")
1279 1277
1280 for clazz in called_by_native_classes: 1278 for clazz in called_by_native_classes:
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 GenerateJNIHeader(input_file, output_file, options) 1516 GenerateJNIHeader(input_file, output_file, options)
1519 1517
1520 if options.depfile: 1518 if options.depfile:
1521 build_utils.WriteDepfile( 1519 build_utils.WriteDepfile(
1522 options.depfile, 1520 options.depfile,
1523 build_utils.GetPythonDependencies()) 1521 build_utils.GetPythonDependencies())
1524 1522
1525 1523
1526 if __name__ == '__main__': 1524 if __name__ == '__main__':
1527 sys.exit(main(sys.argv)) 1525 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « base/android/jni_array_unittest.cc ('k') | base/android/jni_generator/testNativeExportsOption.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698