From 1b98de65873054b148ced772cfa827a7bfb5ad9a Mon Sep 17 00:00:00 2001 From: vladmos Date: Thu, 12 Oct 2017 17:25:24 +0200 Subject: 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. RELNOTES[INC]: The flag --incompatible_disallow_set_constructor is no longer available, the deprecated `set` constructor is not available anymore. PiperOrigin-RevId: 171962361 --- .../build/lib/collect/nestedset/Order.java | 45 +++-------------- .../build/lib/packages/SkylarkSemanticsCodec.java | 2 - .../lib/packages/SkylarkSemanticsOptions.java | 12 ----- .../devtools/build/lib/syntax/BazelLibrary.java | 57 ++-------------------- .../build/lib/syntax/SkylarkNestedSet.java | 14 ------ .../build/lib/syntax/SkylarkSemantics.java | 3 -- 6 files changed, 11 insertions(+), 122 deletions(-) (limited to 'src/main/java/com/google/devtools/build/lib') diff --git a/src/main/java/com/google/devtools/build/lib/collect/nestedset/Order.java b/src/main/java/com/google/devtools/build/lib/collect/nestedset/Order.java index 05cc7a1b1a..6b6fde0927 100644 --- a/src/main/java/com/google/devtools/build/lib/collect/nestedset/Order.java +++ b/src/main/java/com/google/devtools/build/lib/collect/nestedset/Order.java @@ -102,23 +102,20 @@ import java.util.HashMap; * dependencies-after-parent ordering. Note that the latter is usually more important, so please use * LINK_ORDER whenever possible. */ -// TODO(bazel-team): Remove deprecatedSkylarkName and it's associated helpers before Bazel 1.0. +// TODO(bazel-team): Remove deprecated names from the documentation above. public enum Order { - STABLE_ORDER("default", "stable"), - COMPILE_ORDER("postorder", "compile"), - LINK_ORDER("topological", "link"), - NAIVE_LINK_ORDER("preorder", "naive_link"); + STABLE_ORDER("default"), + COMPILE_ORDER("postorder"), + LINK_ORDER("topological"), + NAIVE_LINK_ORDER("preorder"); private static final ImmutableMap VALUES; - private static final ImmutableMap DEPRECATED_VALUES; private final String skylarkName; - private final String deprecatedSkylarkName; private final NestedSet emptySet; - private Order(String skylarkName, String deprecatedSkylarkName) { + private Order(String skylarkName) { this.skylarkName = skylarkName; - this.deprecatedSkylarkName = deprecatedSkylarkName; this.emptySet = new NestedSet<>(this); } @@ -134,46 +131,21 @@ public enum Order { return skylarkName; } - public String getDeprecatedSkylarkName() { - return deprecatedSkylarkName; - } - /** * Parses the given string as a nested set order * * @param name unique name of the order - * @param forbidDeprecatedOrderNames if true, old style ordering names will be rejected * @return the appropriate order instance * @throws IllegalArgumentException if the name is not valid */ - public static Order parse(String name, boolean forbidDeprecatedOrderNames) { + public static Order parse(String name) { if (VALUES.containsKey(name)) { return VALUES.get(name); - } else if (DEPRECATED_VALUES.containsKey(name)) { - if (forbidDeprecatedOrderNames) { - throw new IllegalArgumentException(String.format( - "Order name '%s' is deprecated, use '%s' instead", - name, - DEPRECATED_VALUES.get(name).getSkylarkName() - )); - } - return DEPRECATED_VALUES.get(name); } else { throw new IllegalArgumentException("Invalid order: " + name); } } - /** - * Parses the given string as a nested set order - * - * @param name unique name of the order - * @return the appropriate order instance - * @throws IllegalArgumentException if the name is not valid - */ - public static Order parse(String name) { - return parse(name, false); - } - /** * Determines whether two orders are considered compatible. * @@ -191,14 +163,11 @@ public enum Order { Order[] tmpValues = Order.values(); HashMap entries = Maps.newHashMapWithExpectedSize(tmpValues.length); - HashMap deprecatedEntries = Maps.newHashMapWithExpectedSize(tmpValues.length); for (Order current : tmpValues) { entries.put(current.getSkylarkName(), current); - deprecatedEntries.put(current.getDeprecatedSkylarkName(), current); } VALUES = ImmutableMap.copyOf(entries); - DEPRECATED_VALUES = ImmutableMap.copyOf(deprecatedEntries); } } 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 e36eca2770..52db1ce009 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,7 +47,6 @@ public final class SkylarkSemanticsCodec implements ObjectCodecdepset. " - + "Deprecated in favor of depset.", - parameters = { - @Param( - name = "items", - type = Object.class, - defaultValue = "[]", - doc = "Same as for depset." - ), - @Param( - name = "order", - type = String.class, - defaultValue = "\"default\"", - doc = "Same as for depset." - ) - }, - useLocation = true, - useEnvironment = true - ) - private static final BuiltinFunction set = - new BuiltinFunction("set") { - public SkylarkNestedSet invoke(Object items, String order, Location loc, Environment env) - throws EvalException { - if (env.getSemantics().incompatibleDisallowSetConstructor()) { - throw new EvalException( - loc, - "The `set` constructor for depsets is deprecated and will be removed. Please use " - + "the `depset` constructor instead. You can temporarily enable the " - + "deprecated `set` constructor by passing the flag " - + "--incompatible_disallow_set_constructor=false"); - } - try { - return new SkylarkNestedSet( - Order.parse(order, /*forbidDeprecatedOrderNames=*/false), - items, loc); - } catch (IllegalArgumentException ex) { - throw new EvalException(loc, ex); - } - } - }; - @SkylarkSignature( name = "union", objectType = SkylarkNestedSet.class, @@ -304,7 +255,7 @@ public class BazelLibrary { }; private static Environment.Frame createGlobals() { - List bazelGlobalFunctions = ImmutableList.of(select, depset, set, type); + List bazelGlobalFunctions = ImmutableList.of(select, depset, type); try (Mutability mutability = Mutability.create("BUILD")) { Environment env = Environment.builder(mutability).build(); diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkNestedSet.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkNestedSet.java index 2915a8db83..f72f689d57 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkNestedSet.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkNestedSet.java @@ -92,20 +92,6 @@ public final class SkylarkNestedSet implements SkylarkValue, SkylarkQueryable { @Nullable private final List transitiveItems; - // Dummy class used to create a documentation for the deprecated `set` type - // TODO(bazel-team): remove before the end of 2017 - @SkylarkModule( - name = "set", - category = SkylarkModuleCategory.BUILTIN, - doc = "A deprecated alias for depset. " - + "Please use depset instead. " - + "If you need a hash set that supports O(1) membership testing " - + "consider using a dict." - ) - static final class LegacySet { - private LegacySet() {} - } - public SkylarkNestedSet(Order order, Object item, Location loc) throws EvalException { this(order, SkylarkType.TOP, item, loc, null); } 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 7fbfc3fc6e..8fdfaf5cd1 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 @@ -46,7 +46,6 @@ public abstract class SkylarkSemantics { public abstract boolean incompatibleDictLiteralHasNoDuplicates(); public abstract boolean incompatibleDisallowDictPlus(); public abstract boolean incompatibleDisallowKeywordOnlyArgs(); - public abstract boolean incompatibleDisallowSetConstructor(); public abstract boolean incompatibleDisallowToplevelIfStatement(); public abstract boolean incompatibleListPlusEqualsInplace(); public abstract boolean incompatibleLoadArgumentIsLabel(); @@ -68,7 +67,6 @@ public abstract class SkylarkSemantics { .incompatibleDictLiteralHasNoDuplicates(true) .incompatibleDisallowDictPlus(false) .incompatibleDisallowKeywordOnlyArgs(true) - .incompatibleDisallowSetConstructor(true) .incompatibleDisallowToplevelIfStatement(true) .incompatibleListPlusEqualsInplace(false) .incompatibleLoadArgumentIsLabel(false) @@ -90,7 +88,6 @@ public abstract class SkylarkSemantics { public abstract Builder incompatibleDictLiteralHasNoDuplicates(boolean value); public abstract Builder incompatibleDisallowDictPlus(boolean value); public abstract Builder incompatibleDisallowKeywordOnlyArgs(boolean value); - public abstract Builder incompatibleDisallowSetConstructor(boolean value); public abstract Builder incompatibleDisallowToplevelIfStatement(boolean value); public abstract Builder incompatibleListPlusEqualsInplace(boolean value); public abstract Builder incompatibleLoadArgumentIsLabel(boolean value); -- cgit v1.2.3