use of com.facebook.buck.model.BuildFileTree in project buck by facebook.
the class BuckQueryEnvironment method getBuildFiles.
@Override
public ImmutableSet<QueryTarget> getBuildFiles(Set<QueryTarget> targets) throws QueryException {
final ProjectFilesystem cellFilesystem = rootCell.getFilesystem();
final Path rootPath = cellFilesystem.getRootPath();
Preconditions.checkState(rootPath.isAbsolute());
ImmutableSet.Builder<QueryTarget> builder = ImmutableSet.builder();
for (QueryTarget target : targets) {
Preconditions.checkState(target instanceof QueryBuildTarget);
BuildTarget buildTarget = ((QueryBuildTarget) target).getBuildTarget();
Cell cell = rootCell.getCell(buildTarget);
if (!buildFileTrees.containsKey(cell)) {
LOG.info("Creating a new filesystem-backed build file tree for %s", cell.getRoot());
buildFileTrees.put(cell, new FilesystemBackedBuildFileTree(cell.getFilesystem(), cell.getBuildFileName()));
}
BuildFileTree buildFileTree = Preconditions.checkNotNull(buildFileTrees.get(cell));
Optional<Path> path = buildFileTree.getBasePathOfAncestorTarget(buildTarget.getBasePath());
Preconditions.checkState(path.isPresent());
Path buildFilePath = MorePaths.relativize(rootPath, cell.getFilesystem().resolve(path.get()).resolve(cell.getBuildFileName()));
Preconditions.checkState(cellFilesystem.exists(buildFilePath));
builder.add(QueryFileTarget.of(buildFilePath));
}
return builder.build();
}
use of com.facebook.buck.model.BuildFileTree in project buck by facebook.
the class DaemonicParserState method invalidateBasedOn.
public void invalidateBasedOn(WatchEvent<?> event) {
if (!WatchEvents.isPathChangeEvent(event)) {
// Non-path change event, likely an overflow due to many change events: invalidate everything.
LOG.debug("Received non-path change event %s, assuming overflow and checking caches.", event);
if (invalidateAllCaches()) {
LOG.warn("Invalidated cache on watch event %s.", event);
cacheInvalidatedByWatchOverflowCounter.inc();
}
return;
}
filesChangedCounter.inc();
Path path = (Path) event.context();
try (AutoCloseableLock readLock = cellStateLock.readLock()) {
for (DaemonicCellState state : cellPathToDaemonicState.values()) {
try {
// rule key change. For parsing, these are the only events we need to care about.
if (isPathCreateOrDeleteEvent(event)) {
Cell cell = state.getCell();
BuildFileTree buildFiles = buildFileTrees.get(cell);
if (path.endsWith(cell.getBuildFileName())) {
LOG.debug("Build file %s changed, invalidating build file tree for cell %s", path, cell);
// If a build file has been added or removed, reconstruct the build file tree.
buildFileTrees.invalidate(cell);
}
// "containing" {@code path} unless its filename matches a temp file pattern.
if (!isTempFile(cell, path)) {
invalidateContainingBuildFile(cell, buildFiles, path);
} else {
LOG.debug("Not invalidating the owning build file of %s because it is a temporary file.", state.getCellRoot().resolve(path).toAbsolutePath().toString());
}
}
} catch (ExecutionException | UncheckedExecutionException e) {
try {
Throwables.throwIfInstanceOf(e, BuildFileParseException.class);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
} catch (BuildFileParseException bfpe) {
LOG.warn("Unable to parse already parsed build file.", bfpe);
}
}
}
}
invalidatePath(path);
}
use of com.facebook.buck.model.BuildFileTree in project buck by facebook.
the class BuckQueryEnvironment method getFileOwners.
@Override
public ImmutableSet<QueryTarget> getFileOwners(ImmutableList<String> files, ListeningExecutorService executor) throws InterruptedException, QueryException {
try {
BuildFileTree buildFileTree = Preconditions.checkNotNull(buildFileTrees.get(rootCell));
OwnersReport report = ownersReportBuilder.build(buildFileTree, executor, files);
return getTargetsFromTargetNodes(report.owners.keySet());
} catch (BuildFileParseException | IOException e) {
throw new QueryException(e, "Could not parse build targets.\n%s", e.getMessage());
}
}
use of com.facebook.buck.model.BuildFileTree in project buck by facebook.
the class TargetsCommand method getMatchingNodes.
/**
* @param graph Graph used to resolve dependencies between targets and find all build files.
* @param referencedFiles If present, the result will be limited to the nodes that transitively
* depend on at least one of those.
* @param matchingBuildTargets If present, the result will be limited to the specified targets.
* @param buildRuleTypes If present, the result will be limited to targets with the specified
* types.
* @param detectTestChanges If true, tests are considered to be dependencies of the targets they
* are testing.
* @return A map of target names to target nodes.
*/
@VisibleForTesting
ImmutableSortedMap<String, TargetNode<?, ?>> getMatchingNodes(TargetGraph graph, Optional<ImmutableSet<Path>> referencedFiles, final Optional<ImmutableSet<BuildTarget>> matchingBuildTargets, final Optional<ImmutableSet<Class<? extends Description<?>>>> descriptionClasses, boolean detectTestChanges, String buildFileName) {
ImmutableSet<TargetNode<?, ?>> directOwners;
if (referencedFiles.isPresent()) {
BuildFileTree buildFileTree = new InMemoryBuildFileTree(graph.getNodes().stream().map(TargetNode::getBuildTarget).collect(MoreCollectors.toImmutableSet()));
directOwners = FluentIterable.from(graph.getNodes()).filter(new DirectOwnerPredicate(buildFileTree, referencedFiles.get(), buildFileName)).toSet();
} else {
directOwners = graph.getNodes();
}
Iterable<TargetNode<?, ?>> selectedReferrers = FluentIterable.from(getDependentNodes(graph, directOwners, detectTestChanges)).filter(targetNode -> {
if (matchingBuildTargets.isPresent() && !matchingBuildTargets.get().contains(targetNode.getBuildTarget())) {
return false;
}
if (descriptionClasses.isPresent() && !descriptionClasses.get().contains(targetNode.getDescription().getClass())) {
return false;
}
return true;
});
ImmutableSortedMap.Builder<String, TargetNode<?, ?>> matchingNodesBuilder = ImmutableSortedMap.naturalOrder();
for (TargetNode<?, ?> targetNode : selectedReferrers) {
matchingNodesBuilder.put(targetNode.getBuildTarget().getFullyQualifiedName(), targetNode);
}
return matchingNodesBuilder.build();
}
Aggregations