use of com.google.devtools.build.lib.vfs.PathFragment 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.PathFragment 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.PathFragment in project bazel by bazelbuild.
the class SpawnHelpers method mountFilesFromFilesetManifests.
/** Mount all files that the spawn needs as specified in its fileset manifests. */
void mountFilesFromFilesetManifests(Map<PathFragment, Path> mounts, Spawn spawn, ActionExecutionContext executionContext) throws IOException {
final FilesetActionContext filesetContext = executionContext.getExecutor().getContext(FilesetActionContext.class);
for (Artifact fileset : spawn.getFilesetManifests()) {
File manifestFile = new File(execRoot.getPathString(), AnalysisUtils.getManifestPathFromFilesetPath(fileset.getExecPath()).getPathString());
PathFragment targetDirectory = fileset.getExecPath();
parseManifestFile(execRoot.getFileSystem(), mounts, targetDirectory, manifestFile, true, filesetContext.getWorkspaceName());
}
}
use of com.google.devtools.build.lib.vfs.PathFragment 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.PathFragment in project bazel by bazelbuild.
the class J2ObjcAspect method javaJ2ObjcSource.
private static J2ObjcSource javaJ2ObjcSource(RuleContext ruleContext, Iterable<Artifact> javaInputSourceFiles, Iterable<Artifact> javaSourceJarFiles) {
PathFragment objcFileRootRelativePath = ruleContext.getUniqueDirectory("_j2objc");
PathFragment objcFileRootExecPath = ruleContext.getConfiguration().getBinFragment().getRelative(objcFileRootRelativePath);
Iterable<Artifact> objcSrcs = getOutputObjcFiles(ruleContext, javaInputSourceFiles, objcFileRootRelativePath, ".m");
Iterable<Artifact> objcHdrs = getOutputObjcFiles(ruleContext, javaInputSourceFiles, objcFileRootRelativePath, ".h");
Iterable<PathFragment> headerSearchPaths = J2ObjcLibrary.j2objcSourceHeaderSearchPaths(ruleContext, objcFileRootExecPath, javaInputSourceFiles);
Optional<Artifact> sourceJarTranslatedSrcs = Optional.absent();
Optional<Artifact> sourceJarTranslatedHdrs = Optional.absent();
Optional<PathFragment> sourceJarFileHeaderSearchPaths = Optional.absent();
if (!Iterables.isEmpty(javaSourceJarFiles)) {
sourceJarTranslatedSrcs = Optional.of(j2ObjcSourceJarTranslatedSourceFiles(ruleContext));
sourceJarTranslatedHdrs = Optional.of(j2objcSourceJarTranslatedHeaderFiles(ruleContext));
sourceJarFileHeaderSearchPaths = Optional.of(sourceJarTranslatedHdrs.get().getExecPath());
}
return new J2ObjcSource(ruleContext.getRule().getLabel(), Iterables.concat(objcSrcs, sourceJarTranslatedSrcs.asSet()), Iterables.concat(objcHdrs, sourceJarTranslatedHdrs.asSet()), objcFileRootExecPath, SourceType.JAVA, Iterables.concat(headerSearchPaths, sourceJarFileHeaderSearchPaths.asSet()));
}
Aggregations