diff options
author | Laurent Le Brun <laurentlb@google.com> | 2016-10-27 12:48:22 +0000 |
---|---|---|
committer | John Cater <jcater@google.com> | 2016-10-27 17:11:20 +0000 |
commit | a31bc4eb21c0f07a6558c22f3d17bff656a9648a (patch) | |
tree | e9a5e601287e7fa1ac6c248015f30a59c1bf6722 /src/main/java/com/google/devtools/build/lib/syntax/SkylarkUtils.java | |
parent | 238839cd79ac7bef427df7e6604992b02eff05b7 (diff) |
Move ToolsRepository out of Environment
Other fields will follow (is_skylark, phase, callerLabel).
The goal is to make Environment (and more generally Skylark) less dependent
on Bazel.
--
MOS_MIGRATED_REVID=137386248
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/syntax/SkylarkUtils.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/syntax/SkylarkUtils.java | 38 |
1 files changed, 38 insertions, 0 deletions
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 new file mode 100644 index 0000000000..875586f4f0 --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/syntax/SkylarkUtils.java @@ -0,0 +1,38 @@ +// Copyright 2016 The Bazel Authors. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +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"; + + /** Unsafe version of Environment#update */ + private static void updateEnv(Environment env, String key, Object value) { + try { + env.update(key, value); + } catch (EvalException e) { + throw new AssertionError(e); + } + } + + public static void setToolsRepository(Environment env, String toolsRepository) { + updateEnv(env, TOOLS_REPOSITORY, toolsRepository); + } + + public static String getToolsRepository(Environment env) { + return (String) env.lookup(TOOLS_REPOSITORY); + } +} |