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;
}
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);
}
}
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);
}
}
}
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);
}
}
}
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);
}
Aggregations