aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax
diff options
context:
space:
mode:
authorGravatar Kristina Chodorow <kchodorow@google.com>2016-12-01 17:47:52 +0000
committerGravatar Irina Iancu <elenairina@google.com>2016-12-02 07:42:27 +0000
commit704d8d971b887c7706e93c898e83d685ffffb2f7 (patch)
tree4dedf61f2962bf6e4400c22bf951b98579e5aa4e /src/main/java/com/google/devtools/build/lib/syntax
parent3875712ca6cabaa447b008038225072ee52b24c2 (diff)
*** 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
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax')
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/Environment.java28
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/SkylarkUtils.java22
2 files changed, 26 insertions, 24 deletions
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 7029a59ce5..11515ef7d2 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 @@ public final class Environment implements Freezable {
@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 @@ public final class Environment implements Freezable {
* @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 @@ public final class Environment implements Freezable {
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 @@ public final class Environment implements Freezable {
this.eventHandler = eventHandler;
this.importedExtensions = importedExtensions;
this.phase = phase;
+ this.callerLabel = callerLabel;
this.transitiveHashCode =
computeTransitiveContentHashCode(fileContentHashCode, importedExtensions);
}
@@ -485,6 +495,7 @@ public final class Environment implements Freezable {
@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 @@ public final class Environment implements Freezable {
eventHandler,
importedExtensions,
fileContentHashCode,
- phase);
+ phase,
+ label);
+ }
+
+ public Builder setCallerLabel(Label label) {
+ this.label = label;
+ return this;
}
}
@@ -558,6 +575,13 @@ public final class Environment implements Freezable {
}
/**
+ * 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 3a17fe519c..970543f60a 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 @@ public final class SkylarkUtils {
}
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 final class SkylarkUtils {
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);
- }
}