diff options
author | vladmos <vladmos@google.com> | 2017-11-21 04:40:08 -0800 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2017-11-21 04:41:35 -0800 |
commit | 9bb93ee8c0edae911f9e2adeaca8aebd406788b6 (patch) | |
tree | ec830914e13f142fe1079c92b342cbad38f067c3 /src/main/java | |
parent | 4d09a1de6a60c6f90cc88978151bcde83c8000d4 (diff) |
Remove the deprecated set constructor from Skylark
The `set` constructor used to be deprecated, but it was still possible to use
it by providing --incompatible_disallow_set_constructor=false.
It's still allowed to have `set` in parts of the code that are not executed, this will be deprecated later. You can check if your code is compatible with this future change by using the flag --incompatible_disallow_uncalled_set_constructor (currently the default is "false").
RELNOTES[INC]: The flag --incompatible_disallow_set_constructor is no longer
available, the deprecated `set` constructor is not available anymore.
PiperOrigin-RevId: 176491641
Diffstat (limited to 'src/main/java')
6 files changed, 31 insertions, 31 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 52db1ce009..1ffb7e2cee 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 @@ -48,6 +48,7 @@ public final class SkylarkSemanticsCodec implements ObjectCodec<SkylarkSemantics codedOut.writeBoolNoTag(semantics.incompatibleDisallowDictPlus()); codedOut.writeBoolNoTag(semantics.incompatibleDisallowKeywordOnlyArgs()); codedOut.writeBoolNoTag(semantics.incompatibleDisallowToplevelIfStatement()); + codedOut.writeBoolNoTag(semantics.incompatibleDisallowUncalledSetConstructor()); codedOut.writeBoolNoTag(semantics.incompatibleListPlusEqualsInplace()); codedOut.writeBoolNoTag(semantics.incompatibleLoadArgumentIsLabel()); codedOut.writeBoolNoTag(semantics.incompatibleNewActionsApi()); @@ -70,6 +71,7 @@ public final class SkylarkSemanticsCodec implements ObjectCodec<SkylarkSemantics builder.incompatibleDisallowDictPlus(codedIn.readBool()); builder.incompatibleDisallowKeywordOnlyArgs(codedIn.readBool()); builder.incompatibleDisallowToplevelIfStatement(codedIn.readBool()); + builder.incompatibleDisallowUncalledSetConstructor(codedIn.readBool()); builder.incompatibleListPlusEqualsInplace(codedIn.readBool()); builder.incompatibleLoadArgumentIsLabel(codedIn.readBool()); builder.incompatibleNewActionsApi(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 0f8e0c4ad2..6545d064b5 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 @@ -159,6 +159,17 @@ public class SkylarkSemanticsOptions extends OptionsBase implements Serializable public boolean incompatibleDisallowToplevelIfStatement; @Option( + name = "incompatible_disallow_uncalled_set_constructor", + defaultValue = "false", + category = "incompatible changes", + documentationCategory = OptionDocumentationCategory.UNCATEGORIZED, + effectTags = {OptionEffectTag.UNKNOWN}, + metadataTags = {OptionMetadataTag.INCOMPATIBLE_CHANGE}, + help = "If set to true, it's not allowed to use `set()` even if that code is never executed." + ) + public boolean incompatibleDisallowUncalledSetConstructor; + + @Option( name = "incompatible_list_plus_equals_inplace", defaultValue = "true", category = "incompatible changes", @@ -244,6 +255,7 @@ public class SkylarkSemanticsOptions extends OptionsBase implements Serializable .incompatibleDisallowDictPlus(incompatibleDisallowDictPlus) .incompatibleDisallowKeywordOnlyArgs(incompatibleDisallowKeywordOnlyArgs) .incompatibleDisallowToplevelIfStatement(incompatibleDisallowToplevelIfStatement) + .incompatibleDisallowUncalledSetConstructor(incompatibleDisallowUncalledSetConstructor) .incompatibleListPlusEqualsInplace(incompatibleListPlusEqualsInplace) .incompatibleLoadArgumentIsLabel(incompatibleLoadArgumentIsLabel) .incompatibleNewActionsApi(incompatibleNewActionsApi) diff --git a/src/main/java/com/google/devtools/build/lib/syntax/BazelLibrary.java b/src/main/java/com/google/devtools/build/lib/syntax/BazelLibrary.java index a60ec53337..110c9e1f8c 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/BazelLibrary.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/BazelLibrary.java @@ -175,36 +175,6 @@ public class BazelLibrary { } @SkylarkSignature( - name = "set", - returnType = SkylarkNestedSet.class, - doc = - "A temporary alias for <a href=\"#depset\">depset</a>. " - + "Deprecated in favor of <code>depset</code>.", - parameters = { - @Param( - name = "items", - type = Object.class, - defaultValue = "[]", - doc = "Same as for <a href=\"#depset\">depset</a>." - ), - @Param( - name = "order", - type = String.class, - defaultValue = "\"default\"", - doc = "Same as for <a href=\"#depset\">depset</a>." - ) - }, - useLocation = true - ) - private static final BuiltinFunction set = - new BuiltinFunction("set") { - public SkylarkNestedSet invoke(Object items, String order, Location loc) - throws EvalException { - throw new EvalException(loc, "The function 'set' has been removed in favor of 'depset'."); - } - }; - - @SkylarkSignature( name = "union", objectType = SkylarkNestedSet.class, returnType = SkylarkNestedSet.class, @@ -285,7 +255,7 @@ public class BazelLibrary { }; private static Environment.Frame createGlobals() { - List<BaseFunction> bazelGlobalFunctions = ImmutableList.of(select, depset, set, type); + List<BaseFunction> bazelGlobalFunctions = ImmutableList.of(select, depset, type); try (Mutability mutability = Mutability.create("BUILD")) { Environment env = Environment.builder(mutability) diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Identifier.java b/src/main/java/com/google/devtools/build/lib/syntax/Identifier.java index a0dc773469..1bbf78c225 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Identifier.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Identifier.java @@ -94,6 +94,13 @@ public final class Identifier extends Expression { if (name.equals("$error$")) { return new EvalException(getLocation(), "contains syntax error(s)", true); } + if (name.equals("set")) { + //TODO(vladmos): Remove as soon as the flag is removed + return new EvalException(getLocation(), + "The function 'set' has been removed in favor of 'depset', please use the latter. " + + "You can temporarily refer to the old 'set' constructor from unexecuted code " + + "by using --incompatible_disallow_uncalled_set_constructor=false"); + } String suggestion = SpellChecker.didYouMean(name, symbols); return new EvalException(getLocation(), "name '" + name + "' is not defined" + suggestion); } 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 105768fd3d..39a7673998 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 @@ -47,6 +47,7 @@ public abstract class SkylarkSemantics { public abstract boolean incompatibleDisallowDictPlus(); public abstract boolean incompatibleDisallowKeywordOnlyArgs(); public abstract boolean incompatibleDisallowToplevelIfStatement(); + public abstract boolean incompatibleDisallowUncalledSetConstructor(); public abstract boolean incompatibleListPlusEqualsInplace(); public abstract boolean incompatibleLoadArgumentIsLabel(); public abstract boolean incompatibleNewActionsApi(); @@ -68,6 +69,7 @@ public abstract class SkylarkSemantics { .incompatibleDisallowDictPlus(false) .incompatibleDisallowKeywordOnlyArgs(true) .incompatibleDisallowToplevelIfStatement(true) + .incompatibleDisallowUncalledSetConstructor(false) .incompatibleListPlusEqualsInplace(true) .incompatibleLoadArgumentIsLabel(false) .incompatibleNewActionsApi(false) @@ -89,6 +91,7 @@ public abstract class SkylarkSemantics { public abstract Builder incompatibleDisallowDictPlus(boolean value); public abstract Builder incompatibleDisallowKeywordOnlyArgs(boolean value); public abstract Builder incompatibleDisallowToplevelIfStatement(boolean value); + public abstract Builder incompatibleDisallowUncalledSetConstructor(boolean value); public abstract Builder incompatibleListPlusEqualsInplace(boolean value); public abstract Builder incompatibleLoadArgumentIsLabel(boolean value); public abstract Builder incompatibleNewActionsApi(boolean value); diff --git a/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java b/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java index 451b0d5297..cbe6094d14 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/ValidationEnvironment.java @@ -68,6 +68,12 @@ public final class ValidationEnvironment extends SyntaxTreeVisitor { block.variables.addAll(builtinVariables); block.readOnlyVariables.addAll(builtinVariables); semantics = env.getSemantics(); + + // If the flag is set to false, it should be allowed to have `set` + // in non-executable parts of the code. + if (!env.getSemantics().incompatibleDisallowUncalledSetConstructor()) { + block.variables.add("set"); + } } @Override |