Chromium Code Reviews| 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 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 733 | 733 |
| 734 } // namespace | 734 } // namespace |
| 735 | 735 |
| 736 $OPEN_NAMESPACE | 736 $OPEN_NAMESPACE |
| 737 | 737 |
| 738 $CONSTANT_FIELDS | 738 $CONSTANT_FIELDS |
| 739 | 739 |
| 740 // Step 2: method stubs. | 740 // Step 2: method stubs. |
| 741 $METHOD_STUBS | 741 $METHOD_STUBS |
| 742 | 742 |
| 743 // Step 3: RegisterNatives. | |
|
Torne
2016/08/01 11:51:41
I don't think you should remove this comment - it
| |
| 744 $JNI_NATIVE_METHODS | 743 $JNI_NATIVE_METHODS |
| 745 $REGISTER_NATIVES | 744 $REGISTER_NATIVES |
| 746 $CLOSE_NAMESPACE | 745 $CLOSE_NAMESPACE |
| 747 | 746 |
| 748 #endif // ${HEADER_GUARD} | 747 #endif // ${HEADER_GUARD} |
| 749 """) | 748 """) |
| 750 values = { | 749 values = { |
| 751 'SCRIPT_NAME': self.options.script_name, | 750 'SCRIPT_NAME': self.options.script_name, |
| 752 'FULLY_QUALIFIED_CLASS': self.fully_qualified_class, | 751 'FULLY_QUALIFIED_CLASS': self.fully_qualified_class, |
| 753 'CLASS_PATH_DEFINITIONS': self.GetClassPathDefinitionsString(), | 752 'CLASS_PATH_DEFINITIONS': self.GetClassPathDefinitionsString(), |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 822 return '' | 821 return '' |
| 823 template = Template("""\ | 822 template = Template("""\ |
| 824 static const JNINativeMethod kMethods${JAVA_CLASS}[] = { | 823 static const JNINativeMethod kMethods${JAVA_CLASS}[] = { |
| 825 ${KMETHODS} | 824 ${KMETHODS} |
| 826 }; | 825 }; |
| 827 """) | 826 """) |
| 828 return self.SubstituteNativeMethods(template) | 827 return self.SubstituteNativeMethods(template) |
| 829 | 828 |
| 830 def GetRegisterNativesString(self): | 829 def GetRegisterNativesString(self): |
| 831 """Returns the code for RegisterNatives.""" | 830 """Returns the code for RegisterNatives.""" |
| 831 natives = self.GetRegisterNativesImplString() | |
| 832 if not natives: | |
| 833 return '' | |
| 834 | |
| 832 template = Template("""\ | 835 template = Template("""\ |
| 833 ${REGISTER_NATIVES_SIGNATURE} { | 836 ${REGISTER_NATIVES_SIGNATURE} { |
| 834 ${EARLY_EXIT} | 837 ${EARLY_EXIT} |
| 835 ${NATIVES} | 838 ${NATIVES} |
| 836 return true; | 839 return true; |
| 837 } | 840 } |
| 838 """) | 841 """) |
| 839 signature = 'static bool RegisterNativesImpl(JNIEnv* env)' | 842 signature = 'static bool RegisterNativesImpl(JNIEnv* env)' |
| 840 early_exit = '' | 843 early_exit = '' |
| 841 if self.options.native_exports_optional: | 844 if self.options.native_exports_optional: |
| 842 early_exit = """\ | 845 early_exit = """\ |
| 843 if (base::android::IsManualJniRegistrationDisabled()) return true; | 846 if (base::android::IsManualJniRegistrationDisabled()) return true; |
| 844 """ | 847 """ |
| 845 | 848 |
| 846 natives = self.GetRegisterNativesImplString() | |
| 847 values = {'REGISTER_NATIVES_SIGNATURE': signature, | 849 values = {'REGISTER_NATIVES_SIGNATURE': signature, |
| 848 'EARLY_EXIT': early_exit, | 850 'EARLY_EXIT': early_exit, |
| 849 'NATIVES': natives, | 851 'NATIVES': natives, |
| 850 } | 852 } |
| 851 return template.substitute(values) | 853 return template.substitute(values) |
| 852 | 854 |
| 853 def GetRegisterNativesImplString(self): | 855 def GetRegisterNativesImplString(self): |
| 854 """Returns the shared implementation for RegisterNatives.""" | 856 """Returns the shared implementation for RegisterNatives.""" |
| 855 if not self.options.native_exports_optional: | 857 if not self.options.native_exports_optional: |
| 856 return '' | 858 return '' |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1094 static ${RETURN_TYPE} Java_${JAVA_CLASS}_${METHOD_ID_VAR_NAME}(\ | 1096 static ${RETURN_TYPE} Java_${JAVA_CLASS}_${METHOD_ID_VAR_NAME}(\ |
| 1095 JNIEnv* env${FIRST_PARAM_IN_DECLARATION}${PARAMS_IN_DECLARATION})""") | 1097 JNIEnv* env${FIRST_PARAM_IN_DECLARATION}${PARAMS_IN_DECLARATION})""") |
| 1096 function_header_template = Template("""\ | 1098 function_header_template = Template("""\ |
| 1097 ${FUNCTION_SIGNATURE} {""") | 1099 ${FUNCTION_SIGNATURE} {""") |
| 1098 function_header_with_unused_template = Template("""\ | 1100 function_header_with_unused_template = Template("""\ |
| 1099 ${FUNCTION_SIGNATURE} __attribute__ ((unused)); | 1101 ${FUNCTION_SIGNATURE} __attribute__ ((unused)); |
| 1100 ${FUNCTION_SIGNATURE} {""") | 1102 ${FUNCTION_SIGNATURE} {""") |
| 1101 template = Template(""" | 1103 template = Template(""" |
| 1102 static base::subtle::AtomicWord g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = 0; | 1104 static base::subtle::AtomicWord g_${JAVA_CLASS}_${METHOD_ID_VAR_NAME} = 0; |
| 1103 ${FUNCTION_HEADER} | 1105 ${FUNCTION_HEADER} |
| 1104 /* Must call RegisterNativesImpl() */ | |
|
Torne
2016/08/01 11:51:41
While it does make sense to remove this comment, c
| |
| 1105 CHECK_CLAZZ(env, ${FIRST_PARAM_IN_CALL}, | 1106 CHECK_CLAZZ(env, ${FIRST_PARAM_IN_CALL}, |
| 1106 ${JAVA_CLASS}_clazz(env)${OPTIONAL_ERROR_RETURN}); | 1107 ${JAVA_CLASS}_clazz(env)${OPTIONAL_ERROR_RETURN}); |
| 1107 jmethodID method_id = | 1108 jmethodID method_id = |
| 1108 ${GET_METHOD_ID_IMPL} | 1109 ${GET_METHOD_ID_IMPL} |
| 1109 ${RETURN_DECLARATION} | 1110 ${RETURN_DECLARATION} |
| 1110 ${PRE_CALL}env->${ENV_CALL}(${FIRST_PARAM_IN_CALL}, | 1111 ${PRE_CALL}env->${ENV_CALL}(${FIRST_PARAM_IN_CALL}, |
| 1111 method_id${PARAMS_IN_CALL})${POST_CALL}; | 1112 method_id${PARAMS_IN_CALL})${POST_CALL}; |
| 1112 ${CHECK_EXCEPTION} | 1113 ${CHECK_EXCEPTION} |
| 1113 ${RETURN_CLAUSE} | 1114 ${RETURN_CLAUSE} |
| 1114 }""") | 1115 }""") |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1357 GenerateJNIHeader(input_file, output_file, options) | 1358 GenerateJNIHeader(input_file, output_file, options) |
| 1358 | 1359 |
| 1359 if options.depfile: | 1360 if options.depfile: |
| 1360 build_utils.WriteDepfile( | 1361 build_utils.WriteDepfile( |
| 1361 options.depfile, | 1362 options.depfile, |
| 1362 build_utils.GetPythonDependencies()) | 1363 build_utils.GetPythonDependencies()) |
| 1363 | 1364 |
| 1364 | 1365 |
| 1365 if __name__ == '__main__': | 1366 if __name__ == '__main__': |
| 1366 sys.exit(main(sys.argv)) | 1367 sys.exit(main(sys.argv)) |
| OLD | NEW |