Skip to content

Commit

Permalink
Create a Bootstrap for config-related libraries of skylarkbuildapi.
Browse files Browse the repository at this point in the history
RELNOTES: None.
PiperOrigin-RevId: 198906931
  • Loading branch information
c-parsons authored and Copybara-Service committed Jun 1, 2018
1 parent 218e543 commit fc47454
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.runtime.proto.InvocationPolicyOuterClass.InvocationPolicy;
import com.google.devtools.build.lib.skyframe.ConfiguredTargetAndData;
import com.google.devtools.build.lib.skylarkbuildapi.Bootstrap;
import com.google.devtools.build.lib.skylarkinterface.SkylarkInterfaceUtils;
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule;
import com.google.devtools.build.lib.syntax.Environment;
Expand Down Expand Up @@ -238,6 +239,8 @@ public static class Builder implements RuleDefinitionEnvironment {
new ArrayList<>();
@Nullable private RuleTransitionFactory trimmingTransitionFactory;
private PrerequisiteValidator prerequisiteValidator;
private ImmutableList.Builder<Bootstrap> skylarkBootstraps =
ImmutableList.<Bootstrap>builder();
private ImmutableMap.Builder<String, Object> skylarkAccessibleTopLevels =
ImmutableMap.builder();
private ImmutableList.Builder<Class<?>> skylarkModules =
Expand Down Expand Up @@ -358,6 +361,11 @@ public Builder addUniversalConfigurationFragment(
return this;
}

public Builder addSkylarkBootstrap(Bootstrap bootstrap) {
this.skylarkBootstraps.add(bootstrap);
return this;
}

public Builder addSkylarkAccessibleTopLevels(String name, Object object) {
this.skylarkAccessibleTopLevels.put(name, object);
return this;
Expand Down Expand Up @@ -514,6 +522,7 @@ public ConfiguredRuleClassProvider build() {
trimmingTransitionFactory,
prerequisiteValidator,
skylarkAccessibleTopLevels.build(),
skylarkBootstraps.build(),
skylarkModules.build(),
ImmutableSet.copyOf(reservedActionMnemonics),
actionEnvironmentProvider,
Expand Down Expand Up @@ -651,6 +660,7 @@ private ConfiguredRuleClassProvider(
@Nullable RuleTransitionFactory trimmingTransitionFactory,
PrerequisiteValidator prerequisiteValidator,
ImmutableMap<String, Object> skylarkAccessibleJavaClasses,
ImmutableList<Bootstrap> skylarkBootstraps,
ImmutableList<Class<?>> skylarkModules,
ImmutableSet<String> reservedActionMnemonics,
BuildConfiguration.ActionEnvironmentProvider actionEnvironmentProvider,
Expand All @@ -670,7 +680,7 @@ private ConfiguredRuleClassProvider(
this.universalFragments = universalFragments;
this.trimmingTransitionFactory = trimmingTransitionFactory;
this.prerequisiteValidator = prerequisiteValidator;
this.globals = createGlobals(skylarkAccessibleJavaClasses, skylarkModules);
this.globals = createGlobals(skylarkAccessibleJavaClasses, skylarkBootstraps, skylarkModules);
this.reservedActionMnemonics = reservedActionMnemonics;
this.actionEnvironmentProvider = actionEnvironmentProvider;
this.configurationFragmentMap = createFragmentMap(configurationFragmentFactories);
Expand Down Expand Up @@ -795,6 +805,7 @@ public BuildOptions createBuildOptions(OptionsClassProvider optionsProvider) {

private Environment.GlobalFrame createGlobals(
ImmutableMap<String, Object> skylarkAccessibleTopLevels,
ImmutableList<Bootstrap> bootstraps,
ImmutableList<Class<?>> modules) {
ImmutableMap.Builder<String, Object> envBuilder = ImmutableMap.builder();

Expand All @@ -803,6 +814,9 @@ private Environment.GlobalFrame createGlobals(
Runtime.setupModuleGlobals(envBuilder, module);
}
envBuilder.putAll(skylarkAccessibleTopLevels.entrySet());
for (Bootstrap bootstrap : bootstraps) {
bootstrap.addBindingsToBuilder(envBuilder);
}

return GlobalFrame.createForBuiltins(envBuilder.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider;
import com.google.devtools.build.lib.analysis.ConfiguredRuleClassProvider.RuleSet;
import com.google.devtools.build.lib.rules.core.CoreRules;
import com.google.devtools.build.lib.skylarkbuildapi.config.ConfigBootstrap;

/**
* Set of rules to specify or manipulate configuration settings.
Expand All @@ -39,7 +40,7 @@ public void init(ConfiguredRuleClassProvider.Builder builder) {
new ConfigFeatureFlagConfiguration.Loader());

builder.addRuleDefinition(new ConfigRuleClasses.ConfigFeatureFlagRule());
builder.addSkylarkAccessibleTopLevels("config_common", new ConfigSkylarkCommon());
builder.addSkylarkBootstrap(new ConfigBootstrap(new ConfigSkylarkCommon()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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.config;

import com.google.common.collect.ImmutableMap.Builder;
import com.google.devtools.build.lib.skylarkbuildapi.Bootstrap;

/**
* A {@link Bootstrap} for config-related libraries of the build API.
*/
public class ConfigBootstrap implements Bootstrap {

private final ConfigSkylarkCommonApi configSkylarkCommonApi;

public ConfigBootstrap(ConfigSkylarkCommonApi configSkylarkCommonApi) {
this.configSkylarkCommonApi = configSkylarkCommonApi;
}

@Override
public void addBindingsToBuilder(Builder<String, Object> builder) {
builder.put("config_common", configSkylarkCommonApi);
}
}

0 comments on commit fc47454

Please sign in to comment.