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

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: 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
« no previous file with comments | « no previous file | base/android/jni_generator/testCalledByNatives.golden » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. 743 $STEP3_COMMENT
Torne 2016/08/02 12:31:40 I'd really just leave the comment there; it's an a
no sievers 2016/08/02 23:12:17 Done.
744 $JNI_NATIVE_METHODS 744 $JNI_NATIVE_METHODS
745 $REGISTER_NATIVES 745 $REGISTER_NATIVES
746 $CLOSE_NAMESPACE 746 $CLOSE_NAMESPACE
747 747
748 #endif // ${HEADER_GUARD} 748 #endif // ${HEADER_GUARD}
749 """) 749 """)
750 values = { 750 values = {
751 'SCRIPT_NAME': self.options.script_name, 751 'SCRIPT_NAME': self.options.script_name,
752 'FULLY_QUALIFIED_CLASS': self.fully_qualified_class, 752 'FULLY_QUALIFIED_CLASS': self.fully_qualified_class,
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 'STEP3_COMMENT': '',
757 'JNI_NATIVE_METHODS': self.GetJNINativeMethodsString(), 758 'JNI_NATIVE_METHODS': self.GetJNINativeMethodsString(),
758 'REGISTER_NATIVES': self.GetRegisterNativesString(), 759 'REGISTER_NATIVES': self.GetRegisterNativesString(),
759 'CLOSE_NAMESPACE': self.GetCloseNamespaceString(), 760 'CLOSE_NAMESPACE': self.GetCloseNamespaceString(),
760 'HEADER_GUARD': self.header_guard, 761 'HEADER_GUARD': self.header_guard,
761 'INCLUDES': self.GetIncludesString(), 762 'INCLUDES': self.GetIncludesString(),
762 } 763 }
764 assert (values['JNI_NATIVE_METHODS'] == '') ==
765 (values['REGISTER_NATIVES'] == '')
766 if values['JNI_NATIVE_METHODS'] != '':
767 values['STEP3_COMMENT'] = '// Step 3: RegisterNatives.'
763 return WrapOutput(template.substitute(values)) 768 return WrapOutput(template.substitute(values))
764 769
765 def GetClassPathDefinitionsString(self): 770 def GetClassPathDefinitionsString(self):
766 ret = [] 771 ret = []
767 ret += [self.GetClassPathDefinitions()] 772 ret += [self.GetClassPathDefinitions()]
768 return '\n'.join(ret) 773 return '\n'.join(ret)
769 774
770 def GetConstantFieldsString(self): 775 def GetConstantFieldsString(self):
771 if not self.constant_fields: 776 if not self.constant_fields:
772 return '' 777 return ''
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 return '' 827 return ''
823 template = Template("""\ 828 template = Template("""\
824 static const JNINativeMethod kMethods${JAVA_CLASS}[] = { 829 static const JNINativeMethod kMethods${JAVA_CLASS}[] = {
825 ${KMETHODS} 830 ${KMETHODS}
826 }; 831 };
827 """) 832 """)
828 return self.SubstituteNativeMethods(template) 833 return self.SubstituteNativeMethods(template)
829 834
830 def GetRegisterNativesString(self): 835 def GetRegisterNativesString(self):
831 """Returns the code for RegisterNatives.""" 836 """Returns the code for RegisterNatives."""
837 natives = self.GetRegisterNativesImplString()
838 if not natives:
839 return ''
840
832 template = Template("""\ 841 template = Template("""\
833 ${REGISTER_NATIVES_SIGNATURE} { 842 ${REGISTER_NATIVES_SIGNATURE} {
834 ${EARLY_EXIT} 843 ${EARLY_EXIT}
835 ${NATIVES} 844 ${NATIVES}
836 return true; 845 return true;
837 } 846 }
838 """) 847 """)
839 signature = 'static bool RegisterNativesImpl(JNIEnv* env)' 848 signature = 'static bool RegisterNativesImpl(JNIEnv* env)'
840 early_exit = '' 849 early_exit = ''
841 if self.options.native_exports_optional: 850 if self.options.native_exports_optional:
842 early_exit = """\ 851 early_exit = """\
843 if (base::android::IsManualJniRegistrationDisabled()) return true; 852 if (base::android::IsManualJniRegistrationDisabled()) return true;
844 """ 853 """
845 854
846 natives = self.GetRegisterNativesImplString()
847 values = {'REGISTER_NATIVES_SIGNATURE': signature, 855 values = {'REGISTER_NATIVES_SIGNATURE': signature,
848 'EARLY_EXIT': early_exit, 856 'EARLY_EXIT': early_exit,
849 'NATIVES': natives, 857 'NATIVES': natives,
850 } 858 }
851 859
852 func_declaration = '' 860 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 861
860 def GetRegisterNativesImplString(self): 862 def GetRegisterNativesImplString(self):
861 """Returns the shared implementation for RegisterNatives.""" 863 """Returns the shared implementation for RegisterNatives."""
862 if not self.options.native_exports_optional: 864 if not self.options.native_exports_optional:
863 return '' 865 return ''
864 866
865 template = Template("""\ 867 template = Template("""\
866 const int kMethods${JAVA_CLASS}Size = arraysize(kMethods${JAVA_CLASS}); 868 const int kMethods${JAVA_CLASS}Size = arraysize(kMethods${JAVA_CLASS});
867 869
868 if (env->RegisterNatives(${JAVA_CLASS}_clazz(env), 870 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) 1365 GenerateJNIHeader(input_file, output_file, options)
1364 1366
1365 if options.depfile: 1367 if options.depfile:
1366 build_utils.WriteDepfile( 1368 build_utils.WriteDepfile(
1367 options.depfile, 1369 options.depfile,
1368 build_utils.GetPythonDependencies()) 1370 build_utils.GetPythonDependencies())
1369 1371
1370 1372
1371 if __name__ == '__main__': 1373 if __name__ == '__main__':
1372 sys.exit(main(sys.argv)) 1374 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | base/android/jni_generator/testCalledByNatives.golden » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698