Philipp Wollermann | 1572344e | 2015-06-29 13:59:45 +0000 | [diff] [blame] | 1 | // 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. |
| 14 | package com.google.devtools.build.lib.sandbox; |
| 15 | |
| 16 | import com.google.common.collect.ImmutableList; |
| 17 | import com.google.common.eventbus.Subscribe; |
| 18 | import com.google.devtools.build.lib.actions.ActionContextConsumer; |
| 19 | import com.google.devtools.build.lib.actions.ActionContextProvider; |
| 20 | import com.google.devtools.build.lib.buildtool.BuildRequest; |
| 21 | import com.google.devtools.build.lib.buildtool.buildevent.BuildStartingEvent; |
| 22 | import com.google.devtools.build.lib.runtime.BlazeModule; |
| 23 | import com.google.devtools.build.lib.runtime.BlazeRuntime; |
| 24 | import com.google.devtools.build.lib.runtime.Command; |
| 25 | |
| 26 | /** |
| 27 | * This module provides the Sandbox spawn strategy. |
| 28 | */ |
| 29 | public 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 | } |