aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax
diff options
context:
space:
mode:
authorGravatar dslomov <dslomov@google.com>2017-10-23 17:01:35 +0200
committerGravatar Dmitry Lomov <dslomov@google.com>2017-10-23 17:16:26 +0200
commit4256ce1915c69bb8a8cee0b5c09a094768b7cd02 (patch)
treed47d8ae04f078cbca4e92a3c282f096ff9450e48 /src/main/java/com/google/devtools/build/lib/syntax
parentc6fd7b22a056f38ae717ad87016f2f76df25998b (diff)
Automated rollback of commit 1b98de65873054b148ced772cfa827a7bfb5ad9a.
*** Reason for rollback *** If the 'set' function was used in a .bzl file but not called, --incompatible_disallow_set_constructor=True would allow the load of that .bzl file without error, but this change removes the 'set' function so loading that bzl file is an error. Example failure: https://ci.bazel.io/blue/organizations/jenkins/Global%2FTensorFlow/detail/TensorFlow/245/pipeline/ *** Original change description *** 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: 173115983
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/BazelLibrary.java57
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/SkylarkNestedSet.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/SkylarkSemantics.java3
3 files changed, 70 insertions, 4 deletions
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 110c9e1f8c..20111cedd6 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
@@ -114,7 +114,8 @@ public class BazelLibrary {
defaultValue = "None"
)
},
- useLocation = true
+ useLocation = true,
+ useEnvironment = true
)
private static final BuiltinFunction depset =
new BuiltinFunction("depset") {
@@ -123,11 +124,13 @@ public class BazelLibrary {
String orderString,
Object direct,
Object transitive,
- Location loc)
+ Location loc,
+ Environment env)
throws EvalException {
Order order;
try {
- order = Order.parse(orderString);
+ order = Order.parse(
+ orderString, env.getSemantics().incompatibleDisallowSetConstructor());
} catch (IllegalArgumentException ex) {
throw new EvalException(loc, ex);
}
@@ -175,6 +178,52 @@ public class BazelLibrary {
}
@SkylarkSignature(
+ name = "set",
+ returnType = SkylarkNestedSet.class,
+ documentationReturnType = SkylarkNestedSet.LegacySet.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,
+ 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,
returnType = SkylarkNestedSet.class,
@@ -255,7 +304,7 @@ public class BazelLibrary {
};
private static Environment.Frame createGlobals() {
- List<BaseFunction> bazelGlobalFunctions = ImmutableList.of(select, depset, type);
+ List<BaseFunction> bazelGlobalFunctions = ImmutableList.of(select, depset, set, type);
try (Mutability mutability = Mutability.create("BUILD")) {
Environment env = Environment.builder(mutability)
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 f72f689d57..2915a8db83 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,6 +92,20 @@ public final class SkylarkNestedSet implements SkylarkValue, SkylarkQueryable {
@Nullable
private final List<NestedSet> 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 <a href=\"depset.html\">depset</a>. "
+ + "Please use <a href=\"depset.html\">depset</a> instead. "
+ + "If you need a hash set that supports O(1) membership testing "
+ + "consider using a <a href=\"dict.html\">dict</a>."
+ )
+ 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 105768fd3d..8d1fa59f4e 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,6 +46,7 @@ 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();
@@ -67,6 +68,7 @@ public abstract class SkylarkSemantics {
.incompatibleDictLiteralHasNoDuplicates(true)
.incompatibleDisallowDictPlus(false)
.incompatibleDisallowKeywordOnlyArgs(true)
+ .incompatibleDisallowSetConstructor(true)
.incompatibleDisallowToplevelIfStatement(true)
.incompatibleListPlusEqualsInplace(true)
.incompatibleLoadArgumentIsLabel(false)
@@ -88,6 +90,7 @@ 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);