diff options
author | Googler <noreply@google.com> | 2017-11-22 10:21:00 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-11-22 10:22:28 -0800 |
commit | 2d05d10362fd6a360a2447eebb6138ff05757ec2 (patch) | |
tree | 3d60dc0ffd5e8700927e96c65c10bcb0c757aa06 /src | |
parent | d55acc31ec7c731481a3691e6cf91c53869e9c67 (diff) |
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
Diffstat (limited to 'src')
3 files changed, 42 insertions, 5 deletions
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<String, String> 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 |