Search in sources :

Example 11 with ActionExecutionContext

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

the class PopulateTreeArtifactActionTest method testTreeArtifactPopulated.

@Test
public void testTreeArtifactPopulated() throws Exception {
    ArrayList<Artifact> treefileArtifacts = new ArrayList<Artifact>();
    PopulateTreeArtifactAction action = createPopulateTreeArtifactAction();
    ActionExecutionContext executionContext = actionExecutionContext(treefileArtifacts);
    action.execute(executionContext);
    assertThat(Artifact.toExecPaths(treefileArtifacts)).containsExactly("test/archive_member/archive_members/1.class", "test/archive_member/archive_members/2.class", "test/archive_member/archive_members/txt/text.txt");
}
Also used : ArrayList(java.util.ArrayList) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Example 12 with ActionExecutionContext

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

the class LTOBackendActionTest method createExecutorAndContext.

@Before
public final void createExecutorAndContext() throws Exception {
    executor = new TestExecutorBuilder(directories, binTools).build();
    context = new ActionExecutionContext(executor, null, null, new FileOutErr(), ImmutableMap.<String, String>of(), null);
}
Also used : TestExecutorBuilder(com.google.devtools.build.lib.exec.util.TestExecutorBuilder) FileOutErr(com.google.devtools.build.lib.util.io.FileOutErr) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) Before(org.junit.Before)

Example 13 with ActionExecutionContext

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

the class ActionExecutionFunction method checkCacheAndExecuteIfNeeded.

private ActionExecutionValue checkCacheAndExecuteIfNeeded(Action action, ContinuationState state, Environment env, Map<String, String> clientEnv) throws ActionExecutionException, InterruptedException {
    // other action's value, provided here, since it is populated with metadata for the outputs.
    if (!state.hasArtifactData()) {
        return skyframeActionExecutor.executeAction(action, null, -1, null);
    }
    // This may be recreated if we discover inputs.
    ActionMetadataHandler metadataHandler = new ActionMetadataHandler(state.inputArtifactData, action.getOutputs(), tsgm.get());
    long actionStartTime = BlazeClock.nanoTime();
    // We only need to check the action cache if we haven't done it on a previous run.
    if (!state.hasCheckedActionCache()) {
        state.token = skyframeActionExecutor.checkActionCache(action, metadataHandler, actionStartTime, state.allInputs.actionCacheInputs, clientEnv);
    }
    if (state.token == null) {
        // We got a hit from the action cache -- no need to execute.
        return new ActionExecutionValue(metadataHandler.getOutputArtifactData(), metadataHandler.getOutputTreeArtifactData(), metadataHandler.getAdditionalOutputData());
    }
    // This may be recreated if we discover inputs.
    PerActionFileCache perActionFileCache = new PerActionFileCache(state.inputArtifactData);
    ActionExecutionContext actionExecutionContext = null;
    try {
        if (action.discoversInputs()) {
            if (state.discoveredInputs == null) {
                try {
                    state.discoveredInputs = skyframeActionExecutor.discoverInputs(action, perActionFileCache, metadataHandler, env);
                    Preconditions.checkState(state.discoveredInputs != null, "discoverInputs() returned null on action %s", action);
                } catch (MissingDepException e) {
                    Preconditions.checkState(env.valuesMissing(), action);
                    return null;
                }
            }
            addDiscoveredInputs(state.inputArtifactData, state.expandedArtifacts, state.discoveredInputs, env);
            if (env.valuesMissing()) {
                return null;
            }
            perActionFileCache = new PerActionFileCache(state.inputArtifactData);
            metadataHandler = new ActionMetadataHandler(state.inputArtifactData, action.getOutputs(), tsgm.get());
            // available.
            if (state.discoveredInputsStage2 == null) {
                state.discoveredInputsStage2 = action.discoverInputsStage2(env);
            }
            if (state.discoveredInputsStage2 != null) {
                addDiscoveredInputs(state.inputArtifactData, state.expandedArtifacts, state.discoveredInputsStage2, env);
                if (env.valuesMissing()) {
                    return null;
                }
                perActionFileCache = new PerActionFileCache(state.inputArtifactData);
                metadataHandler = new ActionMetadataHandler(state.inputArtifactData, action.getOutputs(), tsgm.get());
            }
        }
        actionExecutionContext = skyframeActionExecutor.getContext(perActionFileCache, metadataHandler, Collections.unmodifiableMap(state.expandedArtifacts));
        if (!state.hasExecutedAction()) {
            state.value = skyframeActionExecutor.executeAction(action, metadataHandler, actionStartTime, actionExecutionContext);
        }
    } finally {
        if (actionExecutionContext != null) {
            try {
                actionExecutionContext.getFileOutErr().close();
            } catch (IOException e) {
            // Nothing we can do here.
            }
        }
    }
    if (action.discoversInputs()) {
        Iterable<Artifact> newInputs = filterKnownInputs(action.getInputs(), state.inputArtifactData.keySet());
        Map<SkyKey, SkyValue> metadataFoundDuringActionExecution = env.getValues(toKeys(newInputs, action.getMandatoryInputs()));
        state.discoveredInputs = newInputs;
        if (env.valuesMissing()) {
            return null;
        }
        if (!Iterables.isEmpty(newInputs)) {
            // We are in the interesting case of an action that discovered its inputs during
            // execution, and found some new ones, but the new ones were already present in the graph.
            // We must therefore cache the metadata for those new ones.
            Map<Artifact, FileArtifactValue> inputArtifactData = new HashMap<>();
            inputArtifactData.putAll(state.inputArtifactData);
            for (Map.Entry<SkyKey, SkyValue> entry : metadataFoundDuringActionExecution.entrySet()) {
                inputArtifactData.put(ArtifactSkyKey.artifact(entry.getKey()), (FileArtifactValue) entry.getValue());
            }
            state.inputArtifactData = inputArtifactData;
            metadataHandler = new ActionMetadataHandler(state.inputArtifactData, action.getOutputs(), tsgm.get());
        }
    }
    Preconditions.checkState(!env.valuesMissing(), action);
    skyframeActionExecutor.afterExecution(action, metadataHandler, state.token, clientEnv);
    return state.value;
}
Also used : SkyKey(com.google.devtools.build.skyframe.SkyKey) HashMap(java.util.HashMap) IOException(java.io.IOException) Artifact(com.google.devtools.build.lib.actions.Artifact) SkyValue(com.google.devtools.build.skyframe.SkyValue) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map)

Example 14 with ActionExecutionContext

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

the class PopulateTreeArtifactActionTest method testInvalidManifestEntryPaths.

@Test
public void testInvalidManifestEntryPaths() throws Exception {
    Action action = createPopulateTreeArtifactAction();
    scratch.overwriteFile("archiveManifest.txt", "archive_members/1.class", "../invalid_relative_path/myfile.class");
    ActionExecutionContext executionContext = actionExecutionContext(new ArrayList<Artifact>());
    try {
        action.execute(executionContext);
        fail("Invalid manifest entry paths, expected exception");
    } catch (ActionExecutionException e) {
    // Expect ActionExecutionException
    }
}
Also used : Action(com.google.devtools.build.lib.actions.Action) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) Test(org.junit.Test)

Example 15 with ActionExecutionContext

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

the class TreeArtifactBuildTest method testInvalidSymlinkRejected.

@Test
public void testInvalidSymlinkRejected() throws Exception {
    // Failure expected
    StoredEventHandler storingEventHandler = new StoredEventHandler();
    reporter.removeHandler(failFastHandler);
    reporter.addHandler(storingEventHandler);
    final Artifact out = createTreeArtifact("output");
    TreeArtifactTestAction action = new TreeArtifactTestAction(out) {

        @Override
        public void execute(ActionExecutionContext actionExecutionContext) {
            try {
                writeFile(out.getPath().getChild("one"), "one");
                writeFile(out.getPath().getChild("two"), "two");
                FileSystemUtils.ensureSymbolicLink(out.getPath().getChild("links").getChild("link"), "../invalid");
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    };
    registerAction(action);
    try {
        buildArtifact(action.getSoleOutput());
        // Should have thrown
        fail();
    } catch (BuildFailedException e) {
        List<Event> errors = ImmutableList.copyOf(Iterables.filter(storingEventHandler.getEvents(), IS_ERROR_EVENT));
        assertThat(errors).hasSize(2);
        assertThat(errors.get(0).getMessage()).contains("Failed to resolve relative path links/link");
        assertThat(errors.get(1).getMessage()).contains("not all outputs were created or valid");
    }
}
Also used : StoredEventHandler(com.google.devtools.build.lib.events.StoredEventHandler) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) ActionExecutionContext(com.google.devtools.build.lib.actions.ActionExecutionContext) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SpecialArtifact(com.google.devtools.build.lib.actions.Artifact.SpecialArtifact) Artifact(com.google.devtools.build.lib.actions.Artifact) ActionInputHelper.treeFileArtifact(com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) BuildFailedException(com.google.devtools.build.lib.actions.BuildFailedException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

ActionExecutionContext (com.google.devtools.build.lib.actions.ActionExecutionContext)24 Test (org.junit.Test)19 Artifact (com.google.devtools.build.lib.actions.Artifact)17 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)13 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)13 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)13 IOException (java.io.IOException)12 BuildFailedException (com.google.devtools.build.lib.actions.BuildFailedException)10 Action (com.google.devtools.build.lib.actions.Action)7 ActionInputHelper.treeFileArtifact (com.google.devtools.build.lib.actions.ActionInputHelper.treeFileArtifact)7 ImmutableList (com.google.common.collect.ImmutableList)4 StoredEventHandler (com.google.devtools.build.lib.events.StoredEventHandler)4 TestExecutorBuilder (com.google.devtools.build.lib.exec.util.TestExecutorBuilder)4 List (java.util.List)4 Executor (com.google.devtools.build.lib.actions.Executor)3 FileOutErr (com.google.devtools.build.lib.util.io.FileOutErr)3 ArrayList (java.util.ArrayList)3 TestAction (com.google.devtools.build.lib.actions.util.TestAction)2 Collection (java.util.Collection)2 Before (org.junit.Before)2