From d8621ce6610cc44ceda9f12aabc3526636934df4 Mon Sep 17 00:00:00 2001 From: "tedchoc@chromium.org" Date: Fri, 22 Feb 2013 00:37:33 +0000 Subject: Add gyp flag to specify whether we should optimize JNI generation. Do not regenerate JNI files (and subsequently the .so file) if they have not changed. This will happen if you edit a java file that has a native counterpart, but the native signatures were not touched. We do not enable this all the time as some build systems require that when you modify an input, the output should also be modified. This also will result in more command line output, so we'll keep it behind a developer flag for now. BUG= Review URL: https://chromiumcodereview.appspot.com/12314025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@183936 0039d316-1c4b-4281-b951-d872f2087c98 --- base/android/jni_generator/jni_generator.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'base') diff --git a/base/android/jni_generator/jni_generator.py b/base/android/jni_generator/jni_generator.py index 79a2096..d57662e 100755 --- a/base/android/jni_generator/jni_generator.py +++ b/base/android/jni_generator/jni_generator.py @@ -957,7 +957,7 @@ def ExtractJarInputFile(jar_file, input_file, out_dir): return extracted_file_name -def GenerateJNIHeader(input_file, output_file, namespace): +def GenerateJNIHeader(input_file, output_file, namespace, skip_if_same): try: if os.path.splitext(input_file)[1] == '.class': jni_from_javap = JNIFromJavaP.CreateFromClass(input_file, namespace) @@ -971,6 +971,11 @@ def GenerateJNIHeader(input_file, output_file, namespace): if output_file: if not os.path.exists(os.path.dirname(os.path.abspath(output_file))): os.makedirs(os.path.dirname(os.path.abspath(output_file))) + if skip_if_same and os.path.exists(output_file): + with file(output_file, 'r') as f: + existing_content = f.read() + if existing_content == content: + return with file(output_file, 'w') as f: f.write(content) else: @@ -1000,6 +1005,10 @@ See SampleForTests.java for more details. option_parser.add_option('--output_dir', help='The output directory. Must be used with ' '--input') + option_parser.add_option('--optimize_generation', type="int", + default=0, help='Whether we should optimize JNI ' + 'generation by not regenerating files if they have ' + 'not changed.') options, args = option_parser.parse_args(argv) if options.jar_file: input_file = ExtractJarInputFile(options.jar_file, options.input_file, @@ -1010,7 +1019,8 @@ See SampleForTests.java for more details. if options.output_dir: root_name = os.path.splitext(os.path.basename(input_file))[0] output_file = os.path.join(options.output_dir, root_name) + '_jni.h' - GenerateJNIHeader(input_file, output_file, options.namespace) + GenerateJNIHeader(input_file, output_file, options.namespace, + options.optimize_generation) if __name__ == '__main__': -- cgit v1.1