Search in sources :

Example 1 with EnvironmentalExecException

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

the class DarwinSandboxedStrategy method getMounts.

@Override
public Map<PathFragment, Path> getMounts(Spawn spawn, ActionExecutionContext executionContext) throws ExecException {
    try {
        Map<PathFragment, Path> mounts = new HashMap<>();
        spawnHelpers.mountInputs(mounts, spawn, executionContext);
        Map<PathFragment, Path> unfinalized = new HashMap<>();
        spawnHelpers.mountRunfilesFromSuppliers(unfinalized, spawn);
        spawnHelpers.mountFilesFromFilesetManifests(unfinalized, spawn, executionContext);
        mounts.putAll(finalizeLinks(unfinalized));
        return mounts;
    } catch (IllegalArgumentException | IOException e) {
        throw new EnvironmentalExecException("Could not prepare mounts for sandbox execution", e);
    }
}
Also used : SearchPath(com.google.devtools.build.lib.vfs.SearchPath) Path(com.google.devtools.build.lib.vfs.Path) HashMap(java.util.HashMap) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) EnvironmentalExecException(com.google.devtools.build.lib.actions.EnvironmentalExecException)

Example 2 with EnvironmentalExecException

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

the class SandboxStrategy method getMounts.

public Map<PathFragment, Path> getMounts(Spawn spawn, ActionExecutionContext executionContext) throws ExecException {
    try {
        Map<PathFragment, ActionInput> inputMap = spawnInputExpander.getInputMapping(spawn, executionContext.getArtifactExpander(), executionContext.getActionInputFileCache(), executionContext.getExecutor().getContext(FilesetActionContext.class));
        Map<PathFragment, Path> mounts = new TreeMap<>();
        for (Map.Entry<PathFragment, ActionInput> e : inputMap.entrySet()) {
            mounts.put(e.getKey(), execRoot.getRelative(e.getValue().getExecPath()));
        }
        // inputs.
        for (ActionInput input : spawn.getInputFiles()) {
            if (input instanceof Artifact && ((Artifact) input).isTreeArtifact()) {
                List<Artifact> containedArtifacts = new ArrayList<>();
                executionContext.getArtifactExpander().expand((Artifact) input, containedArtifacts);
                // only mount empty TreeArtifacts as directories.
                if (containedArtifacts.isEmpty()) {
                    inputMap.put(input.getExecPath(), input);
                }
            }
        }
        return mounts;
    } catch (IOException e) {
        throw new EnvironmentalExecException("Could not prepare mounts for sandbox execution", e);
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ActionInput(com.google.devtools.build.lib.actions.ActionInput) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ArrayList(java.util.ArrayList) IOException(java.io.IOException) EnvironmentalExecException(com.google.devtools.build.lib.actions.EnvironmentalExecException) TreeMap(java.util.TreeMap) FilesetActionContext(com.google.devtools.build.lib.rules.fileset.FilesetActionContext) Artifact(com.google.devtools.build.lib.actions.Artifact) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 3 with EnvironmentalExecException

use of com.google.devtools.build.lib.actions.EnvironmentalExecException 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 4 with EnvironmentalExecException

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

the class HeaderThinning method findRequiredHeaderInputs.

/**
   * Reads the header scanning output file and discovers all of those headers as input artifacts.
   *
   * @param sourceFile the source that requires these headers
   * @param headersListFile .headers_list file output from header_scanner tool to be read
   * @param inputArtifactsMap map of PathFragment to Artifact of possible headers
   * @return collection of header artifacts that are required for {@code action} to compile
   * @throws ExecException on environmental (IO) or user errors
   */
public static Iterable<Artifact> findRequiredHeaderInputs(Artifact sourceFile, Artifact headersListFile, Map<PathFragment, Artifact> inputArtifactsMap) throws ExecException {
    try {
        ImmutableList.Builder<Artifact> includeBuilder = ImmutableList.builder();
        List<PathFragment> missing = new ArrayList<>();
        for (String line : FileSystemUtils.readLines(headersListFile.getPath(), StandardCharsets.UTF_8)) {
            if (line.isEmpty()) {
                continue;
            }
            PathFragment headerPath = new PathFragment(line);
            Artifact header = inputArtifactsMap.get(headerPath);
            if (header == null) {
                missing.add(headerPath);
            } else {
                includeBuilder.add(header);
            }
        }
        if (!missing.isEmpty()) {
            includeBuilder.addAll(findRequiredHeaderInputsInTreeArtifacts(sourceFile, inputArtifactsMap, missing));
        }
        return includeBuilder.build();
    } catch (IOException ex) {
        throw new EnvironmentalExecException(String.format("Error reading headers file %s", headersListFile.getExecPathString()), ex);
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ArrayList(java.util.ArrayList) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) IOException(java.io.IOException) EnvironmentalExecException(com.google.devtools.build.lib.actions.EnvironmentalExecException) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

EnvironmentalExecException (com.google.devtools.build.lib.actions.EnvironmentalExecException)4 IOException (java.io.IOException)4 Path (com.google.devtools.build.lib.vfs.Path)3 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)3 ImmutableList (com.google.common.collect.ImmutableList)2 Artifact (com.google.devtools.build.lib.actions.Artifact)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ActionInput (com.google.devtools.build.lib.actions.ActionInput)1 Executor (com.google.devtools.build.lib.actions.Executor)1 SimpleSpawn (com.google.devtools.build.lib.actions.SimpleSpawn)1 Spawn (com.google.devtools.build.lib.actions.Spawn)1 RunfilesSupplierImpl (com.google.devtools.build.lib.analysis.RunfilesSupplierImpl)1 FilesetActionContext (com.google.devtools.build.lib.rules.fileset.FilesetActionContext)1 TestAttempt (com.google.devtools.build.lib.rules.test.TestAttempt)1 ResolvedPaths (com.google.devtools.build.lib.rules.test.TestRunnerAction.ResolvedPaths)1 Pair (com.google.devtools.build.lib.util.Pair)1 SearchPath (com.google.devtools.build.lib.vfs.SearchPath)1 TestResultData (com.google.devtools.build.lib.view.test.TestStatus.TestResultData)1 Builder (com.google.devtools.build.lib.view.test.TestStatus.TestResultData.Builder)1