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 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
841 if self.options.native_exports_optional: | 841 if self.options.native_exports_optional: |
842 early_exit = """\ | 842 early_exit = """\ |
843 if (base::android::IsManualJniRegistrationDisabled()) return true; | 843 if (base::android::IsManualJniRegistrationDisabled()) return true; |
844 """ | 844 """ |
845 | 845 |
846 natives = self.GetRegisterNativesImplString() | 846 natives = self.GetRegisterNativesImplString() |
847 values = {'REGISTER_NATIVES_SIGNATURE': signature, | 847 values = {'REGISTER_NATIVES_SIGNATURE': signature, |
848 'EARLY_EXIT': early_exit, | 848 'EARLY_EXIT': early_exit, |
849 'NATIVES': natives, | 849 'NATIVES': natives, |
850 } | 850 } |
851 return template.substitute(values) | 851 |
852 func_declaration = '' | |
853 if not natives: | |
854 func_declaration = Template("""\ | |
855 ${REGISTER_NATIVES_SIGNATURE} __attribute__((unused)); | |
no sievers
2016/08/01 21:42:41
This can only be used on the declaration, not the
Torne
2016/08/02 12:23:13
Yeah attributes are annoying :)
| |
856 """).substitute(values) | |
857 | |
858 return func_declaration + template.substitute(values) | |
852 | 859 |
853 def GetRegisterNativesImplString(self): | 860 def GetRegisterNativesImplString(self): |
854 """Returns the shared implementation for RegisterNatives.""" | 861 """Returns the shared implementation for RegisterNatives.""" |
855 if not self.options.native_exports_optional: | 862 if not self.options.native_exports_optional: |
856 return '' | 863 return '' |
857 | 864 |
858 template = Template("""\ | 865 template = Template("""\ |
859 const int kMethods${JAVA_CLASS}Size = arraysize(kMethods${JAVA_CLASS}); | 866 const int kMethods${JAVA_CLASS}Size = arraysize(kMethods${JAVA_CLASS}); |
860 | 867 |
861 if (env->RegisterNatives(${JAVA_CLASS}_clazz(env), | 868 if (env->RegisterNatives(${JAVA_CLASS}_clazz(env), |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1094 static ${RETURN_TYPE} Java_${JAVA_CLASS}_${METHOD_ID_VAR_NAME}(\ | 1101 static ${RETURN_TYPE} Java_${JAVA_CLASS}_${METHOD_ID_VAR_NAME}(\ |
1095 JNIEnv* env${FIRST_PARAM_IN_DECLARATION}${PARAMS_IN_DECLARATION})""") | 1102 JNIEnv* env${FIRST_PARAM_IN_DECLARATION}${PARAMS_IN_DECLARATION})""") |
1096 function_header_template = Template("""\ | 1103 function_header_template = Template("""\ |
1097 ${FUNCTION_SIGNATURE} {""") | 1104 ${FUNCTION_SIGNATURE} {""") |
1098 function_header_with_unused_template = Template("""\ | 1105 function_header_with_unused_template = Template("""\ |
1099 ${FUNCTION_SIGNATURE} __attribute__ ((unused)); | 1106 ${FUNCTION_SIGNATURE} __attribute__ ((unused)); |
1100 ${FUNCTION_SIGNATURE} {""") | 1107 ${FUNCTION_SIGNATURE} {""") |
1101 template = Template(""" | 1108 template = Template(""" |
1102 static base::subtle::AtomicWord g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = 0; | 1109 static base::subtle::AtomicWord g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = 0; |
1103 ${FUNCTION_HEADER} | 1110 ${FUNCTION_HEADER} |
1104 /* Must call RegisterNativesImpl() */ | |
1105 CHECK_CLAZZ(env, ${FIRST_PARAM_IN_CALL}, | 1111 CHECK_CLAZZ(env, ${FIRST_PARAM_IN_CALL}, |
1106 ${JAVA_CLASS}_clazz(env)${OPTIONAL_ERROR_RETURN}); | 1112 ${JAVA_CLASS}_clazz(env)${OPTIONAL_ERROR_RETURN}); |
1107 jmethodID method_id = | 1113 jmethodID method_id = |
1108 ${GET_METHOD_ID_IMPL} | 1114 ${GET_METHOD_ID_IMPL} |
1109 ${RETURN_DECLARATION} | 1115 ${RETURN_DECLARATION} |
1110 ${PRE_CALL}env->${ENV_CALL}(${FIRST_PARAM_IN_CALL}, | 1116 ${PRE_CALL}env->${ENV_CALL}(${FIRST_PARAM_IN_CALL}, |
1111 method_id${PARAMS_IN_CALL})${POST_CALL}; | 1117 method_id${PARAMS_IN_CALL})${POST_CALL}; |
1112 ${CHECK_EXCEPTION} | 1118 ${CHECK_EXCEPTION} |
1113 ${RETURN_CLAUSE} | 1119 ${RETURN_CLAUSE} |
1114 }""") | 1120 }""") |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1357 GenerateJNIHeader(input_file, output_file, options) | 1363 GenerateJNIHeader(input_file, output_file, options) |
1358 | 1364 |
1359 if options.depfile: | 1365 if options.depfile: |
1360 build_utils.WriteDepfile( | 1366 build_utils.WriteDepfile( |
1361 options.depfile, | 1367 options.depfile, |
1362 build_utils.GetPythonDependencies()) | 1368 build_utils.GetPythonDependencies()) |
1363 | 1369 |
1364 | 1370 |
1365 if __name__ == '__main__': | 1371 if __name__ == '__main__': |
1366 sys.exit(main(sys.argv)) | 1372 sys.exit(main(sys.argv)) |
OLD | NEW |