From 2d05d10362fd6a360a2447eebb6138ff05757ec2 Mon Sep 17 00:00:00 2001 From: Googler Date: Wed, 22 Nov 2017 10:21:00 -0800 Subject: Don't propagate resources when neverlink is specified and manifest is not We already handle this properly in the normal case. However, when no attributes from the new implementation of resource processing are specified, we fall back to the old version, which didn't handle this. RELNOTES: none PiperOrigin-RevId: 176672081 --- .../lib/rules/android/AndroidConfiguration.java | 17 +++++++++++++++++ .../build/lib/rules/android/AndroidLibrary.java | 9 ++++++--- .../build/lib/rules/android/AndroidBinaryTest.java | 21 +++++++++++++++++++-- 3 files changed, 42 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java index 6b48275d3f..e4b8c4d845 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidConfiguration.java @@ -670,6 +670,17 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { ) public boolean inheritResourcesInTests; + @Option( + name = "android_fixed_resource_neverlinking", + defaultValue = "false", + documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, + effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS}, + help = "If true, resources will properly not get propagated through neverlinked libraries." + + " Otherwise, the old behavior of propagating those resources if no resource-related" + + " attributes are specified in the neverlink library will be preserved." + ) + public boolean fixedResourceNeverlinking; + @Override public FragmentOptions getHost() { Options host = (Options) super.getHost(); @@ -753,6 +764,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { private final boolean allowResourcesAttr; private final boolean inheritResourcesInTests; private final boolean skipParsingAction; + private final boolean fixedResourceNeverlinking; AndroidConfiguration(Options options) throws InvalidConfigurationException { @@ -791,6 +803,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { this.allowResourcesAttr = options.allowResourcesAttr; this.inheritResourcesInTests = options.inheritResourcesInTests; this.skipParsingAction = options.skipParsingAction; + this.fixedResourceNeverlinking = options.fixedResourceNeverlinking; if (!dexoptsSupportedInIncrementalDexing.contains("--no-locals")) { // TODO(bazel-team): Still needed? See DexArchiveAspect @@ -954,6 +967,10 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { return this.skipParsingAction; } + public boolean fixedResourceNeverlinking() { + return this.fixedResourceNeverlinking; + } + @Override public void addGlobalMakeVariables(ImmutableMap.Builder globalMakeEnvBuilder) { globalMakeEnvBuilder.put("ANDROID_CPU", cpu); diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java index 4a4ce729ce..d5bd4cb0b6 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidLibrary.java @@ -218,11 +218,14 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory { return null; } } else { - resourceApk = ResourceApk.fromTransitiveResources( - ResourceDependencies.fromRuleResourceAndDeps(ruleContext, false /* neverlink */)); + resourceApk = + ResourceApk.fromTransitiveResources( + ResourceDependencies.fromRuleResourceAndDeps( + ruleContext, + ruleContext.getFragment(AndroidConfiguration.class).fixedResourceNeverlinking() + && JavaCommon.isNeverLink(ruleContext))); } - JavaTargetAttributes javaTargetAttributes = androidCommon.init( javaSemantics, androidSemantics, 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 54808d2665..638344b945 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 @@ -1019,9 +1019,14 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { @Test public void testNeverlinkTransitivity() throws Exception { - scratch.file("java/com/google/android/neversayneveragain/BUILD", + useConfiguration("--android_fixed_resource_neverlinking"); + + scratch.file( + "java/com/google/android/neversayneveragain/BUILD", "android_library(name = 'l1',", - " srcs = ['l1.java'])", + " srcs = ['l1.java'],", + " manifest = 'AndroidManifest.xml',", + " resource_files = ['res/values/resource.xml'])", "android_library(name = 'l2',", " srcs = ['l2.java'],", " deps = [':l1'],", @@ -1056,6 +1061,10 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { "java/com/google/android/neversayneveragain/libl4.jar_desugared.jar"); assertThat(b1Inputs).contains( "java/com/google/android/neversayneveragain/libb1.jar_desugared.jar"); + assertThat( + resourceInputPaths( + "java/com/google/android/neversayneveragain", getResourceContainer(b1))) + .doesNotContain("res/values/resource.xml"); ConfiguredTarget b2 = getConfiguredTarget("//java/com/google/android/neversayneveragain:b2"); Action b2DeployAction = actionsTestUtil().getActionForArtifactEndingWith( @@ -1069,6 +1078,10 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { assertThat(b2Inputs).containsAllOf( "java/com/google/android/neversayneveragain/_dx/l3/libl3.jar_desugared.jar", "java/com/google/android/neversayneveragain/libb2.jar_desugared.jar"); + assertThat( + resourceInputPaths( + "java/com/google/android/neversayneveragain", getResourceContainer(b2))) + .doesNotContain("res/values/resource.xml"); ConfiguredTarget b3 = getConfiguredTarget("//java/com/google/android/neversayneveragain:b3"); Action b3DeployAction = actionsTestUtil().getActionForArtifactEndingWith( @@ -1082,6 +1095,10 @@ public class AndroidBinaryTest extends AndroidBuildViewTestCase { "java/com/google/android/neversayneveragain/libb3.jar_desugared.jar"); assertThat(b3Inputs) .doesNotContain("java/com/google/android/neversayneveragain/libl2.jar_desugared.jar"); + assertThat( + resourceInputPaths( + "java/com/google/android/neversayneveragain", getResourceContainer(b3))) + .contains("res/values/resource.xml"); } @Test -- cgit v1.2.3