Rollback of commit 7c4a8093da6272969c86f22a08c72ddbbf6e8274.

*** Reason for rollback ***

Broke //src/test/shell/bazel:external_skylark_load_test

See http://ci.bazel.io/job/bazel-tests/BAZEL_VERSION=HEAD,PLATFORM_NAME=linux-x86_64/370/console, for example.

*** Original change description ***

Remove callerLabel from Environment.

It is a Bazel-specific information.

--
MOS_MIGRATED_REVID=140742037
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java
index 80cbbb9..9aa6b26 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleClassFunctions.java
@@ -755,7 +755,7 @@
           throws EvalException {
         Label parentLabel = null;
         if (relativeToCallerRepository) {
-          parentLabel = SkylarkUtils.getCallerLabel(env);
+          parentLabel = env.getCallerLabel();
         } else {
           parentLabel = env.getGlobals().label();
         }
diff --git a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleConfiguredTargetBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleConfiguredTargetBuilder.java
index b3c03aa..f78e96d 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleConfiguredTargetBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/SkylarkRuleConfiguredTargetBuilder.java
@@ -47,7 +47,6 @@
 import com.google.devtools.build.lib.syntax.SkylarkList;
 import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
 import com.google.devtools.build.lib.syntax.SkylarkType;
-import com.google.devtools.build.lib.syntax.SkylarkUtils;
 import com.google.devtools.build.lib.syntax.Type;
 import com.google.devtools.build.lib.util.FileType;
 import com.google.devtools.build.lib.util.FileTypeSet;
@@ -76,13 +75,12 @@
       SkylarkRuleContext skylarkRuleContext = new SkylarkRuleContext(ruleContext,
           null);
       Environment env = Environment.builder(mutability)
+          .setCallerLabel(ruleContext.getLabel())
           .setGlobals(
               ruleContext.getRule().getRuleClassObject().getRuleDefinitionEnvironment().getGlobals())
           .setEventHandler(ruleContext.getAnalysisEnvironment().getEventHandler())
           .build(); // NB: loading phase functions are not available: this is analysis already,
                     // so we do *not* setLoadingPhase().
-      SkylarkUtils.setCallerLabel(env, ruleContext.getLabel());
-
       Object target = ruleImplementation.call(
           ImmutableList.<Object>of(skylarkRuleContext),
           ImmutableMap.<String, Object>of(),
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 7029a59..11515ef 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
@@ -336,6 +336,13 @@
   @Nullable private Continuation continuation;
 
   /**
+   * Gets the label of the BUILD file that is using this environment. For example, if a target
+   * //foo has a dependency on //bar which is a Skylark rule defined in //rules:my_rule.bzl being
+   * evaluated in this environment, then this would return //foo.
+   */
+  @Nullable private final Label callerLabel;
+
+  /**
    * Enters a scope by saving state to a new Continuation
    * @param function the function whose scope to enter
    * @param caller the source AST node for the caller
@@ -456,6 +463,7 @@
    * @param importedExtensions Extension-s from which to import bindings with load()
    * @param fileContentHashCode a hash for the source file being evaluated, if any
    * @param phase the current phase
+   * @param callerLabel the label this environment came from
    */
   private Environment(
       Frame globalFrame,
@@ -463,7 +471,8 @@
       EventHandler eventHandler,
       Map<String, Extension> importedExtensions,
       @Nullable String fileContentHashCode,
-      Phase phase) {
+      Phase phase,
+      @Nullable Label callerLabel) {
     this.globalFrame = Preconditions.checkNotNull(globalFrame);
     this.dynamicFrame = Preconditions.checkNotNull(dynamicFrame);
     Preconditions.checkArgument(globalFrame.mutability().isMutable());
@@ -471,6 +480,7 @@
     this.eventHandler = eventHandler;
     this.importedExtensions = importedExtensions;
     this.phase = phase;
+    this.callerLabel = callerLabel;
     this.transitiveHashCode =
         computeTransitiveContentHashCode(fileContentHashCode, importedExtensions);
   }
@@ -485,6 +495,7 @@
     @Nullable private EventHandler eventHandler;
     @Nullable private Map<String, Extension> importedExtensions;
     @Nullable private String fileContentHashCode;
+    private Label label;
 
     Builder(Mutability mutability) {
       this.mutability = mutability;
@@ -549,7 +560,13 @@
           eventHandler,
           importedExtensions,
           fileContentHashCode,
-          phase);
+          phase,
+          label);
+    }
+
+    public Builder setCallerLabel(Label label) {
+      this.label = label;
+      return this;
     }
   }
 
@@ -558,6 +575,13 @@
   }
 
   /**
+   * Returns the caller's label.
+   */
+  public Label getCallerLabel() {
+    return callerLabel;
+  }
+
+  /**
    * Sets a binding for a special dynamic variable in this Environment.
    * This is not for end-users, and will throw an AssertionError in case of conflict.
    * @param varname the name of the dynamic variable to be bound
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 3a17fe5..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
@@ -14,8 +14,6 @@
 
 package com.google.devtools.build.lib.syntax;
 
-import com.google.devtools.build.lib.cmdline.Label;
-
 /** This class contains Bazel-specific functions to extend or interoperate with Skylark. */
 public final class SkylarkUtils {
 
@@ -25,7 +23,6 @@
   }
 
   private static final String BAZEL_INFO_KEY = "$bazel";
-  private static final String CALLER_LABEL_KEY = "$caller_label";
 
   private static BazelInfo getInfo(Environment env) {
     Object info = env.lookup(BAZEL_INFO_KEY);
@@ -49,23 +46,4 @@
   public static String getToolsRepository(Environment env) {
     return getInfo(env).toolsRepository;
   }
-
-  public static void setCallerLabel(Environment env, Label label) {
-    // We cannot store this information in BazelInfo, because we need to
-    // have it in the local environment (not the global environment).
-    try {
-      env.update(CALLER_LABEL_KEY, label);
-    } catch (EvalException e) {
-      throw new AssertionError(e);
-    }
-  }
-
-  /**
-   * Gets the label of the BUILD file that is using this environment. For example, if a target
-   * //foo has a dependency on //bar which is a Skylark rule defined in //rules:my_rule.bzl being
-   * evaluated in this environment, then this would return //foo.
-   */
-  public static Label getCallerLabel(Environment env) {
-    return (Label) env.lookup(CALLER_LABEL_KEY);
-  }
 }