Create SkylarkCallable.useContext and use it instead of Environment.BazelInfo

This makes the Starlark interpreter pass a StarlarkContext object to methods, which, for Bazel, should be a stand-in replacement for the previous BazelInfo object.

In a future cleanup, we can move Mutability to context, and then turn down useEnvironment. Environment is a bit too powerful an object to be passing around.

RELNOTES: None.
PiperOrigin-RevId: 224216211
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
index b8d20f5..3b74a32 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/Environment.java
@@ -28,6 +28,7 @@
 import com.google.devtools.build.lib.events.Location;
 import com.google.devtools.build.lib.skyframe.serialization.autocodec.AutoCodec;
 import com.google.devtools.build.lib.skylarkinterface.SkylarkValue;
+import com.google.devtools.build.lib.skylarkinterface.StarlarkContext;
 import com.google.devtools.build.lib.syntax.Mutability.Freezable;
 import com.google.devtools.build.lib.syntax.Mutability.MutabilityException;
 import com.google.devtools.build.lib.syntax.Parser.ParsingLevel;
@@ -746,6 +747,8 @@
   /** The semantics options that affect how Skylark code is evaluated. */
   private final SkylarkSemantics semantics;
 
+  private final StarlarkContext starlarkContext;
+
   /**
    * An EventHandler for errors and warnings. This is not used in the BUILD language, however it
    * might be used in Skylark code called from the BUILD language, so shouldn't be null.
@@ -874,6 +877,7 @@
       GlobalFrame globalFrame,
       LexicalFrame dynamicFrame,
       SkylarkSemantics semantics,
+      StarlarkContext starlarkContext,
       EventHandler eventHandler,
       Map<String, Extension> importedExtensions,
       @Nullable String fileContentHashCode,
@@ -884,6 +888,7 @@
     Preconditions.checkArgument(!globalFrame.mutability().isFrozen());
     Preconditions.checkArgument(!dynamicFrame.mutability().isFrozen());
     this.semantics = semantics;
+    this.starlarkContext = starlarkContext;
     this.eventHandler = eventHandler;
     this.importedExtensions = importedExtensions;
     this.callerLabel = callerLabel;
@@ -901,6 +906,7 @@
     private final Mutability mutability;
     @Nullable private GlobalFrame parent;
     @Nullable private SkylarkSemantics semantics;
+    @Nullable private StarlarkContext starlarkContext;
     @Nullable private EventHandler eventHandler;
     @Nullable private Map<String, Extension> importedExtensions;
     @Nullable private String fileContentHashCode;
@@ -908,6 +914,8 @@
 
     Builder(Mutability mutability) {
       this.mutability = mutability;
+      // TODO(cparsons): Require specifying a starlarkContext (or declaring use of an empty stub).
+      this.starlarkContext = new StarlarkContext() {};
     }
 
     /**
@@ -931,6 +939,16 @@
       return this;
     }
 
+    public Builder setStarlarkContext(StarlarkContext starlarkContext) {
+      this.starlarkContext = starlarkContext;
+      return this;
+    }
+
+    public Builder useEmptyStarlarkContext() {
+      this.starlarkContext = new StarlarkContext() {};
+      return this;
+    }
+
     /** Sets an EventHandler for errors and warnings. */
     public Builder setEventHandler(EventHandler eventHandler) {
       Preconditions.checkState(this.eventHandler == null);
@@ -988,6 +1006,7 @@
           globalFrame,
           dynamicFrame,
           semantics,
+          starlarkContext,
           eventHandler,
           importedExtensions,
           fileContentHashCode,
@@ -1169,6 +1188,10 @@
     return semantics;
   }
 
+  public StarlarkContext getStarlarkContext() {
+    return starlarkContext;
+  }
+
   public void handleEvent(Event event) {
     eventHandler.handle(event);
   }