diff options
author | Laurent Le Brun <laurentlb@google.com> | 2016-11-22 14:48:44 +0000 |
---|---|---|
committer | Dmitry Lomov <dslomov@google.com> | 2016-11-22 18:14:59 +0000 |
commit | 27d0b32ce5356d209d48c8912b22db5eeb5794e1 (patch) | |
tree | 292f6ec4a0a99b5565fd6620082374d7b9c7aba3 /src/main/java/com/google/devtools | |
parent | a3059e067c245fd56896f477e8a09978d5417823 (diff) |
Minor refactoring in SkylarkUtils
Next step will be to move Environment.Phase to SkylarkUtils.BazelInfo
--
MOS_MIGRATED_REVID=139902745
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/Environment.java | 13 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/SkylarkUtils.java | 23 |
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; } } |