Search in sources :

Example 1 with Spawn

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

the class StandaloneTestStrategy method exec.

@Override
public void exec(TestRunnerAction action, ActionExecutionContext actionExecutionContext) throws ExecException, InterruptedException {
    Path execRoot = actionExecutionContext.getExecutor().getExecRoot();
    Path coverageDir = execRoot.getRelative(action.getCoverageDirectory());
    Path runfilesDir = getLocalRunfilesDirectory(action, actionExecutionContext, binTools, action.getLocalShellEnvironment(), action.isEnableRunfiles());
    Path tmpDir = tmpDirRoot.getChild(getTmpDirName(action.getExecutionSettings().getExecutable().getExecPath()));
    Map<String, String> env = setupEnvironment(action, execRoot, runfilesDir, tmpDir);
    Path workingDirectory = runfilesDir.getRelative(action.getRunfilesPrefix());
    ResolvedPaths resolvedPaths = action.resolve(execRoot);
    Map<String, String> info = new HashMap<>();
    // This key is only understood by StandaloneSpawnStrategy.
    info.put("timeout", "" + getTimeout(action));
    info.putAll(action.getTestProperties().getExecutionInfo());
    Spawn spawn = new SimpleSpawn(action, getArgs(COLLECT_COVERAGE, action), ImmutableMap.copyOf(env), ImmutableMap.copyOf(info), new RunfilesSupplierImpl(runfilesDir.asFragment(), action.getExecutionSettings().getRunfiles()), /*inputs=*/
    ImmutableList.copyOf(action.getInputs()), /*tools=*/
    ImmutableList.<Artifact>of(), /*filesetManifests=*/
    ImmutableList.<Artifact>of(), ImmutableList.copyOf(action.getSpawnOutputs()), action.getTestProperties().getLocalResourceUsage(executionOptions.usingLocalTestJobs()));
    Executor executor = actionExecutionContext.getExecutor();
    TestResultData.Builder dataBuilder = TestResultData.newBuilder();
    try {
        int maxAttempts = getTestAttempts(action);
        TestResultData data = executeTestAttempt(action, spawn, actionExecutionContext, execRoot, coverageDir, tmpDir, workingDirectory);
        int attempt;
        for (attempt = 1; data.getStatus() != BlazeTestStatus.PASSED && attempt < maxAttempts; attempt++) {
            processFailedTestAttempt(attempt, executor, action, dataBuilder, data, actionExecutionContext.getFileOutErr());
            data = executeTestAttempt(action, spawn, actionExecutionContext, execRoot, coverageDir, tmpDir, workingDirectory);
        }
        processLastTestAttempt(attempt, dataBuilder, data);
        ImmutableList.Builder<Pair<String, Path>> testOutputsBuilder = new ImmutableList.Builder<>();
        if (action.getTestLog().getPath().exists()) {
            testOutputsBuilder.add(Pair.of("test.log", action.getTestLog().getPath()));
        }
        if (resolvedPaths.getXmlOutputPath().exists()) {
            testOutputsBuilder.add(Pair.of("test.xml", resolvedPaths.getXmlOutputPath()));
        }
        executor.getEventBus().post(new TestAttempt(action, attempt, data.getTestPassed(), data.getRunDurationMillis(), testOutputsBuilder.build(), true));
        finalizeTest(actionExecutionContext, action, dataBuilder.build());
    } catch (IOException e) {
        executor.getEventHandler().handle(Event.error("Caught I/O exception: " + e));
        throw new EnvironmentalExecException("unexpected I/O exception", e);
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) TestResultData(com.google.devtools.build.lib.view.test.TestStatus.TestResultData) HashMap(java.util.HashMap) SimpleSpawn(com.google.devtools.build.lib.actions.SimpleSpawn) ImmutableList(com.google.common.collect.ImmutableList) Builder(com.google.devtools.build.lib.view.test.TestStatus.TestResultData.Builder) IOException(java.io.IOException) EnvironmentalExecException(com.google.devtools.build.lib.actions.EnvironmentalExecException) RunfilesSupplierImpl(com.google.devtools.build.lib.analysis.RunfilesSupplierImpl) ResolvedPaths(com.google.devtools.build.lib.rules.test.TestRunnerAction.ResolvedPaths) Executor(com.google.devtools.build.lib.actions.Executor) Builder(com.google.devtools.build.lib.view.test.TestStatus.TestResultData.Builder) TestAttempt(com.google.devtools.build.lib.rules.test.TestAttempt) SimpleSpawn(com.google.devtools.build.lib.actions.SimpleSpawn) Spawn(com.google.devtools.build.lib.actions.Spawn) Pair(com.google.devtools.build.lib.util.Pair)

Example 2 with Spawn

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

the class StandaloneSpawnStrategyTest method testCommandHonorsEnvironment.

@Test
public void testCommandHonorsEnvironment() throws Exception {
    Spawn spawn = new BaseSpawn.Local(Arrays.asList("/usr/bin/env"), ImmutableMap.of("foo", "bar", "baz", "boo"), new ActionsTestUtil.NullAction(), ResourceSet.ZERO);
    run(spawn);
    assertEquals(Sets.newHashSet("foo=bar", "baz=boo"), Sets.newHashSet(out().split("\n")));
}
Also used : ActionsTestUtil(com.google.devtools.build.lib.actions.util.ActionsTestUtil) BaseSpawn(com.google.devtools.build.lib.actions.BaseSpawn) Spawn(com.google.devtools.build.lib.actions.Spawn) Test(org.junit.Test)

Example 3 with Spawn

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

the class StandaloneSpawnStrategyTest method testStandardError.

@Test
public void testStandardError() throws Exception {
    Spawn spawn = createSpawn("/bin/sh", "-c", "echo Oops! >&2");
    run(spawn);
    assertEquals("Oops!\n", err());
    assertThat(out()).isEmpty();
}
Also used : BaseSpawn(com.google.devtools.build.lib.actions.BaseSpawn) Spawn(com.google.devtools.build.lib.actions.Spawn) Test(org.junit.Test)

Example 4 with Spawn

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

the class CppLinkAction method execute.

@Override
@ThreadCompatible
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
    if (fake) {
        executeFake();
    } else {
        Executor executor = actionExecutionContext.getExecutor();
        try {
            // Collect input files
            List<ActionInput> allInputs = new ArrayList<>();
            Artifact.addExpandedArtifacts(getMandatoryInputs(), allInputs, actionExecutionContext.getArtifactExpander());
            ImmutableMap<String, String> executionInfo = ImmutableMap.of();
            if (needsToRunOnMac()) {
                executionInfo = ImmutableMap.of(ExecutionRequirements.REQUIRES_DARWIN, "");
            }
            Spawn spawn = new SimpleSpawn(this, ImmutableList.copyOf(getCommandLine()), getEnvironment(), executionInfo, ImmutableList.copyOf(allInputs), getOutputs().asList(), estimateResourceConsumptionLocal());
            executor.getSpawnActionContext(getMnemonic()).exec(spawn, actionExecutionContext);
        } catch (ExecException e) {
            throw e.toActionExecutionException("Linking of rule '" + getOwner().getLabel() + "'", executor.getVerboseFailures(), this);
        }
    }
}
Also used : Executor(com.google.devtools.build.lib.actions.Executor) ActionInput(com.google.devtools.build.lib.actions.ActionInput) SimpleSpawn(com.google.devtools.build.lib.actions.SimpleSpawn) ExecException(com.google.devtools.build.lib.actions.ExecException) ArrayList(java.util.ArrayList) SimpleSpawn(com.google.devtools.build.lib.actions.SimpleSpawn) Spawn(com.google.devtools.build.lib.actions.Spawn) ThreadCompatible(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible)

Example 5 with Spawn

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

the class PopulateTreeArtifactActionTest method testSpawnInputs.

@Test
public void testSpawnInputs() throws Exception {
    PopulateTreeArtifactAction action = createPopulateTreeArtifactAction();
    Spawn spawn = action.createSpawn();
    Iterable<Artifact> inputs = actionInputsToArtifacts(spawn.getInputFiles());
    assertThat(Artifact.toExecPaths(inputs)).containsExactly("myArchive.zip", "archiveManifest.txt", "unzipBinary");
}
Also used : BaseSpawn(com.google.devtools.build.lib.actions.BaseSpawn) Spawn(com.google.devtools.build.lib.actions.Spawn) 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)

Aggregations

Spawn (com.google.devtools.build.lib.actions.Spawn)13 BaseSpawn (com.google.devtools.build.lib.actions.BaseSpawn)10 Test (org.junit.Test)8 Artifact (com.google.devtools.build.lib.actions.Artifact)5 ActionInput (com.google.devtools.build.lib.actions.ActionInput)3 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)3 ExecException (com.google.devtools.build.lib.actions.ExecException)3 Executor (com.google.devtools.build.lib.actions.Executor)3 SimpleSpawn (com.google.devtools.build.lib.actions.SimpleSpawn)3 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)2 ActionsTestUtil (com.google.devtools.build.lib.actions.util.ActionsTestUtil)2 IOException (java.io.IOException)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)1 ArtifactPrefixConflictException (com.google.devtools.build.lib.actions.ArtifactPrefixConflictException)1 EnvironmentalExecException (com.google.devtools.build.lib.actions.EnvironmentalExecException)1 UserExecException (com.google.devtools.build.lib.actions.UserExecException)1 SpawnInfo (com.google.devtools.build.lib.actions.extra.SpawnInfo)1 RunfilesSupplierImpl (com.google.devtools.build.lib.analysis.RunfilesSupplierImpl)1