blob: 65d0c1537959d3c9b93487f6e5d979598a34f34c [file] [log] [blame]
Philipp Wollermann1572344e2015-06-29 13:59:45 +00001// Copyright 2015 Google Inc. All rights reserved.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14package com.google.devtools.build.lib.sandbox;
15
16import com.google.common.collect.ImmutableList;
17import com.google.common.eventbus.Subscribe;
18import com.google.devtools.build.lib.actions.ActionContextConsumer;
19import com.google.devtools.build.lib.actions.ActionContextProvider;
20import com.google.devtools.build.lib.buildtool.BuildRequest;
21import com.google.devtools.build.lib.buildtool.buildevent.BuildStartingEvent;
22import com.google.devtools.build.lib.runtime.BlazeModule;
23import com.google.devtools.build.lib.runtime.BlazeRuntime;
24import com.google.devtools.build.lib.runtime.Command;
25
26/**
27 * This module provides the Sandbox spawn strategy.
28 */
29public class SandboxModule extends BlazeModule {
30 private BuildRequest buildRequest;
31 private BlazeRuntime runtime;
32
33 @Override
34 public Iterable<ActionContextProvider> getActionContextProviders() {
35 return ImmutableList.<ActionContextProvider>of(
36 new SandboxActionContextProvider(runtime, buildRequest));
37 }
38
39 @Override
40 public Iterable<ActionContextConsumer> getActionContextConsumers() {
41 return ImmutableList.<ActionContextConsumer>of(new SandboxActionContextConsumer());
42 }
43
44 @Override
45 public void beforeCommand(BlazeRuntime runtime, Command command) {
46 this.runtime = runtime;
47 runtime.getEventBus().register(this);
48 }
49
50 @Subscribe
51 public void buildStarting(BuildStartingEvent event) {
52 buildRequest = event.getRequest();
53 }
54}