diff options
author | Googler <noreply@google.com> | 2017-09-14 23:06:51 +0200 |
---|---|---|
committer | Philipp Wollermann <philwo@google.com> | 2017-09-15 11:29:02 +0200 |
commit | 2e7b804d29f3c1fa979d8a226d62d970dada64e2 (patch) | |
tree | 47e4cdf94fc00f50f17367ad994672f93d5a3e02 /src/main/java/com/google/devtools/build/lib | |
parent | fe46788eaf91673916c12e83396277e00fd0a9bd (diff) |
Add whitelists for android_resources removal
Add additional tooling for removing android_resources
RELNOTES: none
PiperOrigin-RevId: 168741510
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
5 files changed, 18 insertions, 14 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD index 6b5460458e..e776f31e71 100644 --- a/src/main/java/com/google/devtools/build/lib/BUILD +++ b/src/main/java/com/google/devtools/build/lib/BUILD @@ -900,6 +900,7 @@ java_library( "//src/main/java/com/google/devtools/build/lib:skylarkinterface", "//src/main/java/com/google/devtools/build/lib:util", "//src/main/java/com/google/devtools/build/lib/actions", + "//src/main/java/com/google/devtools/build/lib/analysis/whitelisting", "//src/main/java/com/google/devtools/build/lib/collect", "//src/main/java/com/google/devtools/build/lib/collect/nestedset", "//src/main/java/com/google/devtools/build/lib/concurrent", diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java index 9f02f511c9..c45aeecc7e 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidBinary.java @@ -166,12 +166,7 @@ public abstract class AndroidBinary implements RuleConfiguredTargetFactory { ruleContext.throwWithRuleError("Data binding doesn't work with the \"resources\" attribute. " + "Use \"resource_files\" instead."); } - if (ruleContext.attributes().isAttributeValueExplicitlySpecified("resources") - && !ruleContext.getFragment(AndroidConfiguration.class).allowResourcesAttr()) { - ruleContext.throwWithAttributeError( - "resources", - "The resources attribute has been removed. Please use resource_files instead."); - } + AndroidCommon.validateResourcesAttribute(ruleContext); } private static RuleConfiguredTargetBuilder init( diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java index 40c5a61a6b..d590dd635c 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java @@ -34,6 +34,7 @@ import com.google.devtools.build.lib.analysis.actions.CustomCommandLine; import com.google.devtools.build.lib.analysis.actions.FileWriteAction; import com.google.devtools.build.lib.analysis.actions.SpawnAction; import com.google.devtools.build.lib.analysis.test.InstrumentedFilesCollector.InstrumentationSpec; +import com.google.devtools.build.lib.analysis.whitelisting.Whitelist; import com.google.devtools.build.lib.collect.IterablesChain; import com.google.devtools.build.lib.collect.nestedset.NestedSet; import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; @@ -114,6 +115,8 @@ public class AndroidCommon { return builder.build(); } + public static final String RESOURCES_WHITELIST_NAME = "android_resources"; + private final RuleContext ruleContext; private final JavaCommon javaCommon; private final boolean asNeverLink; @@ -1032,4 +1035,14 @@ public class AndroidCommon { } return supportApks.build(); } + + public static void validateResourcesAttribute(RuleContext ruleContext) throws RuleErrorException { + if (ruleContext.attributes().isAttributeValueExplicitlySpecified("resources") + && !ruleContext.getFragment(AndroidConfiguration.class).allowResourcesAttr() + && !Whitelist.isAvailable(ruleContext, RESOURCES_WHITELIST_NAME)) { + ruleContext.throwWithAttributeError( + "resources", + "The resources attribute has been removed. Please use resource_files instead."); + } + } } 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 0d8b70d105..efebcb0a35 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 @@ -729,7 +729,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS}, help = "For use in testing before migrating away from android_resources. If false, will" - + " fail when android_resources rules are encountered" + + " fail when non-whitelisted android_resources rules are encountered." ) public boolean allowAndroidResources; @@ -739,7 +739,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { documentationCategory = OptionDocumentationCategory.UNDOCUMENTED, effectTags = {OptionEffectTag.LOADING_AND_ANALYSIS}, help = "For use in testing before migrating away from android_resources. If false, will" - + " fail when android_resources rules are encountered" + + " fail when non-whitelisted instances of the 'resources' attribute are encountered." ) public boolean allowResourcesAttr; 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 4dac9c7654..649f1739ea 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 @@ -60,12 +60,7 @@ public abstract class AndroidLibrary implements RuleConfiguredTargetFactory { + "Use \"resource_files\" instead."); } - if (ruleContext.attributes().isAttributeValueExplicitlySpecified("resources") - && !ruleContext.getFragment(AndroidConfiguration.class).allowResourcesAttr()) { - ruleContext.throwWithAttributeError( - "resources", - "The resources attribute has been removed. Please use resource_files instead."); - } + AndroidCommon.validateResourcesAttribute(ruleContext); /** * TODO(b/14473160): Remove when deps are no longer implicitly exported. |