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

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

Issue 2199973003: Android JNI gen: Don't emit code for empty RegisterNatives() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@jnireg1
Patch Set: Android JNI gen: Don't emit code for empty RegisterNatives() Created 4 years, 4 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 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 'CLASS_PATH_DEFINITIONS': self.GetClassPathDefinitionsString(), 753 'CLASS_PATH_DEFINITIONS': self.GetClassPathDefinitionsString(),
754 'CONSTANT_FIELDS': self.GetConstantFieldsString(), 754 'CONSTANT_FIELDS': self.GetConstantFieldsString(),
755 'METHOD_STUBS': self.GetMethodStubsString(), 755 'METHOD_STUBS': self.GetMethodStubsString(),
756 'OPEN_NAMESPACE': self.GetOpenNamespaceString(), 756 'OPEN_NAMESPACE': self.GetOpenNamespaceString(),
757 'JNI_NATIVE_METHODS': self.GetJNINativeMethodsString(), 757 'JNI_NATIVE_METHODS': self.GetJNINativeMethodsString(),
758 'REGISTER_NATIVES': self.GetRegisterNativesString(), 758 'REGISTER_NATIVES': self.GetRegisterNativesString(),
759 'CLOSE_NAMESPACE': self.GetCloseNamespaceString(), 759 'CLOSE_NAMESPACE': self.GetCloseNamespaceString(),
760 'HEADER_GUARD': self.header_guard, 760 'HEADER_GUARD': self.header_guard,
761 'INCLUDES': self.GetIncludesString(), 761 'INCLUDES': self.GetIncludesString(),
762 } 762 }
763 assert ((values['JNI_NATIVE_METHODS'] == '') ==
764 (values['REGISTER_NATIVES'] == ''))
763 return WrapOutput(template.substitute(values)) 765 return WrapOutput(template.substitute(values))
764 766
765 def GetClassPathDefinitionsString(self): 767 def GetClassPathDefinitionsString(self):
766 ret = [] 768 ret = []
767 ret += [self.GetClassPathDefinitions()] 769 ret += [self.GetClassPathDefinitions()]
768 return '\n'.join(ret) 770 return '\n'.join(ret)
769 771
770 def GetConstantFieldsString(self): 772 def GetConstantFieldsString(self):
771 if not self.constant_fields: 773 if not self.constant_fields:
772 return '' 774 return ''
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 return '' 824 return ''
823 template = Template("""\ 825 template = Template("""\
824 static const JNINativeMethod kMethods${JAVA_CLASS}[] = { 826 static const JNINativeMethod kMethods${JAVA_CLASS}[] = {
825 ${KMETHODS} 827 ${KMETHODS}
826 }; 828 };
827 """) 829 """)
828 return self.SubstituteNativeMethods(template) 830 return self.SubstituteNativeMethods(template)
829 831
830 def GetRegisterNativesString(self): 832 def GetRegisterNativesString(self):
831 """Returns the code for RegisterNatives.""" 833 """Returns the code for RegisterNatives."""
834 natives = self.GetRegisterNativesImplString()
835 if not natives:
836 return ''
837
832 template = Template("""\ 838 template = Template("""\
833 ${REGISTER_NATIVES_SIGNATURE} { 839 ${REGISTER_NATIVES_SIGNATURE} {
834 ${EARLY_EXIT} 840 ${EARLY_EXIT}
835 ${NATIVES} 841 ${NATIVES}
836 return true; 842 return true;
837 } 843 }
838 """) 844 """)
839 signature = 'static bool RegisterNativesImpl(JNIEnv* env)' 845 signature = 'static bool RegisterNativesImpl(JNIEnv* env)'
840 early_exit = '' 846 early_exit = ''
841 if self.options.native_exports_optional: 847 if self.options.native_exports_optional:
842 early_exit = """\ 848 early_exit = """\
843 if (base::android::IsManualJniRegistrationDisabled()) return true; 849 if (base::android::IsManualJniRegistrationDisabled()) return true;
844 """ 850 """
845 851
846 natives = self.GetRegisterNativesImplString()
847 values = {'REGISTER_NATIVES_SIGNATURE': signature, 852 values = {'REGISTER_NATIVES_SIGNATURE': signature,
848 'EARLY_EXIT': early_exit, 853 'EARLY_EXIT': early_exit,
849 'NATIVES': natives, 854 'NATIVES': natives,
850 } 855 }
851 856
852 func_declaration = '' 857 return template.substitute(values)
853 if not natives:
854 func_declaration = Template("""\
855 ${REGISTER_NATIVES_SIGNATURE} __attribute__((unused));
856 """).substitute(values)
857
858 return func_declaration + template.substitute(values)
859 858
860 def GetRegisterNativesImplString(self): 859 def GetRegisterNativesImplString(self):
861 """Returns the shared implementation for RegisterNatives.""" 860 """Returns the shared implementation for RegisterNatives."""
862 if not self.options.native_exports_optional: 861 if not self.options.native_exports_optional:
863 return '' 862 return ''
864 863
865 template = Template("""\ 864 template = Template("""\
866 const int kMethods${JAVA_CLASS}Size = arraysize(kMethods${JAVA_CLASS}); 865 const int kMethods${JAVA_CLASS}Size = arraysize(kMethods${JAVA_CLASS});
867 866
868 if (env->RegisterNatives(${JAVA_CLASS}_clazz(env), 867 if (env->RegisterNatives(${JAVA_CLASS}_clazz(env),
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
1363 GenerateJNIHeader(input_file, output_file, options) 1362 GenerateJNIHeader(input_file, output_file, options)
1364 1363
1365 if options.depfile: 1364 if options.depfile:
1366 build_utils.WriteDepfile( 1365 build_utils.WriteDepfile(
1367 options.depfile, 1366 options.depfile,
1368 build_utils.GetPythonDependencies()) 1367 build_utils.GetPythonDependencies())
1369 1368
1370 1369
1371 if __name__ == '__main__': 1370 if __name__ == '__main__':
1372 sys.exit(main(sys.argv)) 1371 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « android_webview/native/input_stream_unittest.cc ('k') | base/android/jni_generator/testCalledByNatives.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698