Search in sources :

Example 71 with PathFragment

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);
    }
}
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 72 with PathFragment

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);
        }
    }
}
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 73 with PathFragment

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());
    }
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) FilesetActionContext(com.google.devtools.build.lib.rules.fileset.FilesetActionContext) File(java.io.File) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 74 with PathFragment

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);
        }
    }
}
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 75 with PathFragment

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()));
}
Also used : PathFragment(com.google.devtools.build.lib.vfs.PathFragment) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

PathFragment (com.google.devtools.build.lib.vfs.PathFragment)512 Test (org.junit.Test)208 Artifact (com.google.devtools.build.lib.actions.Artifact)184 Path (com.google.devtools.build.lib.vfs.Path)111 RootedPath (com.google.devtools.build.lib.vfs.RootedPath)65 SkyKey (com.google.devtools.build.skyframe.SkyKey)56 IOException (java.io.IOException)38 ArrayList (java.util.ArrayList)35 ImmutableList (com.google.common.collect.ImmutableList)32 Root (com.google.devtools.build.lib.actions.Root)32 HashMap (java.util.HashMap)27 Label (com.google.devtools.build.lib.cmdline.Label)26 LinkedHashMap (java.util.LinkedHashMap)26 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)23 ImmutableMap (com.google.common.collect.ImmutableMap)22 Map (java.util.Map)21 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)20 FilesetTraversalParams (com.google.devtools.build.lib.actions.FilesetTraversalParams)16 PackageIdentifier (com.google.devtools.build.lib.cmdline.PackageIdentifier)16 NestedSetBuilder (com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder)16