Search in sources :

Example 1 with AbstractAction

use of com.google.devtools.build.lib.actions.AbstractAction in project bazel by bazelbuild.

the class ActionDataTest method testArgumentToBuildArtifactsIsPassedDownToAction.

@Test
public void testArgumentToBuildArtifactsIsPassedDownToAction() throws Exception {
    class MyAction extends AbstractAction {

        Object executor = null;

        public MyAction(Collection<Artifact> outputs) {
            super(ActionsTestUtil.NULL_ACTION_OWNER, ImmutableList.<Artifact>of(), outputs);
        }

        @Override
        public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException {
            this.executor = actionExecutionContext.getExecutor();
            try {
                FileSystemUtils.createEmptyFile(getPrimaryOutput().getPath());
            } catch (IOException e) {
                throw new ActionExecutionException("failed: ", e, this, false);
            }
        }

        @Override
        protected String computeKey() {
            return "MyAction";
        }

        @Override
        public String getMnemonic() {
            return "MyAction";
        }
    }
    Artifact output = createDerivedArtifact("foo");
    Set<Artifact> outputs = Sets.newHashSet(output);
    MyAction action = new MyAction(outputs);
    registerAction(action);
    Executor executor = new DummyExecutor(scratch.dir("/"));
    amnesiacBuilder().buildArtifacts(reporter, outputs, null, null, null, null, executor, null, /*explain=*/
    false, null, null);
    assertSame(executor, action.executor);
    executor = new DummyExecutor(scratch.dir("/"));
    amnesiacBuilder().buildArtifacts(reporter, outputs, null, null, null, null, executor, null, /*explain=*/
    false, null, null);
    assertSame(executor, action.executor);
}
Also used : DummyExecutor(com.google.devtools.build.lib.actions.util.DummyExecutor) Executor(com.google.devtools.build.lib.actions.Executor) DummyExecutor(com.google.devtools.build.lib.actions.util.DummyExecutor) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) Collection(java.util.Collection) IOException(java.io.IOException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) AbstractAction(com.google.devtools.build.lib.actions.AbstractAction) Artifact(com.google.devtools.build.lib.actions.Artifact) Test(org.junit.Test)

Aggregations

AbstractAction (com.google.devtools.build.lib.actions.AbstractAction)1 ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)1 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 Executor (com.google.devtools.build.lib.actions.Executor)1 DummyExecutor (com.google.devtools.build.lib.actions.util.DummyExecutor)1 IOException (java.io.IOException)1 Collection (java.util.Collection)1 Test (org.junit.Test)1