Search in sources :

Example 6 with BuildTargetException

use of com.facebook.buck.model.BuildTargetException in project buck by facebook.

the class TargetNodeParsePipeline method computeNode.

@Override
protected TargetNode<?, ?> computeNode(final Cell cell, final BuildTarget buildTarget, final Map<String, Object> rawNode) throws BuildTargetException {
    try (final SimplePerfEvent.Scope scope = SimplePerfEvent.scopeIgnoringShortEvents(eventBus, PerfEventId.of("GetTargetNode"), "target", buildTarget, targetNodePipelineLifetimeEventScope, getMinimumPerfEventTimeMs(), TimeUnit.MILLISECONDS)) {
        Function<PerfEventId, SimplePerfEvent.Scope> perfEventScopeFunction = perfEventId -> SimplePerfEvent.scopeIgnoringShortEvents(eventBus, perfEventId, scope, getMinimumPerfEventTimeMs(), TimeUnit.MILLISECONDS);
        final TargetNode<?, ?> targetNode = delegate.createTargetNode(cell, cell.getAbsolutePathToBuildFile(buildTarget), buildTarget, rawNode, perfEventScopeFunction);
        if (speculativeDepsTraversal) {
            executorService.submit(() -> {
                for (BuildTarget depTarget : targetNode.getDeps()) {
                    Path depCellPath = depTarget.getCellPath();
                    // non-threadsafe way making it inconvenient to access from the pipeline.
                    if (depCellPath.equals(cell.getRoot())) {
                        try {
                            if (depTarget.isFlavored()) {
                                getNodeJob(cell, BuildTarget.of(depTarget.getUnflavoredBuildTarget()));
                            }
                            getNodeJob(cell, depTarget);
                        } catch (BuildTargetException e) {
                            // No biggie, we'll hit the error again in the non-speculative path.
                            LOG.info(e, "Could not schedule speculative parsing for %s", depTarget);
                        }
                    }
                }
            });
        }
        return targetNode;
    }
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) Logger(com.facebook.buck.log.Logger) PerfEventId(com.facebook.buck.event.PerfEventId) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TargetNode(com.facebook.buck.rules.TargetNode) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent) BuildTargetException(com.facebook.buck.model.BuildTargetException) ThreadSafe(javax.annotation.concurrent.ThreadSafe) BuildTarget(com.facebook.buck.model.BuildTarget) TimeUnit(java.util.concurrent.TimeUnit) Map(java.util.Map) Cache(com.facebook.buck.parser.PipelineNodeCache.Cache) Cell(com.facebook.buck.rules.Cell) Path(java.nio.file.Path) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Path(java.nio.file.Path) BuildTargetException(com.facebook.buck.model.BuildTargetException) PerfEventId(com.facebook.buck.event.PerfEventId) BuildTarget(com.facebook.buck.model.BuildTarget) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent)

Example 7 with BuildTargetException

use of com.facebook.buck.model.BuildTargetException in project buck by facebook.

the class InstallCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    int exitCode = checkArguments(params);
    if (exitCode != 0) {
        return exitCode;
    }
    try (CommandThreadManager pool = new CommandThreadManager("Install", getConcurrencyLimit(params.getBuckConfig()))) {
        // Get the helper targets if present
        ImmutableSet<String> installHelperTargets;
        try {
            installHelperTargets = getInstallHelperTargets(params, pool.getExecutor());
        } catch (BuildTargetException | BuildFileParseException e) {
            params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
            return 1;
        }
        // Build the targets
        exitCode = super.run(params, pool.getExecutor(), installHelperTargets);
        if (exitCode != 0) {
            return exitCode;
        }
    }
    // Install the targets
    try {
        exitCode = install(params);
    } catch (NoSuchBuildTargetException e) {
        throw new HumanReadableException(e.getHumanReadableErrorMessage());
    }
    if (exitCode != 0) {
        return exitCode;
    }
    return exitCode;
}
Also used : BuildTargetException(com.facebook.buck.model.BuildTargetException) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) HumanReadableException(com.facebook.buck.util.HumanReadableException) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildFileParseException(com.facebook.buck.json.BuildFileParseException)

Example 8 with BuildTargetException

use of com.facebook.buck.model.BuildTargetException 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 9 with BuildTargetException

use of com.facebook.buck.model.BuildTargetException in project buck by facebook.

the class ProjectCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    int rc = runPreprocessScriptIfNeeded(params);
    if (rc != 0) {
        return rc;
    }
    Ide projectIde = getIdeFromBuckConfig(params.getBuckConfig()).orElse(null);
    boolean needsFullRecursiveParse = deprecatedIntelliJProjectGenerationEnabled && projectIde != Ide.XCODE;
    try (CommandThreadManager pool = new CommandThreadManager("Project", getConcurrencyLimit(params.getBuckConfig()))) {
        ImmutableSet<BuildTarget> passedInTargetsSet;
        TargetGraph projectGraph;
        List<String> targets = getArguments();
        if (projectIde != Ide.XCODE && !deprecatedIntelliJProjectGenerationEnabled && targets.isEmpty()) {
            targets = ImmutableList.of("//...");
        }
        try {
            ParserConfig parserConfig = params.getBuckConfig().getView(ParserConfig.class);
            passedInTargetsSet = ImmutableSet.copyOf(Iterables.concat(params.getParser().resolveTargetSpecs(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), parseArgumentsAsTargetNodeSpecs(params.getBuckConfig(), targets), SpeculativeParsing.of(true), parserConfig.getDefaultFlavorsMode())));
            needsFullRecursiveParse = needsFullRecursiveParse || passedInTargetsSet.isEmpty();
            projectGraph = getProjectGraphForIde(params, pool.getExecutor(), passedInTargetsSet, needsFullRecursiveParse);
        } catch (BuildTargetException | BuildFileParseException | HumanReadableException e) {
            params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
            return 1;
        }
        projectIde = getIdeBasedOnPassedInTargetsAndProjectGraph(params.getBuckConfig(), passedInTargetsSet, Optional.of(projectGraph));
        if (projectIde == ProjectCommand.Ide.XCODE) {
            checkForAndKillXcodeIfRunning(params, getIdePrompt(params.getBuckConfig()));
        }
        ProjectPredicates projectPredicates = ProjectPredicates.forIde(projectIde);
        ImmutableSet<BuildTarget> graphRoots;
        if (passedInTargetsSet.isEmpty()) {
            graphRoots = getRootsFromPredicate(projectGraph, projectPredicates.getProjectRootsPredicate());
        } else if (projectIde == Ide.INTELLIJ && needsFullRecursiveParse) {
            ImmutableSet<BuildTarget> supplementalGraphRoots = getRootBuildTargetsForIntelliJ(Ide.INTELLIJ, projectGraph, projectPredicates);
            graphRoots = Sets.union(passedInTargetsSet, supplementalGraphRoots).immutableCopy();
        } else {
            graphRoots = passedInTargetsSet;
        }
        TargetGraphAndTargets targetGraphAndTargets;
        try {
            targetGraphAndTargets = createTargetGraph(params, projectGraph, graphRoots, projectPredicates.getAssociatedProjectPredicate(), isWithTests(params.getBuckConfig()), isWithDependenciesTests(params.getBuckConfig()), needsFullRecursiveParse, pool.getExecutor());
        } catch (BuildFileParseException | TargetGraph.NoSuchNodeException | BuildTargetException | HumanReadableException e) {
            params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
            return 1;
        }
        if (getDryRun()) {
            for (TargetNode<?, ?> targetNode : targetGraphAndTargets.getTargetGraph().getNodes()) {
                params.getConsole().getStdOut().println(targetNode.toString());
            }
            return 0;
        }
        params.getBuckEventBus().post(ProjectGenerationEvent.started());
        int result;
        try {
            switch(projectIde) {
                case INTELLIJ:
                    result = runIntellijProjectGenerator(params, projectGraph, targetGraphAndTargets, passedInTargetsSet);
                    break;
                case XCODE:
                    result = runXcodeProjectGenerator(params, pool.getExecutor(), targetGraphAndTargets, passedInTargetsSet);
                    break;
                default:
                    // unreachable
                    throw new IllegalStateException("'ide' should always be of type 'INTELLIJ' or 'XCODE'");
            }
        } finally {
            params.getBuckEventBus().post(ProjectGenerationEvent.finished());
        }
        return result;
    }
}
Also used : BuildTargetException(com.facebook.buck.model.BuildTargetException) TargetGraphAndTargets(com.facebook.buck.rules.TargetGraphAndTargets) TargetGraph(com.facebook.buck.rules.TargetGraph) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) ImmutableSet(com.google.common.collect.ImmutableSet) BuildTarget(com.facebook.buck.model.BuildTarget) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) ParserConfig(com.facebook.buck.parser.ParserConfig)

Example 10 with BuildTargetException

use of com.facebook.buck.model.BuildTargetException in project buck by facebook.

the class AuditClasspathCommand method runWithoutHelp.

@Override
public int runWithoutHelp(final CommandRunnerParams params) throws IOException, InterruptedException {
    // Create a TargetGraph that is composed of the transitive closure of all of the dependent
    // BuildRules for the specified BuildTargets.
    final ImmutableSet<BuildTarget> targets = getArgumentsFormattedAsBuildTargets(params.getBuckConfig()).stream().map(input -> BuildTargetParser.INSTANCE.parse(input, BuildTargetPatternParser.fullyQualified(), params.getCell().getCellPathResolver())).collect(MoreCollectors.toImmutableSet());
    if (targets.isEmpty()) {
        params.getBuckEventBus().post(ConsoleEvent.severe("Please specify at least one build target."));
        return 1;
    }
    TargetGraph targetGraph;
    try (CommandThreadManager pool = new CommandThreadManager("Audit", getConcurrencyLimit(params.getBuckConfig()))) {
        targetGraph = params.getParser().buildTargetGraph(params.getBuckEventBus(), params.getCell(), getEnableParserProfiling(), pool.getExecutor(), targets);
    } catch (BuildFileParseException | BuildTargetException e) {
        params.getBuckEventBus().post(ConsoleEvent.severe(MoreExceptions.getHumanReadableOrLocalizedMessage(e)));
        return 1;
    }
    try {
        if (shouldGenerateDotOutput()) {
            return printDotOutput(params, targetGraph);
        } else if (shouldGenerateJsonOutput()) {
            return printJsonClasspath(params, targetGraph, targets);
        } else {
            return printClasspath(params, targetGraph, targets);
        }
    } catch (NoSuchBuildTargetException | VersionException e) {
        throw new HumanReadableException(e, MoreExceptions.getHumanReadableOrLocalizedMessage(e));
    }
}
Also used : TargetGraphAndBuildTargets(com.facebook.buck.rules.TargetGraphAndBuildTargets) SortedSet(java.util.SortedSet) VersionException(com.facebook.buck.versions.VersionException) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) MoreExceptions(com.facebook.buck.util.MoreExceptions) Multimap(com.google.common.collect.Multimap) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) BuildRule(com.facebook.buck.rules.BuildRule) Lists(com.google.common.collect.Lists) Argument(org.kohsuke.args4j.Argument) ImmutableList(com.google.common.collect.ImmutableList) BuildTargetPatternParser(com.facebook.buck.parser.BuildTargetPatternParser) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildTargetParser(com.facebook.buck.parser.BuildTargetParser) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) Path(java.nio.file.Path) LinkedHashMultimap(com.google.common.collect.LinkedHashMultimap) Nullable(javax.annotation.Nullable) ActionGraphCache(com.facebook.buck.rules.ActionGraphCache) MoreCollectors(com.facebook.buck.util.MoreCollectors) ImmutableSet(com.google.common.collect.ImmutableSet) TargetGraph(com.facebook.buck.rules.TargetGraph) TargetNode(com.facebook.buck.rules.TargetNode) BuildTargetException(com.facebook.buck.model.BuildTargetException) IOException(java.io.IOException) Option(org.kohsuke.args4j.Option) HumanReadableException(com.facebook.buck.util.HumanReadableException) BuildTarget(com.facebook.buck.model.BuildTarget) HasClasspathEntries(com.facebook.buck.jvm.java.HasClasspathEntries) Sets(com.google.common.collect.Sets) Dot(com.facebook.buck.graph.Dot) List(java.util.List) Preconditions(com.google.common.base.Preconditions) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Description(com.facebook.buck.rules.Description) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildTargetException(com.facebook.buck.model.BuildTargetException) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) TargetGraph(com.facebook.buck.rules.TargetGraph) BuildFileParseException(com.facebook.buck.json.BuildFileParseException) VersionException(com.facebook.buck.versions.VersionException)

Aggregations

BuildTargetException (com.facebook.buck.model.BuildTargetException)14 BuildFileParseException (com.facebook.buck.json.BuildFileParseException)13 BuildTarget (com.facebook.buck.model.BuildTarget)12 ImmutableSet (com.google.common.collect.ImmutableSet)10 TargetNode (com.facebook.buck.rules.TargetNode)8 HumanReadableException (com.facebook.buck.util.HumanReadableException)8 ImmutableList (com.google.common.collect.ImmutableList)8 IOException (java.io.IOException)8 Path (java.nio.file.Path)8 ConsoleEvent (com.facebook.buck.event.ConsoleEvent)6 TargetGraph (com.facebook.buck.rules.TargetGraph)6 MoreExceptions (com.facebook.buck.util.MoreExceptions)6 Logger (com.facebook.buck.log.Logger)5 ParserConfig (com.facebook.buck.parser.ParserConfig)5 Cell (com.facebook.buck.rules.Cell)5 MoreCollectors (com.facebook.buck.util.MoreCollectors)5 Lists (com.google.common.collect.Lists)5 List (java.util.List)5 Optional (java.util.Optional)5 Option (org.kohsuke.args4j.Option)5