Minor refactoring in SkylarkUtils

Next step will be to move Environment.Phase to SkylarkUtils.BazelInfo

--
MOS_MIGRATED_REVID=139902745
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 fffacb6..08ff95b 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
@@ -379,16 +379,9 @@
   private final String transitiveHashCode;
 
   /**
-   * Is this Environment being evaluated during the loading phase?
-   * This is fixed during Environment setup, and enables various functions
-   * that are not available during the analysis or workspace phase.
-   */
-  public Phase getPhase() {
-    return phase;
-  }
-
-  /**
    * Checks that the current Environment is in the loading or the workspace phase.
+   * TODO(laurentlb): Move to SkylarkUtils
+   *
    * @param symbol name of the function being only authorized thus.
    */
   public void checkLoadingOrWorkspacePhase(String symbol, Location loc) throws EvalException {
@@ -399,6 +392,8 @@
 
   /**
    * Checks that the current Environment is in the loading phase.
+   * TODO(laurentlb): Move to SkylarkUtils
+   *
    * @param symbol name of the function being only authorized thus.
    */
   public void checkLoadingPhase(String symbol, Location loc) throws EvalException {
diff --git a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkUtils.java b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkUtils.java
index 875586f..970543f 100644
--- a/src/main/java/com/google/devtools/build/lib/syntax/SkylarkUtils.java
+++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkUtils.java
@@ -17,22 +17,33 @@
 /** This class contains Bazel-specific functions to extend or interoperate with Skylark. */
 public final class SkylarkUtils {
 
-  public static final String TOOLS_REPOSITORY = "$tools_repository";
+  /** Bazel-specific information that we store in the Environment. */
+  private static class BazelInfo {
+    String toolsRepository;
+  }
 
-  /** Unsafe version of Environment#update */
-  private static void updateEnv(Environment env, String key, Object value) {
+  private static final String BAZEL_INFO_KEY = "$bazel";
+
+  private static BazelInfo getInfo(Environment env) {
+    Object info = env.lookup(BAZEL_INFO_KEY);
+    if (info != null) {
+      return (BazelInfo) info;
+    }
+
+    BazelInfo result = new BazelInfo();
     try {
-      env.update(key, value);
+      env.update(BAZEL_INFO_KEY, result);
+      return result;
     } catch (EvalException e) {
       throw new AssertionError(e);
     }
   }
 
   public static void setToolsRepository(Environment env, String toolsRepository) {
-    updateEnv(env, TOOLS_REPOSITORY, toolsRepository);
+    getInfo(env).toolsRepository = toolsRepository;
   }
 
   public static String getToolsRepository(Environment env) {
-    return (String) env.lookup(TOOLS_REPOSITORY);
+    return getInfo(env).toolsRepository;
   }
 }