Search in sources :

Example 36 with TargetNode

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();
}
Also used : AppleConfig(com.facebook.buck.apple.AppleConfig) AppleSimulatorDiscovery(com.facebook.buck.apple.simulator.AppleSimulatorDiscovery) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) AdbOptions(com.facebook.buck.step.AdbOptions) AdbHelper(com.facebook.buck.android.AdbHelper) InstallEvent(com.facebook.buck.event.InstallEvent) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AppleConfig(com.facebook.buck.apple.AppleConfig) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) FluentIterable(com.google.common.collect.FluentIterable) ApplePlatform(com.facebook.buck.apple.ApplePlatform) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Locale(java.util.Locale) AppleCoreSimulatorServiceController(com.facebook.buck.apple.simulator.AppleCoreSimulatorServiceController) Path(java.nio.file.Path) Optionals(com.facebook.buck.util.Optionals) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) AppleSimulator(com.facebook.buck.apple.simulator.AppleSimulator) BuildTargetException(com.facebook.buck.model.BuildTargetException) Option(org.kohsuke.args4j.Option) AppleInfoPlistParsing(com.facebook.buck.apple.AppleInfoPlistParsing) BuildTarget(com.facebook.buck.model.BuildTarget) SuppressFieldNotInitialized(com.facebook.infer.annotation.SuppressFieldNotInitialized) List(java.util.List) AppleBundleDescription(com.facebook.buck.apple.AppleBundleDescription) AppleSimulatorController(com.facebook.buck.apple.simulator.AppleSimulatorController) UninstallOptions(com.facebook.buck.cli.UninstallCommand.UninstallOptions) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Description(com.facebook.buck.rules.Description) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Assertions(com.facebook.infer.annotation.Assertions) Build(com.facebook.buck.command.Build) MoreExceptions(com.facebook.buck.util.MoreExceptions) SourcePath(com.facebook.buck.rules.SourcePath) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) BuildRule(com.facebook.buck.rules.BuildRule) ExecutionContext(com.facebook.buck.step.ExecutionContext) Lists(com.google.common.collect.Lists) AppleDeviceHelper(com.facebook.buck.apple.device.AppleDeviceHelper) ParserConfig(com.facebook.buck.parser.ParserConfig) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) Nullable(javax.annotation.Nullable) Logger(com.facebook.buck.log.Logger) Functions(com.google.common.base.Functions) UnixUserIdFetcher(com.facebook.buck.util.UnixUserIdFetcher) TargetNode(com.facebook.buck.rules.TargetNode) TargetDeviceOptions(com.facebook.buck.step.TargetDeviceOptions) IOException(java.io.IOException) HumanReadableException(com.facebook.buck.util.HumanReadableException) AppleBundle(com.facebook.buck.apple.AppleBundle) HasInstallableApk(com.facebook.buck.android.HasInstallableApk) SpeculativeParsing(com.facebook.buck.parser.SpeculativeParsing) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) VisibleForTesting(com.google.common.annotations.VisibleForTesting) InputStream(java.io.InputStream) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) Flavor(com.facebook.buck.model.Flavor) ParserConfig(com.facebook.buck.parser.ParserConfig) TargetNodeSpec(com.facebook.buck.parser.TargetNodeSpec)

Example 37 with TargetNode

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;
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) XcodeWorkspaceConfigDescription(com.facebook.buck.apple.XcodeWorkspaceConfigDescription) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException)

Example 38 with TargetNode

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));
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets)

Example 39 with TargetNode

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;
}
Also used : TargetNode(com.facebook.buck.rules.TargetNode) BuildTarget(com.facebook.buck.model.BuildTarget) ParserConfig(com.facebook.buck.parser.ParserConfig)

Example 40 with TargetNode

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())));
    }
}
Also used : OptionalCompat(com.facebook.buck.util.OptionalCompat) ProvidesLinkedBinaryDeps(com.facebook.buck.cxx.ProvidesLinkedBinaryDeps) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) AbstractGenruleDescription(com.facebook.buck.shell.AbstractGenruleDescription) RichStream(com.facebook.buck.util.RichStream) InternalFlavor(com.facebook.buck.model.InternalFlavor) FlavorDomain(com.facebook.buck.model.FlavorDomain) CxxCompilationDatabase(com.facebook.buck.cxx.CxxCompilationDatabase) FluentIterable(com.google.common.collect.FluentIterable) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourceList(com.facebook.buck.rules.coercer.SourceList) StripStyle(com.facebook.buck.cxx.StripStyle) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) Path(java.nio.file.Path) CxxDescriptionEnhancer(com.facebook.buck.cxx.CxxDescriptionEnhancer) BuildRules(com.facebook.buck.rules.BuildRules) FrameworkDependencies(com.facebook.buck.cxx.FrameworkDependencies) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) TargetGraph(com.facebook.buck.rules.TargetGraph) Set(java.util.Set) BuildTarget(com.facebook.buck.model.BuildTarget) Sets(com.google.common.collect.Sets) LinkerMapMode(com.facebook.buck.cxx.LinkerMapMode) SourceWithFlags(com.facebook.buck.rules.SourceWithFlags) Predicate(com.google.common.base.Predicate) PathSourcePath(com.facebook.buck.rules.PathSourcePath) Optional(java.util.Optional) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) CxxBinaryDescription(com.facebook.buck.cxx.CxxBinaryDescription) Joiner(com.google.common.base.Joiner) CxxStrip(com.facebook.buck.cxx.CxxStrip) CxxLibraryDescription(com.facebook.buck.cxx.CxxLibraryDescription) SourcePath(com.facebook.buck.rules.SourcePath) Either(com.facebook.buck.model.Either) BuildRule(com.facebook.buck.rules.BuildRule) HashSet(java.util.HashSet) Tool(com.facebook.buck.rules.Tool) ImmutableList(com.google.common.collect.ImmutableList) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) Predicates(com.google.common.base.Predicates) Suppliers(com.google.common.base.Suppliers) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSortedSet(com.google.common.collect.ImmutableSortedSet) CxxConstructorArg(com.facebook.buck.cxx.CxxConstructorArg) TargetNode(com.facebook.buck.rules.TargetNode) CxxPlatform(com.facebook.buck.cxx.CxxPlatform) HumanReadableException(com.facebook.buck.util.HumanReadableException) MorePaths(com.facebook.buck.io.MorePaths) Ordering(com.google.common.collect.Ordering) BuildRuleWithBinary(com.facebook.buck.cxx.BuildRuleWithBinary) Paths(java.nio.file.Paths) SWIFT_EXTENSION(com.facebook.buck.swift.SwiftDescriptions.SWIFT_EXTENSION) Preconditions(com.google.common.base.Preconditions) Flavor(com.facebook.buck.model.Flavor) VisibleForTesting(com.google.common.annotations.VisibleForTesting) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) PathSourcePath(com.facebook.buck.rules.PathSourcePath)

Aggregations

TargetNode (com.facebook.buck.rules.TargetNode)88 BuildTarget (com.facebook.buck.model.BuildTarget)73 TargetGraph (com.facebook.buck.rules.TargetGraph)43 Test (org.junit.Test)40 Path (java.nio.file.Path)36 ImmutableSet (com.google.common.collect.ImmutableSet)33 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)23 PathSourcePath (com.facebook.buck.rules.PathSourcePath)22 SourcePath (com.facebook.buck.rules.SourcePath)22 ImmutableMap (com.google.common.collect.ImmutableMap)22 Optional (java.util.Optional)20 Map (java.util.Map)18 HumanReadableException (com.facebook.buck.util.HumanReadableException)17 ImmutableList (com.google.common.collect.ImmutableList)17 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)13 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)13 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)13 Cell (com.facebook.buck.rules.Cell)13 IOException (java.io.IOException)13 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)12