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
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 86f95b3..6606029 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 @@
 
 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 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 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);
-    }
-  }
 }