diff options
author | 2018-03-01 15:16:46 -0800 | |
---|---|---|
committer | 2018-03-01 15:18:45 -0800 | |
commit | 99be8b417a95224f66b3e00c9103cbde460d3b07 (patch) | |
tree | cddd8696ba024c1122fb33a4f45424012e670061 /src/main/java | |
parent | 1085ce935b68d51e6754148ef4c1e4e73e7dc2b6 (diff) |
Create --incompatible_disable_objc_provider_resources to disable deprecated objc provider skylark fields.
This flag is not fully implemented -- there should also be a way to disable the provider getters using this flag, but, since @SkylarkCallable does not allow for evaluation of SkylarkSemantics, this is not yet possible.
RELNOTES: None.
PiperOrigin-RevId: 187542004
Diffstat (limited to 'src/main/java')
5 files changed, 44 insertions, 2 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java index 9f729b5710..978e7e9a3f 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java +++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsCodec.java @@ -47,6 +47,7 @@ public final class SkylarkSemanticsCodec implements ObjectCodec<SkylarkSemantics codedOut.writeBoolNoTag(semantics.incompatibleDepsetIsNotIterable()); codedOut.writeBoolNoTag(semantics.incompatibleDepsetUnion()); codedOut.writeBoolNoTag(semantics.incompatibleDisableGlobTracking()); + codedOut.writeBoolNoTag(semantics.incompatibleDisableObjcProviderResources()); codedOut.writeBoolNoTag(semantics.incompatibleDisallowDictPlus()); codedOut.writeBoolNoTag(semantics.incompatibleDisallowToplevelIfStatement()); codedOut.writeBoolNoTag(semantics.incompatibleDisallowUncalledSetConstructor()); @@ -69,6 +70,7 @@ public final class SkylarkSemanticsCodec implements ObjectCodec<SkylarkSemantics builder.incompatibleDepsetIsNotIterable(codedIn.readBool()); builder.incompatibleDepsetUnion(codedIn.readBool()); builder.incompatibleDisableGlobTracking(codedIn.readBool()); + builder.incompatibleDisableObjcProviderResources(codedIn.readBool()); builder.incompatibleDisallowDictPlus(codedIn.readBool()); builder.incompatibleDisallowToplevelIfStatement(codedIn.readBool()); builder.incompatibleDisallowUncalledSetConstructor(codedIn.readBool()); diff --git a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java index 1bcd5a1ee2..86f6b44b9f 100644 --- a/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java +++ b/src/main/java/com/google/devtools/build/lib/packages/SkylarkSemanticsOptions.java @@ -111,6 +111,17 @@ public class SkylarkSemanticsOptions extends OptionsBase implements Serializable public boolean incompatibleDisableGlobTracking; @Option( + name = "incompatible_disable_objc_provider_resources", + defaultValue = "false", + category = "incompatible changes", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE}, + help = "If set to true, disallow use of deprecated resource fields on the Objc provider." + ) + public boolean incompatibleDisableObjcProviderResources; + + @Option( name = "incompatible_disallow_dict_plus", defaultValue = "false", category = "incompatible changes", @@ -238,6 +249,7 @@ public class SkylarkSemanticsOptions extends OptionsBase implements Serializable .incompatibleDepsetIsNotIterable(incompatibleDepsetIsNotIterable) .incompatibleDepsetUnion(incompatibleDepsetUnion) .incompatibleDisableGlobTracking(incompatibleDisableGlobTracking) + .incompatibleDisableObjcProviderResources(incompatibleDisableObjcProviderResources) .incompatibleDisallowDictPlus(incompatibleDisallowDictPlus) .incompatibleDisallowToplevelIfStatement(incompatibleDisallowToplevelIfStatement) .incompatibleDisallowUncalledSetConstructor(incompatibleDisallowUncalledSetConstructor) diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java index 5e8881adff..fa2cee202f 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/AppleSkylarkCommon.java @@ -43,6 +43,7 @@ import com.google.devtools.build.lib.skylarkinterface.SkylarkCallable; import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; import com.google.devtools.build.lib.skylarkinterface.SkylarkSignature; import com.google.devtools.build.lib.syntax.BuiltinFunction; +import com.google.devtools.build.lib.syntax.Environment; import com.google.devtools.build.lib.syntax.EvalException; import com.google.devtools.build.lib.syntax.Runtime; import com.google.devtools.build.lib.syntax.SkylarkDict; @@ -375,14 +376,18 @@ public class AppleSkylarkCommon { type = SkylarkDict.class, defaultValue = "{}", doc = "Dictionary of arguments." - ) + ), + useEnvironment = true ) public static final BuiltinFunction NEW_OBJC_PROVIDER = new BuiltinFunction("new_objc_provider") { @SuppressWarnings("unused") // This method is registered statically for skylark, and never called directly. public ObjcProvider invoke( - AppleSkylarkCommon self, Boolean usesSwift, SkylarkDict<String, Object> kwargs) { + AppleSkylarkCommon self, Boolean usesSwift, SkylarkDict<String, Object> kwargs, + Environment environment) { + boolean disableObjcResourceKeys = + environment.getSemantics().incompatibleDisableObjcProviderResources(); ObjcProvider.Builder resultBuilder = new ObjcProvider.Builder(); if (usesSwift) { resultBuilder.add(ObjcProvider.FLAG, ObjcProvider.Flag.USES_SWIFT); @@ -390,6 +395,9 @@ public class AppleSkylarkCommon { for (Entry<String, Object> entry : kwargs.entrySet()) { Key<?> key = ObjcProvider.getSkylarkKeyForString(entry.getKey()); if (key != null) { + if (disableObjcResourceKeys && ObjcProvider.isDeprecatedResourceKey(key)) { + throw new IllegalArgumentException(String.format(BAD_KEY_ERROR, entry.getKey())); + } resultBuilder.addElementsFromSkylark(key, entry.getValue()); } else if (entry.getKey().equals("providers")) { resultBuilder.addProvidersFromSkylark(entry.getValue()); diff --git a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java index 3dfada91b2..1cc56aeefc 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java +++ b/src/main/java/com/google/devtools/build/lib/rules/objc/ObjcProvider.java @@ -411,6 +411,19 @@ public final class ObjcProvider extends NativeInfo { XCDATAMODEL, XIB); + /** Deprecated keys in ObjcProvider pertaining to resource files. */ + static final ImmutableList<Key<?>> DEPRECATED_RESOURCE_KEYS = + ImmutableList.<Key<?>>of( + ASSET_CATALOG, + BUNDLE_FILE, + MERGE_ZIP, + ROOT_MERGE_ZIP, + STORYBOARD, + STRINGS, + XCASSETS_DIR, + XCDATAMODEL, + XIB); + @SkylarkCallable(name = "asset_catalog", structField = true, doc = "<b>Deprecated. Resource-related fields will be migrated to another provider.</b> " @@ -808,6 +821,10 @@ public final class ObjcProvider extends NativeInfo { return null; } + static boolean isDeprecatedResourceKey(Key<?> key) { + return DEPRECATED_RESOURCE_KEYS.contains(key); + } + // Items which should be passed to strictly direct dependers, but not transitive dependers. private final ImmutableMap<Key<?>, NestedSet<?>> strictDependencyItems; diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java index 85f5c08be6..95edc23fc3 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java @@ -45,6 +45,7 @@ public abstract class SkylarkSemantics { public abstract boolean incompatibleDepsetUnion(); public abstract boolean incompatibleDisableGlobTracking(); + public abstract boolean incompatibleDisableObjcProviderResources(); public abstract boolean incompatibleDisallowDictPlus(); public abstract boolean incompatibleDisallowToplevelIfStatement(); @@ -79,6 +80,7 @@ public abstract class SkylarkSemantics { .incompatibleDepsetIsNotIterable(false) .incompatibleDepsetUnion(false) .incompatibleDisableGlobTracking(true) + .incompatibleDisableObjcProviderResources(false) .incompatibleDisallowDictPlus(false) .incompatibleDisallowToplevelIfStatement(true) .incompatibleDisallowUncalledSetConstructor(true) @@ -102,6 +104,7 @@ public abstract class SkylarkSemantics { public abstract Builder incompatibleDepsetUnion(boolean value); public abstract Builder incompatibleDisableGlobTracking(boolean value); + public abstract Builder incompatibleDisableObjcProviderResources(boolean value); public abstract Builder incompatibleDisallowDictPlus(boolean value); public abstract Builder incompatibleDisallowToplevelIfStatement(boolean value); |