aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/Environment.java13
-rw-r--r--src/main/java/com/google/devtools/build/lib/syntax/SkylarkUtils.java23
2 files changed, 21 insertions, 15 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 fffacb65dc..08ff95b8b1 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 @@ public final class Environment implements Freezable {
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 @@ public final class Environment implements Freezable {
/**
* 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 875586f4f0..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
@@ -17,22 +17,33 @@ package com.google.devtools.build.lib.syntax;
/** 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;
+ }
+
+ 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;
+ }
- /** Unsafe version of Environment#update */
- private static void updateEnv(Environment env, String key, Object value) {
+ 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;
}
}