aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar ajmichael <ajmichael@google.com>2017-10-05 18:21:49 +0200
committerGravatar Klaus Aehlig <aehlig@google.com>2017-10-06 19:47:10 +0200
commita784c8fc3a7b812bd2f4d9cfa9fdc1c9695ada13 (patch)
tree45a4f1d7879759a540c97a91065891b0eace87b7 /src
parent334d2f155d85fca1797e249dc0acf2c47be089b0 (diff)
Use bundled proguard 5.3.3 instead of 4.7 from the SDK
Fixes https://github.com/bazelbuild/bazel/issues/3777 Also adds a proguard integration test so that hopefully we notice next time it breaks. RELNOTES: Updated Android proguard to 5.3.3. It now works with android-24+. PiperOrigin-RevId: 171162295
Diffstat (limited to 'src')
-rw-r--r--src/BUILD1
-rw-r--r--src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java4
-rwxr-xr-xsrc/test/shell/bazel/android/android_integration_test.sh52
-rw-r--r--src/test/shell/unittest.bash18
4 files changed, 75 insertions, 0 deletions
diff --git a/src/BUILD b/src/BUILD
index 7c79e6737a..cb4d0bf1d5 100644
--- a/src/BUILD
+++ b/src/BUILD
@@ -145,6 +145,7 @@ py_binary(
"//third_party/java/j2objc:embedded_tools_srcs",
"//third_party/java/jarjar:embedded_tools_srcs",
"//third_party/java/jdk/langtools:test-srcs",
+ "//third_party/java/proguard:embedded_tools",
"//third_party/py/concurrent:srcs",
"//third_party/py/gflags:srcs",
"//third_party/py/six:srcs",
diff --git a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
index bde6e37421..d77d04bce5 100644
--- a/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
+++ b/src/test/java/com/google/devtools/build/lib/analysis/mock/BazelAnalysisMock.java
@@ -113,6 +113,10 @@ public final class BazelAnalysisMock extends AnalysisMock {
config.create(
"/bazel_tools_workspace/tools/android/emulator/BUILD",
Iterables.toArray(createToolsAndroidEmulatorContents(), String.class));
+ // Bundled Proguard used by android_sdk_repository
+ config.create(
+ "/bazel_tools_workspace/third_party/java/proguard/BUILD",
+ "exports_files(['proguard'])");
config.create(
"/bazel_tools_workspace/tools/genrule/BUILD", "exports_files(['genrule-setup.sh'])");
diff --git a/src/test/shell/bazel/android/android_integration_test.sh b/src/test/shell/bazel/android/android_integration_test.sh
index 0f6b8d23c3..965626ef6f 100755
--- a/src/test/shell/bazel/android/android_integration_test.sh
+++ b/src/test/shell/bazel/android/android_integration_test.sh
@@ -214,6 +214,58 @@ function test_allow_custom_manifest_name() {
"Failed to build android_binary with custom Android manifest file name"
}
+function test_proguard() {
+ create_new_workspace
+ setup_android_sdk_support
+ mkdir -p java/com/bin
+ cat > java/com/bin/BUILD <<EOF
+android_binary(
+ name = 'bin',
+ srcs = ['Bin.java', 'NotUsed.java'],
+ manifest = 'AndroidManifest.xml',
+ proguard_specs = ['proguard.config'],
+ deps = [':lib'],
+)
+android_library(
+ name = 'lib',
+ srcs = ['Lib.java'],
+)
+EOF
+ cat > java/com/bin/AndroidManifest.xml <<EOF
+<manifest package='com.bin' />
+EOF
+ cat > java/com/bin/Bin.java <<EOF
+package com.bin;
+public class Bin {
+ public Lib getLib() {
+ return new Lib();
+ }
+}
+EOF
+ cat > java/com/bin/NotUsed.java <<EOF
+package com.bin;
+public class NotUsed {}
+EOF
+ cat > java/com/bin/Lib.java <<EOF
+package com.bin;
+public class Lib {}
+EOF
+ cat > java/com/bin/proguard.config <<EOF
+-keep public class com.bin.Bin {
+ public *;
+}
+EOF
+ assert_build //java/com/bin
+ output_classes=$(zipinfo -1 bazel-bin/java/com/bin/bin_proguard.jar)
+ assert_equals 3 $(wc -w <<< $output_classes)
+ assert_one_of $output_classes "META-INF/MANIFEST.MF"
+ assert_one_of $output_classes "com/bin/Bin.class"
+ # Not kept by proguard
+ assert_not_one_of $output_classes "com/bin/Unused.class"
+ # This is renamed by proguard to something else
+ assert_not_one_of $output_classes "com/bin/Lib.class"
+}
+
if [[ ! -d "${TEST_SRCDIR}/androidsdk" ]]; then
echo "Not running Android tests due to lack of an Android SDK."
exit 0
diff --git a/src/test/shell/unittest.bash b/src/test/shell/unittest.bash
index b1e606b238..73a5974dc2 100644
--- a/src/test/shell/unittest.bash
+++ b/src/test/shell/unittest.bash
@@ -521,6 +521,24 @@ function assert_one_of() {
return 1
}
+# Usage: assert_not_one_of <expected_list>... <actual>
+# Asserts that actual is not one of the items in expected_list
+# Example: assert_not_one_of ( "foo", "bar", "baz" ) actualval
+function assert_not_one_of() {
+ local args=("$@")
+ local last_arg_index=$((${#args[@]} - 1))
+ local actual=${args[last_arg_index]}
+ unset args[last_arg_index]
+ for expected_item in "${args[@]}"; do
+ if [ "$expected_item" = "$actual" ]; then
+ fail "'${args[@]}' contains '$actual'"
+ return 1
+ fi
+ done;
+
+ return 0
+}
+
# Usage: assert_equals <expected> <actual>
# Asserts [ expected = actual ].
function assert_equals() {