diff options
author | cparsons <cparsons@google.com> | 2018-05-23 10:01:20 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-05-23 10:02:24 -0700 |
commit | cf3e59d30e56d79163a5006e079e04eadb026541 (patch) | |
tree | 2595dd7555337fd6b0a97a9b507d27f15f83ab95 /src/main/java/com/google/devtools/build/lib/skylarkbuildapi | |
parent | a1a990e42bab1bed01a7dff02a8b214c23f3dae4 (diff) |
Create GlobalBootstrap and the Bootstrap interface to add portions of the build API to a global environment.
RELNOTES: None.
PiperOrigin-RevId: 197742427
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skylarkbuildapi')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skylarkbuildapi/Bootstrap.java | 31 | ||||
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TopLevelBootstrap.java | 51 |
2 files changed, 82 insertions, 0 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/Bootstrap.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/Bootstrap.java new file mode 100644 index 0000000000..5d531dacbc --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/Bootstrap.java @@ -0,0 +1,31 @@ +// Copyright 2018 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.skylarkbuildapi; + +import com.google.common.collect.ImmutableMap; + +/** + * A helper for registering a portion of the build API to skylark environment globals. + * + * <p>A global environment may be initialized by tabulating globals into a single map by passing + * a single map builder to {@link #addBindingsToBuilder} for several bootstrap helpers. + */ +public interface Bootstrap { + + /** + * Adds this bootstrap's bindings to the given environment map builder. + */ + public void addBindingsToBuilder(ImmutableMap.Builder<String, Object> builder); +} diff --git a/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TopLevelBootstrap.java b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TopLevelBootstrap.java new file mode 100644 index 0000000000..910a67a39b --- /dev/null +++ b/src/main/java/com/google/devtools/build/lib/skylarkbuildapi/TopLevelBootstrap.java @@ -0,0 +1,51 @@ +// Copyright 2018 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.skylarkbuildapi; + +import com.google.common.collect.ImmutableMap; +import com.google.devtools.build.lib.syntax.Runtime; + +/** + * A {@link Bootstrap} for top-level libraries of the build API. + */ +public class TopLevelBootstrap implements Bootstrap { + private final Class<? extends SkylarkBuildApiGlobals> skylarkBuildApiGlobals; + private final Class<? extends SkylarkAttrApi> skylarkAttrApi; + private final Class<? extends SkylarkCommandLineApi> skylarkCommandLineApi; + private final Class<? extends SkylarkNativeModuleApi> skylarkNativeModuleApi; + private final Class<? extends SkylarkRuleFunctionsApi<?>> skylarkRuleFunctionsApi; + + public TopLevelBootstrap( + Class<? extends SkylarkBuildApiGlobals> skylarkBuildApiGlobals, + Class<? extends SkylarkAttrApi> skylarkAttrApi, + Class<? extends SkylarkCommandLineApi> skylarkCommandLineApi, + Class<? extends SkylarkNativeModuleApi> skylarkNativeModuleApi, + Class<? extends SkylarkRuleFunctionsApi<?>> skylarkRuleFunctionsApi) { + this.skylarkAttrApi = skylarkAttrApi; + this.skylarkBuildApiGlobals = skylarkBuildApiGlobals; + this.skylarkCommandLineApi = skylarkCommandLineApi; + this.skylarkNativeModuleApi = skylarkNativeModuleApi; + this.skylarkRuleFunctionsApi = skylarkRuleFunctionsApi; + } + + @Override + public void addBindingsToBuilder(ImmutableMap.Builder<String, Object> builder) { + Runtime.setupModuleGlobals(builder, skylarkAttrApi); + Runtime.setupModuleGlobals(builder, skylarkBuildApiGlobals); + Runtime.setupModuleGlobals(builder, skylarkCommandLineApi); + Runtime.setupModuleGlobals(builder, skylarkNativeModuleApi); + Runtime.setupModuleGlobals(builder, skylarkRuleFunctionsApi); + } +} |