summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-15 00:12:07 +0000
committercjhopman@chromium.org <cjhopman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-15 00:12:07 +0000
commit582a8575e5259762d5cb7b517b928ed7fc75ca11 (patch)
tree05084b8b749aa740a9afde426f0326ec600cc60d
parent8ce89cd31f3a2361a03d0451f75f14a97e311638 (diff)
downloadchromium_src-582a8575e5259762d5cb7b517b928ed7fc75ca11.zip
chromium_src-582a8575e5259762d5cb7b517b928ed7fc75ca11.tar.gz
chromium_src-582a8575e5259762d5cb7b517b928ed7fc75ca11.tar.bz2
Add support for proguard preprocessing.
* Adds support for running proguard on our libraries before they are added to the final release APK. * Start using the proguard preprocessing for third_party/guava. BUG=272790 NOTRY=true TBR=darin@chromium.org Review URL: https://chromiumcodereview.appspot.com/23213002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217706 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-xbuild/android/gyp/proguard.py55
-rw-r--r--build/java.gypi48
-rw-r--r--third_party/guava/guava.gyp2
-rw-r--r--third_party/guava/proguard.flags33
4 files changed, 136 insertions, 2 deletions
diff --git a/build/android/gyp/proguard.py b/build/android/gyp/proguard.py
new file mode 100755
index 0000000..6268caf
--- /dev/null
+++ b/build/android/gyp/proguard.py
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+#
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import fnmatch
+import optparse
+import os
+import sys
+
+from util import build_utils
+
+def DoProguard(options):
+ injars = options.input_path
+ outjars = options.output_path
+ classpath = build_utils.ParseGypList(options.classpath)
+ classpath = list(set(classpath))
+ libraryjars = ':'.join(classpath)
+ # proguard does its own dependency checking, which can be avoided by deleting
+ # the output.
+ if os.path.exists(options.output_path):
+ os.remove(options.output_path)
+ proguard_cmd = [options.proguard_path,
+ '-injars', injars,
+ '-outjars', outjars,
+ '-libraryjars', libraryjars,
+ '@' + options.proguard_config]
+ build_utils.CheckCallDie(proguard_cmd)
+
+def main(argv):
+ parser = optparse.OptionParser()
+ parser.add_option('--proguard-path',
+ help='Path to the proguard executable.')
+ parser.add_option('--input-path',
+ help='Path to the .jar file proguard should run on.')
+ parser.add_option('--output-path', help='Path to the generated .jar file.')
+ parser.add_option('--proguard-config',
+ help='Path to the proguard configuration file.')
+ parser.add_option('--classpath', help="Classpath for proguard.")
+ parser.add_option('--stamp', help='Path to touch on success.')
+
+ # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
+ parser.add_option('--ignore', help='Ignored.')
+
+ options, _ = parser.parse_args()
+
+ DoProguard(options)
+
+ if options.stamp:
+ build_utils.Touch(options.stamp)
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
diff --git a/build/java.gypi b/build/java.gypi
index 1635c71..5318e2a 100644
--- a/build/java.gypi
+++ b/build/java.gypi
@@ -70,6 +70,21 @@
'intermediate_dir': '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)',
'classes_dir': '<(intermediate_dir)/classes',
'compile_stamp': '<(intermediate_dir)/compile.stamp',
+ 'proguard_config%': '',
+ 'proguard_preprocess%': '0',
+ 'variables': {
+ 'variables': {
+ 'proguard_preprocess%': 0,
+ },
+ 'conditions': [
+ ['proguard_preprocess == 1', {
+ 'javac_jar_path': '<(intermediate_dir)/<(_target_name).pre.jar'
+ }, {
+ 'javac_jar_path': '<(PRODUCT_DIR)/lib.java/<(jar_name)'
+ }],
+ ],
+ },
+ 'javac_jar_path': '<(javac_jar_path)',
},
# This all_dependent_settings is used for java targets only. This will add the
# jar path to the classpath of dependent java targets.
@@ -218,6 +233,35 @@
},
],
}],
+ ['proguard_preprocess == 1', {
+ 'actions': [
+ {
+ 'action_name': 'proguard_<(_target_name)',
+ 'message': 'Proguard preprocessing <(_target_name) jar',
+ 'inputs': [
+ '<(android_sdk_root)/tools/proguard/bin/proguard.sh',
+ '<(DEPTH)/build/android/gyp/util/build_utils.py',
+ '<(DEPTH)/build/android/gyp/proguard.py',
+ '<(javac_jar_path)',
+ '<(proguard_config)',
+ ],
+ 'outputs': [
+ '<(jar_path)',
+ ],
+ 'action': [
+ 'python', '<(DEPTH)/build/android/gyp/proguard.py',
+ '--proguard-path=<(android_sdk_root)/tools/proguard/bin/proguard.sh',
+ '--input-path=<(javac_jar_path)',
+ '--output-path=<(jar_path)',
+ '--proguard-config=<(proguard_config)',
+ '--classpath=<(android_sdk_jar) >(input_jars_paths)',
+
+ # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
+ '--ignore=>!(echo \'>(_inputs)\' | md5sum)',
+ ]
+ },
+ ],
+ }],
],
'actions': [
{
@@ -263,12 +307,12 @@
'<(compile_stamp)',
],
'outputs': [
- '<(jar_path)',
+ '<(javac_jar_path)',
],
'action': [
'python', '<(DEPTH)/build/android/gyp/jar.py',
'--classes-dir=<(classes_dir)',
- '--jar-path=<(jar_path)',
+ '--jar-path=<(javac_jar_path)',
'--excluded-classes=<(jar_excluded_classes)',
# TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
diff --git a/third_party/guava/guava.gyp b/third_party/guava/guava.gyp
index bfe2a30..e300460 100644
--- a/third_party/guava/guava.gyp
+++ b/third_party/guava/guava.gyp
@@ -9,6 +9,8 @@
'type': 'none',
'variables': {
'java_in_dir': 'src/guava',
+ 'proguard_preprocess': 1,
+ 'proguard_config': 'proguard.flags',
},
'dependencies': [
'../../third_party/jsr-305/jsr-305.gyp:jsr_305_javalib',
diff --git a/third_party/guava/proguard.flags b/third_party/guava/proguard.flags
new file mode 100644
index 0000000..015d703
--- /dev/null
+++ b/third_party/guava/proguard.flags
@@ -0,0 +1,33 @@
+# Copyright 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+-keep class com.google.common.base.** {
+ *;
+}
+
+-keep class com.google.common.annotations.** {
+ *;
+}
+
+-keep class com.google.common.collect.** {
+ *;
+}
+
+-keepattributes Signature
+
+# Don't complain about usage of sun.misc.Unsafe. Guava imports this,
+# but does not use it unless it exists.
+# The gyp-target that uses this is guava.gyp:guava_javalib.
+-dontwarn sun.misc.Unsafe
+# Striped64 uses reflection to access some local fields.
+-dontnote com.google.common.cache.Striped64
+-dontnote com.google.common.cache.Striped64$Cell
+
+# Keep all enum values and valueOf methods. See
+# http://proguard.sourceforge.net/index.html#manual/examples.html
+# for the reason for this. Also, see http://crbug.com/248037.
+-keepclassmembers enum * {
+ public static **[] values();
+ public static ** valueOf(java.lang.String);
+}