Search in sources :

Example 51 with Path

use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.

the class LinuxSandboxedStrategy method getReadOnlyBindMounts.

private SortedMap<Path, Path> getReadOnlyBindMounts(BlazeDirectories blazeDirs, Path sandboxExecRoot) throws UserExecException {
    Path tmpPath = blazeDirs.getFileSystem().getPath("/tmp");
    final SortedMap<Path, Path> bindMounts = Maps.newTreeMap();
    if (blazeDirs.getWorkspace().startsWith(tmpPath)) {
        bindMounts.put(blazeDirs.getWorkspace(), blazeDirs.getWorkspace());
    }
    if (blazeDirs.getOutputBase().startsWith(tmpPath)) {
        bindMounts.put(blazeDirs.getOutputBase(), blazeDirs.getOutputBase());
    }
    for (ImmutableMap.Entry<String, String> additionalMountPath : sandboxOptions.sandboxAdditionalMounts) {
        try {
            final Path mountTarget = blazeDirs.getFileSystem().getPath(additionalMountPath.getValue());
            // If source path is relative, treat it as a relative path inside the execution root
            final Path mountSource = sandboxExecRoot.getRelative(additionalMountPath.getKey());
            // If a target has more than one source path, the latter one will take effect.
            bindMounts.put(mountTarget, mountSource);
        } catch (IllegalArgumentException e) {
            throw new UserExecException(String.format("Error occurred when analyzing bind mount pairs. %s", e.getMessage()));
        }
    }
    validateBindMounts(bindMounts);
    return bindMounts;
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) UserExecException(com.google.devtools.build.lib.actions.UserExecException) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 52 with Path

use of com.google.devtools.build.lib.vfs.Path 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 53 with Path

use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.

the class SpawnHelpers method mountRunfilesFromSuppliers.

/** Mount all runfiles that the spawn needs as specified via its runfiles suppliers. */
void mountRunfilesFromSuppliers(Map<PathFragment, Path> mounts, Spawn spawn) throws IOException {
    Map<PathFragment, Map<PathFragment, Artifact>> rootsAndMappings = spawn.getRunfilesSupplier().getMappings();
    for (Map.Entry<PathFragment, Map<PathFragment, Artifact>> rootAndMappings : rootsAndMappings.entrySet()) {
        PathFragment root = rootAndMappings.getKey();
        if (root.isAbsolute()) {
            root = root.relativeTo(execRoot.asFragment());
        }
        for (Map.Entry<PathFragment, Artifact> mapping : rootAndMappings.getValue().entrySet()) {
            Artifact sourceArtifact = mapping.getValue();
            Path source = (sourceArtifact != null) ? execRoot.getRelative(sourceArtifact.getExecPath()) : null;
            Preconditions.checkArgument(!mapping.getKey().isAbsolute());
            PathFragment target = root.getRelative(mapping.getKey());
            mounts.put(target, source);
        }
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) HashMap(java.util.HashMap) Map(java.util.Map) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 54 with Path

use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.

the class SymlinkedExecRoot method createInputs.

private void createInputs(Map<PathFragment, Path> inputs) throws IOException {
    // All input files are relative to the execroot.
    for (Entry<PathFragment, Path> entry : inputs.entrySet()) {
        Path key = sandboxExecRoot.getRelative(entry.getKey());
        FileStatus keyStat = key.statNullable(Symlinks.NOFOLLOW);
        if (keyStat != null) {
            if (keyStat.isSymbolicLink() && entry.getValue() != null && key.readSymbolicLink().equals(entry.getValue().asFragment())) {
                continue;
            }
            key.delete();
        }
        // A null value means that we're supposed to create an empty file as the input.
        if (entry.getValue() != null) {
            key.createSymbolicLink(entry.getValue());
        } else {
            FileSystemUtils.createEmptyFile(key);
        }
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) FileStatus(com.google.devtools.build.lib.vfs.FileStatus) PathFragment(com.google.devtools.build.lib.vfs.PathFragment)

Example 55 with Path

use of com.google.devtools.build.lib.vfs.Path in project bazel by bazelbuild.

the class GrpcServerImpl method writeServerFile.

private void writeServerFile(String name, String contents) throws IOException {
    Path file = serverDirectory.getChild(name);
    FileSystemUtils.writeContentAsLatin1(file, contents);
    deleteAtExit(file, false);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path)

Aggregations

Path (com.google.devtools.build.lib.vfs.Path)492 Test (org.junit.Test)250 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)111 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)105 IOException (java.io.IOException)102 Artifact (com.google.devtools.build.lib.actions.Artifact)37 SkyKey (com.google.devtools.build.skyframe.SkyKey)37 ArrayList (java.util.ArrayList)29 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)17 FileSystem (com.google.devtools.build.lib.vfs.FileSystem)17 InMemoryFileSystem (com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem)17 HashMap (java.util.HashMap)17 WindowsPath (com.google.devtools.build.lib.windows.WindowsFileSystem.WindowsPath)16 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)14 Before (org.junit.Before)14 Package (com.google.devtools.build.lib.packages.Package)13 FileStatus (com.google.devtools.build.lib.vfs.FileStatus)13 Map (java.util.Map)12 Nullable (javax.annotation.Nullable)12 Executor (com.google.devtools.build.lib.actions.Executor)10