diff options
author | Googler <noreply@google.com> | 2017-09-06 16:23:17 +0200 |
---|---|---|
committer | Yun Peng <pcloudy@google.com> | 2017-09-07 09:57:07 +0200 |
commit | 82f7a8bea69d6c57fe26b04217197015121f36f6 (patch) | |
tree | 6d78cd96a890a753abf8a2f435b2b2fde1460e4f /src/main/java/com/google/devtools/build/lib | |
parent | c5c8c35114eed2b0cdc7fefa75c2d795aa2dc0b0 (diff) |
Add flag to turn off the resources attribute
The resources attribute is being deprecated. Add a flag to disable it so we can
test impact locally and turn it off globally without waiting for a Bazel
release.
RELNOTES: none
PiperOrigin-RevId: 167717822
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
3 files changed, 29 insertions, 0 deletions
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 1198ee341a..d8d856cd58 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 @@ -165,6 +165,12 @@ 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."); + } } private static RuleConfiguredTargetBuilder init( 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 036f606ecd..ccc5b4c0f1 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 @@ -723,6 +723,16 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { ) public boolean allowAndroidResources; + @Option( + name = "experimental_android_allow_resources_attr", + defaultValue = "true", + 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" + ) + public boolean allowResourcesAttr; + @Override public FragmentOptions getHost(boolean fallback) { Options host = (Options) super.getHost(fallback); @@ -805,6 +815,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { private final boolean useParallelDex2Oat; private final boolean useManifestFromResourceApk; private final boolean allowAndroidResources; + private final boolean allowResourcesAttr; AndroidConfiguration(Options options) throws InvalidConfigurationException { @@ -844,6 +855,7 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { this.useParallelDex2Oat = options.useParallelDex2Oat; this.useManifestFromResourceApk = options.useManifestFromResourceApk; this.allowAndroidResources = options.allowAndroidResources; + this.allowResourcesAttr = options.allowResourcesAttr; if (!dexoptsSupportedInIncrementalDexing.contains("--no-locals")) { // TODO(bazel-team): Still needed? See DexArchiveAspect @@ -986,6 +998,10 @@ public class AndroidConfiguration extends BuildConfiguration.Fragment { return this.allowAndroidResources; } + public boolean allowResourcesAttr() { + return this.allowResourcesAttr; + } + @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 1709701712..dd91d88e37 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 @@ -56,6 +56,13 @@ public abstract class AndroidLibrary 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."); + } } /** |