use of com.facebook.buck.rules.TargetNode 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.rules.TargetNode in project buck by facebook.
the class ProjectCommand method getIdeBasedOnPassedInTargetsAndProjectGraph.
private Ide getIdeBasedOnPassedInTargetsAndProjectGraph(BuckConfig buckConfig, ImmutableSet<BuildTarget> passedInTargetsSet, Optional<TargetGraph> projectGraph) {
if (ide != null) {
return ide;
}
Ide projectIde = getIdeFromBuckConfig(buckConfig).orElse(null);
if (projectIde == null && !passedInTargetsSet.isEmpty() && projectGraph.isPresent()) {
Ide guessedIde = null;
for (BuildTarget buildTarget : passedInTargetsSet) {
Optional<TargetNode<?, ?>> node = projectGraph.get().getOptional(buildTarget);
if (!node.isPresent()) {
throw new HumanReadableException("Project graph %s doesn't contain build target " + "%s", projectGraph.get(), buildTarget);
}
Description<?> description = node.get().getDescription();
boolean canGenerateXcodeProject = canGenerateImplicitWorkspaceForDescription(description);
canGenerateXcodeProject |= description instanceof XcodeWorkspaceConfigDescription;
if (guessedIde == null && canGenerateXcodeProject) {
guessedIde = Ide.XCODE;
} else if (guessedIde == Ide.XCODE && !canGenerateXcodeProject || guessedIde == Ide.INTELLIJ && canGenerateXcodeProject) {
throw new HumanReadableException("Passed targets (%s) contain both Xcode and Idea " + "projects.\nCan't choose Ide from this mixed set. " + "Please pass only Xcode targets or only Idea targets.", passedInTargetsSet);
} else {
guessedIde = Ide.INTELLIJ;
}
}
projectIde = guessedIde;
}
if (projectIde == null) {
throw new HumanReadableException("Please specify ide using --ide option or set ide in " + ".buckconfig");
}
return projectIde;
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class TargetsCommand method runWithExecutor.
private int runWithExecutor(CommandRunnerParams params, ListeningExecutorService executor) throws IOException, InterruptedException, BuildFileParseException, BuildTargetException, CycleException, VersionException {
Optional<ImmutableSet<Class<? extends Description<?>>>> descriptionClasses = getDescriptionClassFromParams(params);
if (!descriptionClasses.isPresent()) {
return 1;
}
if (isShowCellPath() || isShowOutput() || isShowFullOutput() || isShowRuleKey() || isShowTargetHash()) {
ImmutableMap<BuildTarget, ShowOptions> showRulesResult;
TargetGraphAndBuildTargets targetGraphAndBuildTargetsForShowRules = buildTargetGraphAndTargetsForShowRules(params, executor, descriptionClasses);
boolean useVersioning = isShowRuleKey() || isShowOutput() || isShowFullOutput() ? params.getBuckConfig().getBuildVersions() : params.getBuckConfig().getTargetsVersions();
targetGraphAndBuildTargetsForShowRules = useVersioning ? toVersionedTargetGraph(params, targetGraphAndBuildTargetsForShowRules) : targetGraphAndBuildTargetsForShowRules;
showRulesResult = computeShowRules(params, executor, TargetGraphAndTargetNodes.fromTargetGraphAndBuildTargets(targetGraphAndBuildTargetsForShowRules));
if (shouldUseJsonFormat()) {
Iterable<TargetNode<?, ?>> matchingNodes = targetGraphAndBuildTargetsForShowRules.getTargetGraph().getAll(targetGraphAndBuildTargetsForShowRules.getBuildTargets());
printJsonForTargets(params, executor, matchingNodes, showRulesResult, getOutputAttributes());
} else {
printShowRules(showRulesResult, params);
}
return 0;
}
return printResults(params, executor, getMatchingNodes(params, buildTargetGraphAndTargets(params, executor), descriptionClasses));
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class TargetsCommand method getMatchingNodes.
private SortedMap<String, TargetNode<?, ?>> getMatchingNodes(CommandRunnerParams params, TargetGraphAndBuildTargets targetGraphAndBuildTargets, Optional<ImmutableSet<Class<? extends Description<?>>>> descriptionClasses) throws IOException {
PathArguments.ReferencedFiles referencedFiles = getReferencedFiles(params.getCell().getFilesystem().getRootPath());
SortedMap<String, TargetNode<?, ?>> matchingNodes;
// If all of the referenced files are paths outside the project root, then print nothing.
if (!referencedFiles.absolutePathsOutsideProjectRootOrNonExistingPaths.isEmpty() && referencedFiles.relativePathsUnderProjectRoot.isEmpty()) {
matchingNodes = ImmutableSortedMap.of();
} else {
ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
ImmutableSet<BuildTarget> matchingBuildTargets = targetGraphAndBuildTargets.getBuildTargets();
matchingNodes = getMatchingNodes(targetGraphAndBuildTargets.getTargetGraph(), referencedFiles.relativePathsUnderProjectRoot.isEmpty() ? Optional.empty() : Optional.of(referencedFiles.relativePathsUnderProjectRoot), matchingBuildTargets.isEmpty() ? Optional.empty() : Optional.of(matchingBuildTargets), descriptionClasses.get().isEmpty() ? Optional.empty() : descriptionClasses, isDetectTestChanges(), parserConfig.getBuildFileName());
}
return matchingNodes;
}
use of com.facebook.buck.rules.TargetNode in project buck by facebook.
the class AppleDescriptions method createBuildRulesForSceneKitAssetsDependencies.
public static Optional<SceneKitAssets> createBuildRulesForSceneKitAssetsDependencies(TargetGraph targetGraph, BuildRuleParams params, AppleCxxPlatform appleCxxPlatform) {
TargetNode<?, ?> targetNode = targetGraph.get(params.getBuildTarget());
ImmutableSet<AppleWrapperResourceArg> sceneKitAssetsArgs = AppleBuildRules.collectTransitiveBuildRules(targetGraph, Optional.empty(), AppleBuildRules.SCENEKIT_ASSETS_DESCRIPTION_CLASSES, ImmutableList.of(targetNode));
BuildRuleParams sceneKitAssetsParams = params.withAppendedFlavor(SceneKitAssets.FLAVOR).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of()));
if (sceneKitAssetsArgs.isEmpty()) {
return Optional.empty();
} else {
return Optional.of(new SceneKitAssets(sceneKitAssetsParams, appleCxxPlatform, sceneKitAssetsArgs.stream().map(input -> new PathSourcePath(params.getProjectFilesystem(), input.path)).collect(MoreCollectors.toImmutableSet())));
}
}
Aggregations