summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-22 00:37:33 +0000
committertedchoc@chromium.org <tedchoc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-22 00:37:33 +0000
commitd8621ce6610cc44ceda9f12aabc3526636934df4 (patch)
tree879fe3590168c1472a98a0d2692b06d6b822fe50
parentcb80af8ba224c8fbb1f45cdd9653caa0c739e2b1 (diff)
downloadchromium_src-d8621ce6610cc44ceda9f12aabc3526636934df4.zip
chromium_src-d8621ce6610cc44ceda9f12aabc3526636934df4.tar.gz
chromium_src-d8621ce6610cc44ceda9f12aabc3526636934df4.tar.bz2
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
-rwxr-xr-xbase/android/jni_generator/jni_generator.py14
-rw-r--r--build/common.gypi6
-rw-r--r--build/jar_file_jni_generator.gypi2
-rw-r--r--build/jni_generator.gypi2
4 files changed, 22 insertions, 2 deletions
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__':
diff --git a/build/common.gypi b/build/common.gypi
index 6ac534d..605cd55 100644
--- a/build/common.gypi
+++ b/build/common.gypi
@@ -1154,6 +1154,12 @@
# to specify the output directory for Ant in the Android build.
'ant_build_out': '`cd <(PRODUCT_DIR) && pwd -P`',
+ # Determines whether we should optimize JNI generation at the cost of
+ # breaking assumptions in the build system that when inputs have changed
+ # the outputs should always change as well. This is meant purely for
+ # developer builds, to avoid spurious re-linking of native files.
+ 'optimize_jni_generation%': 0,
+
# Always uses openssl.
'use_openssl%': 1,
diff --git a/build/jar_file_jni_generator.gypi b/build/jar_file_jni_generator.gypi
index 3c14cf8..2f03b85 100644
--- a/build/jar_file_jni_generator.gypi
+++ b/build/jar_file_jni_generator.gypi
@@ -42,6 +42,8 @@
'<(input_java_class)',
'--output_dir',
'<(SHARED_INTERMEDIATE_DIR)/<(jni_gen_dir)/jni',
+ '--optimize_generation',
+ '<(optimize_jni_generation)',
],
'message': 'Generating JNI bindings from <(input_jar_file)/<(input_java_class)',
'process_outputs_as_sources': 1,
diff --git a/build/jni_generator.gypi b/build/jni_generator.gypi
index 837d9ab..d45daaaf 100644
--- a/build/jni_generator.gypi
+++ b/build/jni_generator.gypi
@@ -47,6 +47,8 @@
'<(RULE_INPUT_PATH)',
'--output_dir',
'<(SHARED_INTERMEDIATE_DIR)/<(jni_gen_dir)/jni',
+ '--optimize_generation',
+ '<(optimize_jni_generation)',
],
'message': 'Generating JNI bindings from <(RULE_INPUT_PATH)',
'process_outputs_as_sources': 1,