use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class ActionCacheChecker method getCachedInputs.
@Nullable
public Iterable<Artifact> getCachedInputs(Action action, PackageRootResolver resolver) throws PackageRootResolutionException, InterruptedException {
ActionCache.Entry entry = getCacheEntry(action);
if (entry == null || entry.isCorrupted()) {
return ImmutableList.of();
}
List<PathFragment> outputs = new ArrayList<>();
for (Artifact output : action.getOutputs()) {
outputs.add(output.getExecPath());
}
List<PathFragment> inputExecPaths = new ArrayList<>();
for (String path : entry.getPaths()) {
PathFragment execPath = new PathFragment(path);
// most efficient.
if (!outputs.contains(execPath)) {
inputExecPaths.add(execPath);
}
}
// Note that this method may trigger a violation of the desirable invariant that getInputs()
// is a superset of getMandatoryInputs(). See bug about an "action not in canonical form"
// error message and the integration test test_crosstool_change_and_failure().
Map<PathFragment, Artifact> allowedDerivedInputsMap = new HashMap<>();
for (Artifact derivedInput : action.getAllowedDerivedInputs()) {
if (!derivedInput.isSourceArtifact()) {
allowedDerivedInputsMap.put(derivedInput.getExecPath(), derivedInput);
}
}
List<Artifact> inputArtifacts = new ArrayList<>();
List<PathFragment> unresolvedPaths = new ArrayList<>();
for (PathFragment execPath : inputExecPaths) {
Artifact artifact = allowedDerivedInputsMap.get(execPath);
if (artifact != null) {
inputArtifacts.add(artifact);
} else {
// Remember this execPath, we will try to resolve it as a source artifact.
unresolvedPaths.add(execPath);
}
}
Map<PathFragment, Artifact> resolvedArtifacts = artifactResolver.resolveSourceArtifacts(unresolvedPaths, resolver);
if (resolvedArtifacts == null) {
// We are missing some dependencies. We need to rerun this update later.
return null;
}
for (PathFragment execPath : unresolvedPaths) {
Artifact artifact = resolvedArtifacts.get(execPath);
// was used before) and will force action execution.
if (artifact != null) {
inputArtifacts.add(artifact);
}
}
return inputArtifacts;
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class ActionInputHelper method asTreeFileArtifacts.
/** Returns a Set of TreeFileArtifacts with the given parent and parent-relative paths. */
public static Set<TreeFileArtifact> asTreeFileArtifacts(final Artifact parent, Set<? extends PathFragment> parentRelativePaths) {
Preconditions.checkState(parent.isTreeArtifact(), "Given parent %s must be a TreeArtifact", parent);
ImmutableSet.Builder<TreeFileArtifact> builder = ImmutableSet.builder();
for (PathFragment path : parentRelativePaths) {
builder.add(treeFileArtifact(parent, path));
}
return builder.build();
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class Artifact method asRootPrefixedExecPath.
@VisibleForTesting
static String asRootPrefixedExecPath(Artifact artifact) {
PathFragment execPath = artifact.getExecPath();
PathFragment rootRel = artifact.getRootRelativePath();
if (execPath.equals(rootRel)) {
return ":" + rootRel.getPathString();
} else {
//if (execPath.endsWith(rootRel)) {
PathFragment rootPrefix = trimTail(execPath, rootRel);
return rootPrefix.getPathString() + ":" + rootRel.getPathString();
}
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class ArtifactFactory method resolveSourceArtifactWithAncestor.
/**
* Returns an {@link Artifact} with exec path formed by composing {@code baseExecPath} and
* {@code relativePath} (via {@code baseExecPath.getRelative(relativePath)} if baseExecPath is
* not null). That Artifact will have root determined by the package roots of this factory if it
* lives in a subpackage distinct from that of baseExecPath, and {@code baseRoot} otherwise.
*/
public synchronized Artifact resolveSourceArtifactWithAncestor(PathFragment relativePath, PathFragment baseExecPath, Root baseRoot, RepositoryName repositoryName) {
Preconditions.checkState((baseExecPath == null) == (baseRoot == null), "%s %s %s", relativePath, baseExecPath, baseRoot);
Preconditions.checkState(relativePath.segmentCount() > 0, "%s %s %s", relativePath, baseExecPath, baseRoot);
PathFragment execPath = baseExecPath == null ? relativePath : baseExecPath.getRelative(relativePath);
execPath = execPath.normalize();
if (execPath.containsUplevelReferences()) {
// Source exec paths cannot escape the source root.
return null;
}
// Don't create an artifact if it's derived.
if (isDerivedArtifact(execPath)) {
return null;
}
Root sourceRoot = findSourceRoot(execPath, baseExecPath, baseRoot, repositoryName);
Artifact artifact = sourceArtifactCache.getArtifactIfValid(execPath);
if (artifact != null) {
Preconditions.checkState(sourceRoot == null || sourceRoot.equals(artifact.getRoot()));
return artifact;
}
return createArtifactIfNotValid(sourceRoot, execPath);
}
use of com.google.devtools.build.lib.vfs.PathFragment in project bazel by bazelbuild.
the class ArtifactFactory method findSourceRoot.
/**
* Probe the known packages to find the longest package prefix up until the base, or until the
* root directory if our execPath doesn't start with baseExecPath due to uplevel references.
*/
@Nullable
private Root findSourceRoot(PathFragment execPath, @Nullable PathFragment baseExecPath, @Nullable Root baseRoot, RepositoryName repositoryName) {
PathFragment dir = execPath.getParentDirectory();
if (dir == null) {
return null;
}
Pair<RepositoryName, PathFragment> repo = RepositoryName.fromPathFragment(dir);
if (repo != null) {
repositoryName = repo.getFirst();
dir = repo.getSecond();
}
while (dir != null && !dir.equals(baseExecPath)) {
Root sourceRoot = packageRoots.get(PackageIdentifier.create(repositoryName, dir));
if (sourceRoot != null) {
return sourceRoot;
}
dir = dir.getParentDirectory();
}
return dir != null && dir.equals(baseExecPath) ? baseRoot : null;
}
Aggregations