blob: 05442e6114f9e73b5b1e29623ef5595c9338e2c8 [file] [log] [blame]
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +00001// Copyright 2015 The Bazel Authors. 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.skyframe;
15
Florian Weikert92b22362015-12-03 10:17:18 +000016import static org.junit.Assert.assertSame;
Florian Weikert92b22362015-12-03 10:17:18 +000017
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000018import com.google.common.collect.ImmutableList;
19import com.google.common.collect.Sets;
20import com.google.devtools.build.lib.actions.AbstractAction;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000021import com.google.devtools.build.lib.actions.ActionExecutionContext;
22import com.google.devtools.build.lib.actions.ActionExecutionException;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000023import com.google.devtools.build.lib.actions.Artifact;
24import com.google.devtools.build.lib.actions.Executor;
25import com.google.devtools.build.lib.actions.ResourceSet;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000026import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
27import com.google.devtools.build.lib.actions.util.DummyExecutor;
28import com.google.devtools.build.lib.vfs.FileSystemUtils;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000029import java.io.IOException;
30import java.util.Collection;
31import java.util.Set;
Lukacs Berki5ea2b142017-02-28 10:46:53 +000032import org.junit.Test;
33import org.junit.runner.RunWith;
34import org.junit.runners.JUnit4;
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000035
36/**
37 * Tests that the data passed from the application to the Builder is passed
38 * down to each Action executed.
39 */
Florian Weikert92b22362015-12-03 10:17:18 +000040@RunWith(JUnit4.class)
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000041public class ActionDataTest extends TimestampBuilderTestCase {
42
Florian Weikert92b22362015-12-03 10:17:18 +000043 @Test
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000044 public void testArgumentToBuildArtifactsIsPassedDownToAction() throws Exception {
45
46 class MyAction extends AbstractAction {
47
48 Object executor = null;
49
50 public MyAction(Collection<Artifact> outputs) {
51 super(ActionsTestUtil.NULL_ACTION_OWNER, ImmutableList.<Artifact>of(), outputs);
52 }
53
54 @Override
55 public void execute(ActionExecutionContext actionExecutionContext)
56 throws ActionExecutionException {
57 this.executor = actionExecutionContext.getExecutor();
58 try {
59 FileSystemUtils.createEmptyFile(getPrimaryOutput().getPath());
60 } catch (IOException e) {
61 throw new ActionExecutionException("failed: ", e, this, false);
62 }
63 }
64
65 @Override
66 public ResourceSet estimateResourceConsumption(Executor executor) {
67 return ResourceSet.ZERO;
68 }
69
70 @Override
71 protected String computeKey() {
72 return "MyAction";
73 }
74
75 @Override
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000076 public String getMnemonic() {
77 return "MyAction";
78 }
79 }
80
81 Artifact output = createDerivedArtifact("foo");
82 Set<Artifact> outputs = Sets.newHashSet(output);
83
84 MyAction action = new MyAction(outputs);
85 registerAction(action);
86
87 Executor executor = new DummyExecutor(scratch.dir("/"));
88 amnesiacBuilder()
89 .buildArtifacts(
Googlerbfd4e242016-07-15 22:23:37 +000090 reporter, outputs, null, null, null, null, executor, null, /*explain=*/ false, null,
91 null);
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000092 assertSame(executor, action.executor);
93
94 executor = new DummyExecutor(scratch.dir("/"));
95 amnesiacBuilder()
96 .buildArtifacts(
Googlerbfd4e242016-07-15 22:23:37 +000097 reporter, outputs, null, null, null, null, executor, null, /*explain=*/ false, null,
98 null);
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +000099 assertSame(executor, action.executor);
100 }
Han-Wen Nienhuys81b90832015-10-26 16:57:27 +0000101}