use of com.facebook.buck.query.QueryTarget in project buck by facebook.
the class TargetPatternEvaluator method resolveFilePattern.
ImmutableSet<QueryTarget> resolveFilePattern(String pattern) throws IOException {
ImmutableSet<Path> filePaths = PathArguments.getCanonicalFilesUnderProjectRoot(projectRoot, ImmutableList.of(pattern)).relativePathsUnderProjectRoot;
ImmutableSet.Builder<QueryTarget> builder = ImmutableSortedSet.naturalOrder();
for (Path filePath : filePaths) {
builder.add(QueryFileTarget.of(filePath));
}
return builder.build();
}
use of com.facebook.buck.query.QueryTarget in project buck by facebook.
the class QueryMacroExpander method extractTargets.
private Stream<BuildTarget> extractTargets(BuildTarget target, CellPathResolver cellNames, Optional<BuildRuleResolver> resolver, T input) {
String queryExpression = CharMatcher.anyOf("\"'").trimFrom(input.getQuery().getQuery());
final GraphEnhancementQueryEnvironment env = new GraphEnhancementQueryEnvironment(resolver, targetGraph, cellNames, BuildTargetPatternParser.forBaseName(target.getBaseName()), ImmutableSet.of());
try {
QueryExpression parsedExp = QueryExpression.parse(queryExpression, env);
HashSet<String> targetLiterals = new HashSet<>();
parsedExp.collectTargetPatterns(targetLiterals);
return targetLiterals.stream().flatMap(pattern -> {
try {
return env.getTargetsMatchingPattern(pattern, executorService).stream();
} catch (Exception e) {
throw new HumanReadableException(e, "Error parsing target expression %s for target %s", pattern, target);
}
}).map(queryTarget -> {
Preconditions.checkState(queryTarget instanceof QueryBuildTarget);
return ((QueryBuildTarget) queryTarget).getBuildTarget();
});
} catch (QueryException e) {
throw new HumanReadableException("Error executing query in macro for target %s", target, e);
}
}
use of com.facebook.buck.query.QueryTarget in project buck by facebook.
the class QueryMacroExpander method resolveQuery.
Stream<QueryTarget> resolveQuery(BuildTarget target, CellPathResolver cellNames, final BuildRuleResolver resolver, String queryExpression) throws MacroException {
GraphEnhancementQueryEnvironment env = new GraphEnhancementQueryEnvironment(Optional.of(resolver), targetGraph, cellNames, BuildTargetPatternParser.forBaseName(target.getBaseName()), ImmutableSet.of());
try {
QueryExpression parsedExp = QueryExpression.parse(queryExpression, env);
Set<QueryTarget> queryTargets = parsedExp.eval(env, executorService);
return queryTargets.stream();
} catch (QueryException e) {
throw new MacroException("Error parsing/executing query from macro", e);
} catch (InterruptedException e) {
throw new MacroException("Error executing query", e);
}
}
use of com.facebook.buck.query.QueryTarget in project buck by facebook.
the class BuckQueryEnvironment method getReverseDeps.
@Override
public Set<QueryTarget> getReverseDeps(Iterable<QueryTarget> targets) throws QueryException, InterruptedException {
Set<QueryTarget> result = new LinkedHashSet<>();
for (QueryTarget target : targets) {
TargetNode<?, ?> node = getNode(target);
result.addAll(getTargetsFromTargetNodes(graph.getIncomingNodesFor(node)));
}
return result;
}
use of com.facebook.buck.query.QueryTarget 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();
}
Aggregations