diff options
author | ajmichael <ajmichael@google.com> | 2017-10-30 11:57:46 -0400 |
---|---|---|
committer | John Cater <jcater@google.com> | 2017-10-31 10:36:54 -0400 |
commit | 5df4759783be1bf6ef54754171e34732aa77d7ba (patch) | |
tree | a7cc2f21f10d6d80676936f818be92475e09b58f /src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java | |
parent | fadeb90a05321195a969ae526ee8cbfea5db6cc6 (diff) |
Make AndroidRuleClasses#hasProguardSpecs less fragile.
Keeps the semantics the same.
RELNOTES: None
PiperOrigin-RevId: 173899927
Diffstat (limited to 'src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java')
-rw-r--r-- | src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java index 8793c07a57..a9d892c79f 100644 --- a/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java +++ b/src/test/java/com/google/devtools/build/lib/rules/android/AndroidBinaryTest.java @@ -13,6 +13,7 @@ // limitations under the License. package com.google.devtools.build.lib.rules.android; +import static com.google.common.collect.ImmutableList.toImmutableList; import static com.google.common.collect.Iterables.getOnlyElement; import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; @@ -40,6 +41,8 @@ import com.google.devtools.build.lib.analysis.actions.SpawnAction; import com.google.devtools.build.lib.cmdline.RepositoryName; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.packages.BuildType; +import com.google.devtools.build.lib.packages.FileTarget; +import com.google.devtools.build.lib.packages.Rule; import com.google.devtools.build.lib.packages.util.BazelMockAndroidSupport; import com.google.devtools.build.lib.rules.android.AndroidRuleClasses.MultidexMode; import com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo; @@ -2330,17 +2333,24 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { // regression test for b/14288948 @Test public void testEmptyListAsProguardSpec() throws Exception { - scratchConfiguredTarget("java/foo", "abin", + scratch.file( + "java/foo/BUILD", "android_binary(", " name = 'abin',", " srcs = ['a.java'],", " proguard_specs = [],", " manifest = 'AndroidManifest.xml')"); + Rule rule = getTarget("//java/foo:abin").getAssociatedRule(); + assertNoEvents(); + ImmutableList<String> implicitOutputFilenames = + rule.getOutputFiles().stream().map(FileTarget::getName).collect(toImmutableList()); + assertThat(implicitOutputFilenames).doesNotContain("abin_proguard.jar"); } @Test public void testConfigurableProguardSpecsEmptyList() throws Exception { - scratchConfiguredTarget("java/foo", "abin", + scratch.file( + "java/foo/BUILD", "android_binary(", " name = 'abin',", " srcs = ['a.java'],", @@ -2348,7 +2358,11 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { " '" + BuildType.Selector.DEFAULT_CONDITION_KEY + "': [],", " }),", " manifest = 'AndroidManifest.xml')"); + Rule rule = getTarget("//java/foo:abin").getAssociatedRule(); assertNoEvents(); + ImmutableList<String> implicitOutputFilenames = + rule.getOutputFiles().stream().map(FileTarget::getName).collect(toImmutableList()); + assertThat(implicitOutputFilenames).contains("abin_proguard.jar"); } @Test @@ -3810,4 +3824,44 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { AndroidInstrumentationInfo provider = b1.get(AndroidInstrumentationInfo.PROVIDER); assertThat(provider).isNull(); } + + /** + * 'proguard_specs' attribute gets read by an implicit outputs function: the + * current heuristic is that if this attribute is configurable, we assume its + * contents are non-empty and thus create the mybinary_proguard.jar output. + * Test that here. + */ + @Test + public void testConfigurableProguardSpecs() throws Exception { + scratch.file("conditions/BUILD", + "config_setting(", + " name = 'a',", + " values = {'test_arg': 'a'})", + "config_setting(", + " name = 'b',", + " values = {'test_arg': 'b'})"); + scratchConfiguredTarget("java/foo", "abin", + "android_binary(", + " name = 'abin',", + " srcs = ['a.java'],", + " proguard_specs = select({", + " '//conditions:a': [':file1.pro'],", + " '//conditions:b': [],", + " '//conditions:default': [':file3.pro'],", + " }) + [", + // Add a long list here as a regression test for b/68238721 + " 'file4.pro',", + " 'file5.pro',", + " 'file6.pro',", + " 'file7.pro',", + " 'file8.pro',", + " ],", + " manifest = 'AndroidManifest.xml')"); + checkProguardUse( + "//java/foo:abin", + "abin_proguard.jar", + /*expectMapping=*/ false, + /*passes=*/ null, + getAndroidJarPath()); + } } |