diff options
author | 2018-05-01 10:54:58 -0700 | |
---|---|---|
committer | 2018-05-01 10:57:43 -0700 | |
commit | b80eb18e66adcdcbfbc1ec62cd1a67db1924504d (patch) | |
tree | 66080c778b7b095d3d159ba84855b315be96f4b9 /src/main/java/com/google/devtools/build/lib/syntax/Runtime.java | |
parent | 1de17c2644f8e0f4da0fbc6569db083a8acc56e7 (diff) |
Move BazelLibrary from syntax/ to packages/
This helps the Skylark interpreter to not depend on Bazel concepts, though it adds a temporary dependency of Skylint on packages/. The fix for that will be to create a Build API interface for BazelLibrary (e.g., "BazelLibraryAPI").
Refactored some GlobalFrame construction logic to be more uniform. Instead of constructing a whole Environment just to get a frame, we build the frame directly, using ImmutableMap.Builder to accumulate bindings. This convention may further change once we convert MethodLibrary and the like to @SkylarkGlobalLibrary, but for now it's more readable.
RELNOTES: None
PiperOrigin-RevId: 194960824
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/Runtime.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/Runtime.java | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Runtime.java b/src/main/java/com/google/devtools/build/lib/syntax/Runtime.java index 86f95b38b7..66060299b2 100644 --- a/src/main/java/com/google/devtools/build/lib/syntax/Runtime.java +++ b/src/main/java/com/google/devtools/build/lib/syntax/Runtime.java @@ -16,6 +16,7 @@ package com.google.devtools.build.lib.syntax; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable; import com.google.devtools.build.lib.skylarkinterface.SkylarkGlobalLibrary; @@ -137,14 +138,16 @@ public final class Runtime { ) public static final String REPOSITORY_NAME = "REPOSITORY_NAME"; - /** - * Set up a given environment for supported class methods. - */ - static Environment setupConstants(Environment env) { + /** Adds bindings for False/True/None constants to the given map builder. */ + public static void addConstantsToBuilder(ImmutableMap.Builder<String, Object> builder) { // In Python 2.x, True and False are global values and can be redefined by the user. - // In Python 3.x, they are keywords. We implement them as values, for the sake of - // simplicity. We define them as Boolean objects. - return env.setup("False", FALSE).setup("True", TRUE).setup("None", NONE); + // In Python 3.x, they are keywords. We implement them as values. Currently they can't be + // redefined because builtins can't be overridden. In the future we should permit shadowing of + // most builtins but still prevent shadowing of these constants. + builder + .put("False", FALSE) + .put("True", TRUE) + .put("None", NONE); } @@ -390,11 +393,4 @@ public final class Runtime { public static void registerModuleGlobals(Environment env, Class<?> moduleClass) { setupModuleGlobals(env, moduleClass); } - - static void setupMethodEnvironment( - Environment env, Iterable<BaseFunction> functions) { - for (BaseFunction function : functions) { - env.setup(function.getName(), function); - } - } } |