aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/syntax
diff options
context:
space:
mode:
authorGravatar Laurent Le Brun <laurentlb@google.com>2016-12-01 13:24:41 +0000
committerGravatar Irina Iancu <elenairina@google.com>2016-12-01 13:32:05 +0000
commit7c4a8093da6272969c86f22a08c72ddbbf6e8274 (patch)
tree7e32f416433c98f436d490d46917e4928cb8cc48 /src/main/java/com/google/devtools/build/lib/syntax
parent12c661013ec4f67c4200049c4bf289c4f43efc53 (diff)
Remove callerLabel from Environment.
It is a Bazel-specific information. -- MOS_MIGRATED_REVID=140719791
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, 24 insertions, 26 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 11515ef7d2..7029a59ce5 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,13 +336,6 @@ 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
@@ -463,7 +456,6 @@ 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,
@@ -471,8 +463,7 @@ public final class Environment implements Freezable {
EventHandler eventHandler,
Map<String, Extension> importedExtensions,
@Nullable String fileContentHashCode,
- Phase phase,
- @Nullable Label callerLabel) {
+ Phase phase) {
this.globalFrame = Preconditions.checkNotNull(globalFrame);
this.dynamicFrame = Preconditions.checkNotNull(dynamicFrame);
Preconditions.checkArgument(globalFrame.mutability().isMutable());
@@ -480,7 +471,6 @@ public final class Environment implements Freezable {
this.eventHandler = eventHandler;
this.importedExtensions = importedExtensions;
this.phase = phase;
- this.callerLabel = callerLabel;
this.transitiveHashCode =
computeTransitiveContentHashCode(fileContentHashCode, importedExtensions);
}
@@ -495,7 +485,6 @@ 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;
@@ -560,13 +549,7 @@ public final class Environment implements Freezable {
eventHandler,
importedExtensions,
fileContentHashCode,
- phase,
- label);
- }
-
- public Builder setCallerLabel(Label label) {
- this.label = label;
- return this;
+ phase);
}
}
@@ -575,13 +558,6 @@ 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 970543f60a..3a17fe519c 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,6 +14,8 @@
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 {
@@ -23,6 +25,7 @@ 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);
@@ -46,4 +49,23 @@ 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);
+ }
}