OLD | NEW |
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 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 'METHOD_ID_VAR_NAME': called_by_native.method_id_var_name, | 915 'METHOD_ID_VAR_NAME': called_by_native.method_id_var_name, |
916 'GET_METHOD_ID_IMPL': self.GetMethodIDImpl(called_by_native), | 916 'GET_METHOD_ID_IMPL': self.GetMethodIDImpl(called_by_native), |
917 } | 917 } |
918 ret += [template.substitute(values)] | 918 ret += [template.substitute(values)] |
919 return '\n'.join(ret) | 919 return '\n'.join(ret) |
920 | 920 |
921 def GetRegisterNativesString(self): | 921 def GetRegisterNativesString(self): |
922 """Returns the code for RegisterNatives.""" | 922 """Returns the code for RegisterNatives.""" |
923 template = Template("""\ | 923 template = Template("""\ |
924 ${REGISTER_NATIVES_SIGNATURE} { | 924 ${REGISTER_NATIVES_SIGNATURE} { |
925 ${EARLY_EXIT}${CLASSES} | 925 ${EARLY_EXIT} |
| 926 ${CLASSES} |
926 ${NATIVES} | 927 ${NATIVES} |
927 ${CALLED_BY_NATIVES} | 928 ${CALLED_BY_NATIVES} |
928 return true; | 929 return true; |
929 } | 930 } |
930 """) | 931 """) |
931 signature = 'static bool RegisterNativesImpl(JNIEnv* env' | 932 signature = 'static bool RegisterNativesImpl(JNIEnv* env' |
932 if self.init_native: | 933 if self.init_native: |
933 signature += ', jclass clazz)' | 934 signature += ', jclass clazz)' |
934 else: | 935 else: |
935 signature += ')' | 936 signature += ')' |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 return template.substitute(values) | 1067 return template.substitute(values) |
1067 else: | 1068 else: |
1068 return native.name | 1069 return native.name |
1069 | 1070 |
1070 def GetForwardDeclaration(self, native): | 1071 def GetForwardDeclaration(self, native): |
1071 template_str = """ | 1072 template_str = """ |
1072 static ${RETURN} ${NAME}(JNIEnv* env, ${PARAMS}); | 1073 static ${RETURN} ${NAME}(JNIEnv* env, ${PARAMS}); |
1073 """ | 1074 """ |
1074 if self.options.native_exports: | 1075 if self.options.native_exports: |
1075 template_str += """ | 1076 template_str += """ |
1076 __attribute__((visibility("default"), alias("${NAME}"))) | 1077 __attribute__((visibility("default"))) |
1077 ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS}); | 1078 ${RETURN} ${STUB_NAME}(JNIEnv* env, ${PARAMS}) { |
| 1079 return ${NAME}(${PARAMS_IN_CALL}); |
| 1080 } |
1078 """ | 1081 """ |
1079 template = Template(template_str) | 1082 template = Template(template_str) |
1080 params_in_call = [] | 1083 params_in_call = [] |
1081 if not self.options.pure_native_methods: | 1084 if not self.options.pure_native_methods: |
1082 params_in_call = ['env', 'jcaller'] | 1085 params_in_call = ['env', 'jcaller'] |
1083 params_in_call = ', '.join(params_in_call + [p.name for p in native.params]) | 1086 params_in_call = ', '.join(params_in_call + [p.name for p in native.params]) |
1084 | 1087 |
1085 values = {'RETURN': JavaDataTypeToC(native.return_type), | 1088 values = {'RETURN': JavaDataTypeToC(native.return_type), |
1086 'NAME': native.name, | 1089 'NAME': native.name, |
1087 'PARAMS': self.GetParamsInDeclaration(native), | 1090 'PARAMS': self.GetParamsInDeclaration(native), |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 } | 1308 } |
1306 ret += [template.substitute(values)] | 1309 ret += [template.substitute(values)] |
1307 | 1310 |
1308 return '\n'.join(ret) | 1311 return '\n'.join(ret) |
1309 | 1312 |
1310 def GetFindClasses(self): | 1313 def GetFindClasses(self): |
1311 """Returns the imlementation of FindClass for all known classes.""" | 1314 """Returns the imlementation of FindClass for all known classes.""" |
1312 if self.init_native: | 1315 if self.init_native: |
1313 if self.options.native_exports: | 1316 if self.options.native_exports: |
1314 template = Template("""\ | 1317 template = Template("""\ |
1315 base::subtle::Release_Store(&g_${JAVA_CLASS}_clazz, | 1318 base::subtle::Release_Store(&g_${JAVA_CLASS}_clazz, |
1316 static_cast<base::subtle::AtomicWord>(env->NewWeakGlobalRef(clazz));""") | 1319 static_cast<base::subtle::AtomicWord>(env->NewWeakGlobalRef(clazz));""") |
1317 else: | 1320 else: |
1318 template = Template("""\ | 1321 template = Template("""\ |
1319 g_${JAVA_CLASS}_clazz = static_cast<jclass>(env->NewWeakGlobalRef(clazz));""") | 1322 g_${JAVA_CLASS}_clazz = static_cast<jclass>(env->NewWeakGlobalRef(clazz));""") |
1320 else: | 1323 else: |
1321 if self.options.native_exports: | 1324 if self.options.native_exports: |
1322 return '\n' | 1325 return '\n' |
1323 template = Template("""\ | 1326 template = Template("""\ |
1324 g_${JAVA_CLASS}_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( | 1327 g_${JAVA_CLASS}_clazz = reinterpret_cast<jclass>(env->NewGlobalRef( |
1325 base::android::GetClass(env, k${JAVA_CLASS}ClassPath).obj()));""") | 1328 base::android::GetClass(env, k${JAVA_CLASS}ClassPath).obj()));""") |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 GenerateJNIHeader(input_file, output_file, options) | 1548 GenerateJNIHeader(input_file, output_file, options) |
1546 | 1549 |
1547 if options.depfile: | 1550 if options.depfile: |
1548 build_utils.WriteDepfile( | 1551 build_utils.WriteDepfile( |
1549 options.depfile, | 1552 options.depfile, |
1550 build_utils.GetPythonDependencies()) | 1553 build_utils.GetPythonDependencies()) |
1551 | 1554 |
1552 | 1555 |
1553 if __name__ == '__main__': | 1556 if __name__ == '__main__': |
1554 sys.exit(main(sys.argv)) | 1557 sys.exit(main(sys.argv)) |
OLD | NEW |