use of com.facebook.buck.parser.TargetNodeSpec in project buck by facebook.
the class ProjectCommand method getFocusModules.
private Optional<ImmutableSet<UnflavoredBuildTarget>> getFocusModules(CommandRunnerParams params, ListeningExecutorService executor) throws IOException, InterruptedException {
if (modulesToFocusOn == null) {
return Optional.empty();
}
Iterable<String> patterns = Splitter.onPattern("\\s+").split(modulesToFocusOn);
// Parse patterns with the following syntax:
// https://buckbuild.com/concept/build_target_pattern.html
ImmutableList<TargetNodeSpec> specs = parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), patterns);
// Resolve the list of targets matching the patterns.
ImmutableSet<BuildTarget> passedInTargetsSet;
ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
try {
passedInTargetsSet = params.getParser().resolveTargetSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, specs, SpeculativeParsing.of(false), parserConfig.getDefaultFlavorsMode()).stream().flatMap(Collection::stream).map(target -> target.withoutCell()).collect(MoreCollectors.toImmutableSet());
} catch (BuildTargetException | BuildFileParseException | HumanReadableException e) {
params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
return Optional.empty();
}
LOG.debug("Selected targets: %s", passedInTargetsSet.toString());
// Retrieve mapping: cell name -> path.
ImmutableMap<String, Path> cellPaths = params.getCell().getCellPathResolver().getCellPaths();
ImmutableMap<Path, String> cellNames = ImmutableBiMap.copyOf(cellPaths).inverse();
// Create a set of unflavored targets that have cell names.
ImmutableSet.Builder<UnflavoredBuildTarget> builder = ImmutableSet.builder();
for (BuildTarget target : passedInTargetsSet) {
String cell = cellNames.get(target.getCellPath());
if (cell == null) {
builder.add(target.getUnflavoredBuildTarget());
} else {
UnflavoredBuildTarget targetWithCell = UnflavoredBuildTarget.of(target.getCellPath(), Optional.of(cell), target.getBaseName(), target.getShortName());
builder.add(targetWithCell);
}
}
ImmutableSet<UnflavoredBuildTarget> passedInUnflavoredTargetsSet = builder.build();
LOG.debug("Selected unflavored targets: %s", passedInUnflavoredTargetsSet.toString());
return Optional.of(passedInUnflavoredTargetsSet);
}
use of com.facebook.buck.parser.TargetNodeSpec in project buck by facebook.
the class InstallCommand method getInstallHelperTargets.
private ImmutableSet<String> getInstallHelperTargets(CommandRunnerParams params, ListeningExecutorService executor) throws IOException, InterruptedException, BuildTargetException, BuildFileParseException {
ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
ImmutableSet.Builder<String> installHelperTargets = ImmutableSet.builder();
for (int index = 0; index < getArguments().size(); index++) {
// TODO(ryu2): Cache argument parsing
TargetNodeSpec spec = parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), getArguments()).get(index);
BuildTarget target = FluentIterable.from(params.getParser().resolveTargetSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, ImmutableList.of(spec), SpeculativeParsing.of(false), parserConfig.getDefaultFlavorsMode())).transformAndConcat(Functions.identity()).first().get();
TargetNode<?, ?> node = params.getParser().getTargetNode(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), executor, target);
if (node != null && Description.getBuildRuleType(node.getDescription()).equals(Description.getBuildRuleType(AppleBundleDescription.class))) {
for (Flavor flavor : node.getBuildTarget().getFlavors()) {
if (ApplePlatform.needsInstallHelper(flavor.getName())) {
AppleConfig appleConfig = new AppleConfig(params.getBuckConfig());
Optional<BuildTarget> deviceHelperTarget = appleConfig.getAppleDeviceHelperTarget();
Optionals.addIfPresent(Optionals.bind(deviceHelperTarget, input -> !input.toString().isEmpty() ? Optional.of(input.toString()) : Optional.empty()), installHelperTargets);
}
}
}
}
return installHelperTargets.build();
}
use of com.facebook.buck.parser.TargetNodeSpec in project buck by facebook.
the class PublishCommand method parseArgumentsAsTargetNodeSpecs.
@Override
public ImmutableList<TargetNodeSpec> parseArgumentsAsTargetNodeSpecs(BuckConfig config, Iterable<String> targetsAsArgs) {
ImmutableList<TargetNodeSpec> specs = super.parseArgumentsAsTargetNodeSpecs(config, targetsAsArgs);
if (includeSource) {
specs = ImmutableList.<TargetNodeSpec>builder().addAll(specs).addAll(specs.stream().filter(input -> {
if (!(input instanceof BuildTargetSpec)) {
throw new IllegalArgumentException("Targets must be explicitly defined when using " + INCLUDE_SOURCE_LONG_ARG);
}
return !((BuildTargetSpec) input).getBuildTarget().getFlavors().contains(JavaLibrary.SRC_JAR);
}).map(input -> BuildTargetSpec.of(((BuildTargetSpec) input).getBuildTarget().withFlavors(JavaLibrary.SRC_JAR), input.getBuildFileSpec())).iterator()).build();
}
// Append "maven" flavor
specs = specs.stream().map(input -> {
if (!(input instanceof BuildTargetSpec)) {
throw new IllegalArgumentException("Need to specify build targets explicitly when publishing. " + "Cannot modify " + input);
}
BuildTargetSpec buildTargetSpec = (BuildTargetSpec) input;
BuildTarget buildTarget = Preconditions.checkNotNull(buildTargetSpec.getBuildTarget());
return buildTargetSpec.withBuildTarget(BuildTarget.builder(buildTarget).addFlavors(JavaLibrary.MAVEN_JAR).build());
}).collect(MoreCollectors.toImmutableList());
return specs;
}
use of com.facebook.buck.parser.TargetNodeSpec in project buck by facebook.
the class TargetPatternEvaluator method resolveBuildTargetPatterns.
ImmutableMap<String, ImmutableSet<QueryTarget>> resolveBuildTargetPatterns(List<String> patterns, ListeningExecutorService executor) throws InterruptedException, BuildFileParseException, BuildTargetException, IOException {
// Build up an ordered list of patterns and pass them to the parse to get resolved in one go.
// The returned list of nodes maintains the spec list ordering.
List<TargetNodeSpec> specs = new ArrayList<>();
for (String pattern : patterns) {
specs.addAll(targetNodeSpecParser.parse(rootCell.getCellPathResolver(), pattern));
}
ImmutableList<ImmutableSet<BuildTarget>> buildTargets = parser.resolveTargetSpecs(eventBus, rootCell, enableProfiling, executor, specs, SpeculativeParsing.of(false), // because the query engine doesn't handle flavors very well.
ParserConfig.ApplyDefaultFlavorsMode.DISABLED);
LOG.verbose("Resolved target patterns %s -> targets %s", patterns, buildTargets);
// Convert the ordered result into a result map of pattern to set of resolved targets.
ImmutableMap.Builder<String, ImmutableSet<QueryTarget>> queryTargets = ImmutableMap.builder();
for (int index = 0; index < buildTargets.size(); index++) {
ImmutableSet<BuildTarget> targets = buildTargets.get(index);
// Sorting to have predictable results across different java libraries implementations.
ImmutableSet.Builder<QueryTarget> builder = ImmutableSortedSet.naturalOrder();
for (BuildTarget target : targets) {
builder.add(QueryBuildTarget.of(target));
}
queryTargets.put(patterns.get(index), builder.build());
}
return queryTargets.build();
}
use of com.facebook.buck.parser.TargetNodeSpec in project buck by facebook.
the class AbstractCommand method parseArgumentsAsTargetNodeSpecs.
public ImmutableList<TargetNodeSpec> parseArgumentsAsTargetNodeSpecs(BuckConfig config, Iterable<String> targetsAsArgs) {
ImmutableList.Builder<TargetNodeSpec> specs = ImmutableList.builder();
CommandLineTargetNodeSpecParser parser = new CommandLineTargetNodeSpecParser(config, new BuildTargetPatternTargetNodeParser());
for (String arg : targetsAsArgs) {
specs.addAll(parser.parse(config.getCellPathResolver(), arg));
}
return specs.build();
}
Aggregations