diff options
author | 2017-11-17 12:28:22 -0800 | |
---|---|---|
committer | 2017-11-17 12:30:30 -0800 | |
commit | a13ac58a88dff1e0ddc35107af77aee46f240f6f (patch) | |
tree | ee4548115819466208cbc5f12e3743eee9cbf4dd /src/test | |
parent | a90a976418e31922749d20e0caaa19cfe129ddbd (diff) |
Shard android_integration_test's sdk, proguard and aar tests out to improve performance.
Shaves ~30-40 seconds off the critical path. The critical path is now dominated by the NDK test, but that's out of scope for this change. See below for data.
BEFORE:
$ bazel test //src/test/shell/bazel/android:android_integration_test
INFO: Analysed target //src/test/shell/bazel/android:android_integration_test (0 packages loaded).
INFO: Found 1 test target...
[4 / 5] Testing //src/test/shell/bazel/android:android_integration_test; 23s linux-sandbox
Target //src/test/shell/bazel/android:android_integration_test up-to-date:
/tmp/bazel-bin/src/test/shell/bazel/android/android_integration_test
INFO: Elapsed time: 93.696s, Critical Path: 93.37s
INFO: Build completed successfully, 2 total actions
//src/test/shell/bazel/android:android_integration_test PASSED in 93.4s
AFTER:
$ bazel test :all --nocache_test_results
WARNING: The major revision of the Android NDK referenced by android_ndk_repository rule 'androidndk' is 15. The major revisions supported by Bazel are [10, 11, 12, 13, 14]. Defaulting to revision 14.
WARNING: API level 26 specified by android_ndk_repository 'androidndk' is not available. Using latest known API level 25
INFO: Analysed 9 targets (0 packages loaded).
INFO: Found 2 targets and 7 test targets...
INFO: Elapsed time: 106.452s, Critical Path: 105.66s
INFO: Build completed successfully, 8 total actions
//src/test/shell/bazel/android:aidl_integration_test PASSED in 43.9s
//src/test/shell/bazel/android:android_integration_test PASSED in 55.1s
//src/test/shell/bazel/android:android_ndk_integration_test PASSED in 105.6s
//src/test/shell/bazel/android:android_sdk_integration_test PASSED in 68.4s
//src/test/shell/bazel/android:desugarer_integration_test PASSED in 43.9s
//src/test/shell/bazel/android:proguard_integration_test PASSED in 43.7s
//src/test/shell/bazel/android:resources_integration_test PASSED in 51.4s
Executed 7 out of 7 tests: 7 tests pass.
RELNOTES: None.
PiperOrigin-RevId: 176144822
Diffstat (limited to 'src/test')
9 files changed, 425 insertions, 251 deletions
diff --git a/src/test/shell/bazel/android/BUILD b/src/test/shell/bazel/android/BUILD index f8928ddd16..d371b041ac 100644 --- a/src/test/shell/bazel/android/BUILD +++ b/src/test/shell/bazel/android/BUILD @@ -17,12 +17,51 @@ filegroup( # tools/android/android_sdk_repository_template.bzl and # src/main/java/com/google/devtools/build/lib/bazel/rules/android/android_ndk_build_file_template.txt +sh_library( + name = "android_helper", + srcs = ["android_helper.sh"], + data = ["sample.aar"], +) + sh_test( name = "android_integration_test", - size = "large", + size = "medium", srcs = ["android_integration_test.sh"], data = [ - "sample.aar", + ":android_helper", + "//external:android_sdk_for_testing", + "//src/test/shell/bazel:test-deps", + ], +) + +sh_test( + name = "aar_integration_test", + size = "medium", + srcs = ["aar_integration_test.sh"], + data = [ + ":android_helper", + "//external:android_sdk_for_testing", + "//src/test/shell/bazel:test-deps", + ], +) + +sh_test( + name = "proguard_integration_test", + size = "medium", + srcs = ["proguard_integration_test.sh"], + data = [ + ":android_helper", + "//external:android_sdk_for_testing", + "//src/test/shell/bazel:test-deps", + ], +) + +sh_test( + name = "android_sdk_integration_test", + size = "medium", + srcs = ["android_sdk_integration_test.sh"], + data = [ + ":android_helper", "//external:android_sdk_for_testing", "//src/test/shell/bazel:test-deps", ], @@ -30,9 +69,10 @@ sh_test( sh_test( name = "android_ndk_integration_test", - size = "large", + size = "medium", srcs = ["android_ndk_integration_test.sh"], data = [ + ":android_helper", "//external:android_ndk_for_testing", "//external:android_sdk_for_testing", "//src/test/shell/bazel:test-deps", @@ -41,9 +81,10 @@ sh_test( sh_test( name = "aidl_integration_test", - size = "large", + size = "medium", srcs = ["aidl_integration_test.sh"], data = [ + ":android_helper", "//external:android_sdk_for_testing", "//src/test/shell/bazel:test-deps", ], @@ -51,9 +92,10 @@ sh_test( sh_test( name = "desugarer_integration_test", - size = "large", + size = "medium", srcs = ["desugarer_integration_test.sh"], data = [ + ":android_helper", "//external:android_sdk_for_testing", "//src/test/shell/bazel:test-deps", ], diff --git a/src/test/shell/bazel/android/aar_integration_test.sh b/src/test/shell/bazel/android/aar_integration_test.sh new file mode 100755 index 0000000000..7ecd3c08a2 --- /dev/null +++ b/src/test/shell/bazel/android/aar_integration_test.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For these tests to run do the following: +# +# 1. Install an Android SDK from https://developer.android.com +# 2. Set the $ANDROID_HOME environment variable +# 3. Uncomment the line in WORKSPACE containing android_sdk_repository +# +# Note that if the environment is not set up as above android_integration_test +# will silently be ignored and will be shown as passing. + +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source "${CURRENT_DIR}/android_helper.sh" \ + || { echo "android_helper.sh not found!" >&2; exit 1; } +fail_if_no_android_sdk + +source "${CURRENT_DIR}/../../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } + +# Regression test for https://github.com/bazelbuild/bazel/issues/1928. +function test_empty_tree_artifact_action_inputs_mount_empty_directories() { + create_new_workspace + setup_android_sdk_support + cat > AndroidManifest.xml <<EOF +<manifest package="com.test"/> +EOF + mkdir res + zip test.aar AndroidManifest.xml res/ + cat > BUILD <<EOF +aar_import( + name = "test", + aar = "test.aar", +) +EOF + # Building aar_import invokes the AndroidResourceProcessingAction with a + # TreeArtifact of the AAR resources as the input. Since there are no + # resources, the Bazel sandbox should create an empty directory. If the + # directory is not created, the action thinks that its inputs do not exist and + # crashes. + bazel build :test +} + +function test_nonempty_aar_resources_tree_artifact() { + create_new_workspace + setup_android_sdk_support + cat > AndroidManifest.xml <<EOF +<manifest package="com.test"/> +EOF + mkdir -p res/values + cat > res/values/values.xml <<EOF +<?xml version="1.0" encoding="utf-8"?> +<resources xmlns:android="http://schemas.android.com/apk/res/android"> +</resources> +EOF + zip test.aar AndroidManifest.xml res/values/values.xml + cat > BUILD <<EOF +aar_import( + name = "test", + aar = "test.aar", +) +EOF + bazel build :test +} + +run_suite "aar_import integration tests" diff --git a/src/test/shell/bazel/android/aidl_integration_test.sh b/src/test/shell/bazel/android/aidl_integration_test.sh index a74b6a20b3..9e7482a08a 100755 --- a/src/test/shell/bazel/android/aidl_integration_test.sh +++ b/src/test/shell/bazel/android/aidl_integration_test.sh @@ -15,6 +15,11 @@ # limitations under the License. CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source "${CURRENT_DIR}/android_helper.sh" \ + || { echo "android_helper.sh not found!" >&2; exit 1; } +fail_if_no_android_sdk + source "${CURRENT_DIR}/../../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } @@ -64,9 +69,4 @@ EOF || fail "build failed" } -if [[ ! -r "${TEST_SRCDIR}/androidsdk" ]]; then - echo "Not running Android tests due to lack of an Android SDK." - exit 0 -fi - run_suite "Android IDL tests" diff --git a/src/test/shell/bazel/android/android_helper.sh b/src/test/shell/bazel/android/android_helper.sh new file mode 100755 index 0000000000..826d966297 --- /dev/null +++ b/src/test/shell/bazel/android/android_helper.sh @@ -0,0 +1,84 @@ +#!/bin/bash +# +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +function fail_if_no_android_sdk() { + if [[ ! -d "${TEST_SRCDIR}/androidsdk" ]]; then + echo "Not running Android tests due to lack of an Android SDK." + exit 1 + fi +} + +function fail_if_no_android_ndk() { + # ndk r10 and earlier + if [[ ! -r "${TEST_SRCDIR}/androidndk/ndk/RELEASE.TXT" ]]; then + # ndk r11 and later + if [[ ! -r "${TEST_SRCDIR}/androidndk/ndk/source.properties" ]]; then + echo "Not running Android NDK tests due to lack of an Android NDK." + exit 1 + fi + fi +} + +function create_android_binary() { + mkdir -p java/bazel + cat > java/bazel/BUILD <<EOF +aar_import( + name = "aar", + aar = "sample.aar", +) +android_library( + name = "lib", + srcs = ["Lib.java"], + deps = [":aar"], +) +android_binary( + name = "bin", + srcs = ["MainActivity.java"], + manifest = "AndroidManifest.xml", + deps = [":lib"], +) +EOF + + cp "${TEST_SRCDIR}/io_bazel/src/test/shell/bazel/android/sample.aar" \ + java/bazel/sample.aar + cat > java/bazel/AndroidManifest.xml <<EOF + <manifest package="bazel.android" /> +EOF + + cat > java/bazel/Lib.java <<EOF +package bazel; +import com.sample.aar.Sample; +public class Lib { + public static String message() { + return "Hello Lib" + Sample.getZero(); + } +} +EOF + + cat > java/bazel/MainActivity.java <<EOF +package bazel; + +import android.app.Activity; +import android.os.Bundle; + +public class MainActivity extends Activity { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } +} +EOF +} diff --git a/src/test/shell/bazel/android/android_integration_test.sh b/src/test/shell/bazel/android/android_integration_test.sh index 23ea519af0..557816083b 100755 --- a/src/test/shell/bazel/android/android_integration_test.sh +++ b/src/test/shell/bazel/android/android_integration_test.sh @@ -25,60 +25,13 @@ # Load the test setup defined in the parent directory CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -source "${CURRENT_DIR}/../../integration_test_setup.sh" \ - || { echo "integration_test_setup.sh not found!" >&2; exit 1; } - - -function create_android_binary() { - mkdir -p java/bazel - cat > java/bazel/BUILD <<EOF -aar_import( - name = "aar", - aar = "sample.aar", -) -android_library( - name = "lib", - srcs = ["Lib.java"], - deps = [":aar"], -) -android_binary( - name = "bin", - srcs = ["MainActivity.java"], - manifest = "AndroidManifest.xml", - deps = [":lib"], -) -EOF - - cp "${TEST_SRCDIR}/io_bazel/src/test/shell/bazel/android/sample.aar" \ - java/bazel/sample.aar - cat > java/bazel/AndroidManifest.xml <<EOF - <manifest package="bazel.android" /> -EOF - - cat > java/bazel/Lib.java <<EOF -package bazel; -import com.sample.aar.Sample; -public class Lib { - public static String message() { - return "Hello Lib" + Sample.getZero(); - } -} -EOF - - cat > java/bazel/MainActivity.java <<EOF -package bazel; -import android.app.Activity; -import android.os.Bundle; +source "${CURRENT_DIR}/android_helper.sh" \ + || { echo "android_helper.sh not found!" >&2; exit 1; } +fail_if_no_android_sdk -public class MainActivity extends Activity { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - } -} -EOF -} +source "${CURRENT_DIR}/../../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } function test_sdk_library_deps() { create_new_workspace @@ -95,119 +48,6 @@ EOF bazel build --nobuild //java/a:a || fail "build failed" } -# Regression test for https://github.com/bazelbuild/bazel/issues/1928. -function test_empty_tree_artifact_action_inputs_mount_empty_directories() { - create_new_workspace - setup_android_sdk_support - cat > AndroidManifest.xml <<EOF -<manifest package="com.test"/> -EOF - mkdir res - zip test.aar AndroidManifest.xml res/ - cat > BUILD <<EOF -aar_import( - name = "test", - aar = "test.aar", -) -EOF - # Building aar_import invokes the AndroidResourceProcessingAction with a - # TreeArtifact of the AAR resources as the input. Since there are no - # resources, the Bazel sandbox should create an empty directory. If the - # directory is not created, the action thinks that its inputs do not exist and - # crashes. - bazel build :test -} - -function test_nonempty_aar_resources_tree_artifact() { - create_new_workspace - setup_android_sdk_support - cat > AndroidManifest.xml <<EOF -<manifest package="com.test"/> -EOF - mkdir -p res/values - cat > res/values/values.xml <<EOF -<?xml version="1.0" encoding="utf-8"?> -<resources xmlns:android="http://schemas.android.com/apk/res/android"> -</resources> -EOF - zip test.aar AndroidManifest.xml res/values/values.xml - cat > BUILD <<EOF -aar_import( - name = "test", - aar = "test.aar", -) -EOF - bazel build :test -} - -function test_android_sdk_repository_path_from_environment() { - create_new_workspace - setup_android_sdk_support - # Overwrite WORKSPACE that was created by setup_android_sdk_support with one - # that does not set the path attribute of android_sdk_repository. - cat > WORKSPACE <<EOF -android_sdk_repository( - name = "androidsdk", -) -EOF - ANDROID_HOME=$ANDROID_SDK bazel build @androidsdk//:files || fail \ - "android_sdk_repository failed to build with \$ANDROID_HOME instead of " \ - "path" -} - -function test_android_sdk_repository_no_path_or_android_home() { - create_new_workspace - cat > WORKSPACE <<EOF -android_sdk_repository( - name = "androidsdk", - api_level = 25, -) -EOF - bazel build @androidsdk//:files >& $TEST_log && fail "Should have failed" - expect_log "Either the path attribute of android_sdk_repository" -} - -function test_android_sdk_repository_wrong_path() { - create_new_workspace - mkdir "$TEST_SRCDIR/some_dir" - cat > WORKSPACE <<EOF -android_sdk_repository( - name = "androidsdk", - api_level = 25, - path = "$TEST_SRCDIR/some_dir", -) -EOF - bazel build @androidsdk//:files >& $TEST_log && fail "Should have failed" - expect_log "Unable to read the Android SDK at $TEST_SRCDIR/some_dir, the path may be invalid." \ - " Is the path in android_sdk_repository() or \$ANDROID_SDK_HOME set correctly?" -} - -# Check that the build succeeds if an android_sdk is specified with --android_sdk -function test_specifying_android_sdk_flag() { - create_new_workspace - setup_android_sdk_support - create_android_binary - cat > WORKSPACE <<EOF -android_sdk_repository( - name = "a", -) -EOF - ANDROID_HOME=$ANDROID_SDK bazel build --android_sdk=@a//:sdk-24 \ - //java/bazel:bin || fail "build with --android_sdk failed" -} - -# Regression test for https://github.com/bazelbuild/bazel/issues/2621. -function test_android_sdk_repository_returns_null_if_env_vars_missing() { - create_new_workspace - setup_android_sdk_support - ANDROID_HOME=/does_not_exist_1 bazel build @androidsdk//:files || \ - fail "Build failed" - sed -i -e 's/path =/#path =/g' WORKSPACE - ANDROID_HOME=/does_not_exist_2 bazel build @androidsdk//:files && \ - fail "Build should have failed" - ANDROID_HOME=$ANDROID_SDK bazel build @androidsdk//:files || "Build failed" -} - function test_allow_custom_manifest_name() { create_new_workspace setup_android_sdk_support @@ -221,61 +61,4 @@ 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 -fi - run_suite "Android integration tests" diff --git a/src/test/shell/bazel/android/android_ndk_integration_test.sh b/src/test/shell/bazel/android/android_ndk_integration_test.sh index 920fa9d480..08de4df265 100755 --- a/src/test/shell/bazel/android/android_ndk_integration_test.sh +++ b/src/test/shell/bazel/android/android_ndk_integration_test.sh @@ -27,6 +27,12 @@ # Load the test setup defined in the parent directory CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source "${CURRENT_DIR}/android_helper.sh" \ + || { echo "android_helper.sh not found!" >&2; exit 1; } +fail_if_no_android_sdk +fail_if_no_android_ndk + source "${CURRENT_DIR}/../../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } @@ -298,18 +304,4 @@ EOF " Is the path in android_ndk_repository() or \$ANDROID_NDK_HOME set correctly?" } -# ndk r10 and earlier -if [[ ! -r "${TEST_SRCDIR}/androidndk/ndk/RELEASE.TXT" ]]; then - # ndk r11 and later - if [[ ! -r "${TEST_SRCDIR}/androidndk/ndk/source.properties" ]]; then - echo "Not running Android NDK tests due to lack of an Android NDK." - exit 0 - fi -fi - -if [[ ! -d "${TEST_SRCDIR}/androidsdk" ]]; then - echo "Not running Android NDK tests due to lack of an Android SDK." - exit 0 -fi - run_suite "Android NDK integration tests" diff --git a/src/test/shell/bazel/android/android_sdk_integration_test.sh b/src/test/shell/bazel/android/android_sdk_integration_test.sh new file mode 100755 index 0000000000..27f1905e7b --- /dev/null +++ b/src/test/shell/bazel/android/android_sdk_integration_test.sh @@ -0,0 +1,104 @@ +#!/bin/bash +# +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For these tests to run do the following: +# +# 1. Install an Android SDK from https://developer.android.com +# 2. Set the $ANDROID_HOME environment variable +# 3. Uncomment the line in WORKSPACE containing android_sdk_repository +# +# Note that if the environment is not set up as above android_integration_test +# will silently be ignored and will be shown as passing. + +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source "${CURRENT_DIR}/android_helper.sh" \ + || { echo "android_helper.sh not found!" >&2; exit 1; } +fail_if_no_android_sdk + +source "${CURRENT_DIR}/../../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } + +function test_android_sdk_repository_path_from_environment() { + create_new_workspace + setup_android_sdk_support + # Overwrite WORKSPACE that was created by setup_android_sdk_support with one + # that does not set the path attribute of android_sdk_repository. + cat > WORKSPACE <<EOF +android_sdk_repository( + name = "androidsdk", +) +EOF + ANDROID_HOME=$ANDROID_SDK bazel build @androidsdk//:files || fail \ + "android_sdk_repository failed to build with \$ANDROID_HOME instead of " \ + "path" +} + +function test_android_sdk_repository_no_path_or_android_home() { + create_new_workspace + cat > WORKSPACE <<EOF +android_sdk_repository( + name = "androidsdk", + api_level = 25, +) +EOF + bazel build @androidsdk//:files >& $TEST_log && fail "Should have failed" + expect_log "Either the path attribute of android_sdk_repository" +} + +function test_android_sdk_repository_wrong_path() { + create_new_workspace + mkdir "$TEST_SRCDIR/some_dir" + cat > WORKSPACE <<EOF +android_sdk_repository( + name = "androidsdk", + api_level = 25, + path = "$TEST_SRCDIR/some_dir", +) +EOF + bazel build @androidsdk//:files >& $TEST_log && fail "Should have failed" + expect_log "Unable to read the Android SDK at $TEST_SRCDIR/some_dir, the path may be invalid." \ + " Is the path in android_sdk_repository() or \$ANDROID_SDK_HOME set correctly?" +} + +# Check that the build succeeds if an android_sdk is specified with --android_sdk +function test_specifying_android_sdk_flag() { + create_new_workspace + setup_android_sdk_support + create_android_binary + cat > WORKSPACE <<EOF +android_sdk_repository( + name = "a", +) +EOF + ANDROID_HOME=$ANDROID_SDK bazel build --android_sdk=@a//:sdk-24 \ + //java/bazel:bin || fail "build with --android_sdk failed" +} + +# Regression test for https://github.com/bazelbuild/bazel/issues/2621. +function test_android_sdk_repository_returns_null_if_env_vars_missing() { + create_new_workspace + setup_android_sdk_support + ANDROID_HOME=/does_not_exist_1 bazel build @androidsdk//:files || \ + fail "Build failed" + sed -i -e 's/path =/#path =/g' WORKSPACE + ANDROID_HOME=/does_not_exist_2 bazel build @androidsdk//:files && \ + fail "Build should have failed" + ANDROID_HOME=$ANDROID_SDK bazel build @androidsdk//:files || "Build failed" +} + +run_suite "Android integration tests for SDK" diff --git a/src/test/shell/bazel/android/desugarer_integration_test.sh b/src/test/shell/bazel/android/desugarer_integration_test.sh index 1dda424980..c51d3da2e9 100755 --- a/src/test/shell/bazel/android/desugarer_integration_test.sh +++ b/src/test/shell/bazel/android/desugarer_integration_test.sh @@ -21,6 +21,11 @@ # more details. CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source "${CURRENT_DIR}/android_helper.sh" \ + || { echo "android_helper.sh not found!" >&2; exit 1; } +fail_if_no_android_sdk + source "${CURRENT_DIR}/../../integration_test_setup.sh" \ || { echo "integration_test_setup.sh not found!" >&2; exit 1; } @@ -81,9 +86,4 @@ function test_java_8_android_binary() { || fail "build failed" } -if [[ ! -d "${TEST_SRCDIR}/androidsdk" ]]; then - echo "Not running Android desugarer tests due to lack of an Android SDK." - exit 0 -fi - run_suite "Android desugarer integration tests" diff --git a/src/test/shell/bazel/android/proguard_integration_test.sh b/src/test/shell/bazel/android/proguard_integration_test.sh new file mode 100755 index 0000000000..0fb1e2eb1f --- /dev/null +++ b/src/test/shell/bazel/android/proguard_integration_test.sh @@ -0,0 +1,88 @@ +#!/bin/bash +# +# Copyright 2017 The Bazel Authors. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# For these tests to run do the following: +# +# 1. Install an Android SDK from https://developer.android.com +# 2. Set the $ANDROID_HOME environment variable +# 3. Uncomment the line in WORKSPACE containing android_sdk_repository +# +# Note that if the environment is not set up as above android_integration_test +# will silently be ignored and will be shown as passing. + +# Load the test setup defined in the parent directory +CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +source "${CURRENT_DIR}/android_helper.sh" \ + || { echo "android_helper.sh not found!" >&2; exit 1; } +fail_if_no_android_sdk + +source "${CURRENT_DIR}/../../integration_test_setup.sh" \ + || { echo "integration_test_setup.sh not found!" >&2; exit 1; } + +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" +} + +run_suite "Android integration tests for Proguard" |