Search in sources :

Example 1 with RuleKeyFieldLoader

use of com.facebook.buck.rules.keys.RuleKeyFieldLoader in project buck by facebook.

the class VerifyCachesCommand method verifyRuleKeyCache.

private boolean verifyRuleKeyCache(PrintStream stdOut, int ruleKeySeed, FileHashCache fileHashCache, RuleKeyCacheRecycler<RuleKey> recycler) {
    ImmutableList<Map.Entry<BuildRule, RuleKey>> contents = recycler.getCachedBuildRules();
    RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(ruleKeySeed);
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    contents.forEach(e -> resolver.addToIndex(e.getKey()));
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    DefaultRuleKeyFactory defaultRuleKeyFactory = new DefaultRuleKeyFactory(fieldLoader, fileHashCache, pathResolver, ruleFinder);
    stdOut.println(String.format("Examining %d build rule keys.", contents.size()));
    ImmutableList<BuildRule> mismatches = RichStream.from(contents).filter(entry -> !defaultRuleKeyFactory.build(entry.getKey()).equals(entry.getValue())).map(Map.Entry::getKey).toImmutableList();
    if (mismatches.isEmpty()) {
        stdOut.println("No rule key cache errors found.");
    } else {
        stdOut.println("Found rule key cache errors:");
        for (BuildRule rule : mismatches) {
            stdOut.println(String.format("  %s", rule));
        }
    }
    return true;
}
Also used : RuleKeyFieldLoader(com.facebook.buck.rules.keys.RuleKeyFieldLoader) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) Map(java.util.Map) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver)

Example 2 with RuleKeyFieldLoader

use of com.facebook.buck.rules.keys.RuleKeyFieldLoader in project buck by facebook.

the class BuildCommand method showOutputs.

private void showOutputs(CommandRunnerParams params, ActionGraphAndResolver actionGraphAndResolver) {
    Optional<DefaultRuleKeyFactory> ruleKeyFactory = Optional.empty();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(actionGraphAndResolver.getResolver());
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    if (showRuleKey) {
        RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(params.getBuckConfig().getKeySeed());
        ruleKeyFactory = Optional.of(new DefaultRuleKeyFactory(fieldLoader, params.getFileHashCache(), pathResolver, ruleFinder));
    }
    params.getConsole().getStdOut().println("The outputs are:");
    for (BuildTarget buildTarget : buildTargets) {
        try {
            BuildRule rule = actionGraphAndResolver.getResolver().requireRule(buildTarget);
            Optional<Path> outputPath = TargetsCommand.getUserFacingOutputPath(pathResolver, rule, showFullOutput, params.getBuckConfig().getBuckOutCompatLink());
            params.getConsole().getStdOut().printf("%s%s%s\n", rule.getFullyQualifiedName(), showRuleKey ? " " + ruleKeyFactory.get().build(rule).toString() : "", showOutput || showFullOutput ? " " + outputPath.map(Object::toString).orElse("") : "");
        } catch (NoSuchBuildTargetException e) {
            throw new HumanReadableException(MoreExceptions.getHumanReadableOrLocalizedMessage(e));
        }
    }
}
Also used : RuleKeyFieldLoader(com.facebook.buck.rules.keys.RuleKeyFieldLoader) Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) BuildTarget(com.facebook.buck.model.BuildTarget) HumanReadableException(com.facebook.buck.util.HumanReadableException) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) BuildRule(com.facebook.buck.rules.BuildRule) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 3 with RuleKeyFieldLoader

use of com.facebook.buck.rules.keys.RuleKeyFieldLoader in project buck by facebook.

the class ActionGraphCache method getActionGraph.

/**
   * It returns an {@link ActionGraphAndResolver}. If the {@code targetGraph} exists in the cache
   * it returns a cached version of the {@link ActionGraphAndResolver}, else returns a new one and
   * updates the cache.
   * @param eventBus the {@link BuckEventBus} to post the events of the processing.
   * @param skipActionGraphCache if true, do not invalidate the {@link ActionGraph} cached in
   *     memory. Instead, create a new {@link ActionGraph} for this request, which should be
   *     garbage-collected at the end of the request.
   * @param targetGraph the target graph that the action graph will be based on.
   * @return a {@link ActionGraphAndResolver}
   */
public ActionGraphAndResolver getActionGraph(final BuckEventBus eventBus, final boolean checkActionGraphs, final boolean skipActionGraphCache, final TargetGraph targetGraph, int keySeed) {
    ActionGraphEvent.Started started = ActionGraphEvent.started();
    eventBus.post(started);
    ActionGraphAndResolver out;
    try {
        RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(keySeed);
        if (lastActionGraph != null && lastActionGraph.getFirst().equals(targetGraph)) {
            eventBus.post(ActionGraphEvent.Cache.hit());
            LOG.info("ActionGraph cache hit.");
            if (checkActionGraphs) {
                compareActionGraphs(eventBus, lastActionGraph.getSecond(), targetGraph, fieldLoader);
            }
            out = lastActionGraph.getSecond();
        } else {
            eventBus.post(ActionGraphEvent.Cache.miss(lastActionGraph == null));
            LOG.debug("Computing TargetGraph HashCode...");
            HashCode targetGraphHash = getTargetGraphHash(targetGraph);
            if (lastActionGraph == null) {
                LOG.info("ActionGraph cache miss. Cache was empty.");
            } else if (Objects.equals(lastTargetGraphHash, targetGraphHash)) {
                LOG.info("ActionGraph cache miss. TargetGraphs mismatched but hashes are the same.");
                eventBus.post(ActionGraphEvent.Cache.missWithTargetGraphHashMatch());
            } else {
                LOG.info("ActionGraph cache miss. TargetGraphs mismatched.");
            }
            lastTargetGraphHash = targetGraphHash;
            Pair<TargetGraph, ActionGraphAndResolver> freshActionGraph = new Pair<TargetGraph, ActionGraphAndResolver>(targetGraph, createActionGraph(eventBus, new DefaultTargetNodeToBuildRuleTransformer(), targetGraph));
            out = freshActionGraph.getSecond();
            if (!skipActionGraphCache) {
                LOG.info("ActionGraph cache assignment. skipActionGraphCache? %s", skipActionGraphCache);
                lastActionGraph = freshActionGraph;
            }
        }
    } finally {
        eventBus.post(ActionGraphEvent.finished(started));
    }
    return out;
}
Also used : RuleKeyFieldLoader(com.facebook.buck.rules.keys.RuleKeyFieldLoader) HashCode(com.google.common.hash.HashCode) ActionGraphEvent(com.facebook.buck.event.ActionGraphEvent) Pair(com.facebook.buck.model.Pair)

Example 4 with RuleKeyFieldLoader

use of com.facebook.buck.rules.keys.RuleKeyFieldLoader in project buck by facebook.

the class PythonTestDescriptionTest method calculateRuleKey.

private RuleKey calculateRuleKey(BuildRuleResolver ruleResolver, BuildRule rule) {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(new RuleKeyFieldLoader(0), new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(rule.getProjectFilesystem()))), new SourcePathResolver(ruleFinder), ruleFinder);
    return ruleKeyFactory.build(rule);
}
Also used : RuleKeyFieldLoader(com.facebook.buck.rules.keys.RuleKeyFieldLoader) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Example 5 with RuleKeyFieldLoader

use of com.facebook.buck.rules.keys.RuleKeyFieldLoader in project buck by facebook.

the class PythonBinaryDescriptionTest method calculateRuleKey.

private RuleKey calculateRuleKey(BuildRuleResolver ruleResolver, BuildRule rule) {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(new RuleKeyFieldLoader(0), new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(rule.getProjectFilesystem()))), new SourcePathResolver(ruleFinder), ruleFinder);
    return ruleKeyFactory.build(rule);
}
Also used : RuleKeyFieldLoader(com.facebook.buck.rules.keys.RuleKeyFieldLoader) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver)

Aggregations

RuleKeyFieldLoader (com.facebook.buck.rules.keys.RuleKeyFieldLoader)7 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)5 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)5 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)5 BuildRule (com.facebook.buck.rules.BuildRule)3 BuildTarget (com.facebook.buck.model.BuildTarget)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)2 Path (java.nio.file.Path)2 HashMap (java.util.HashMap)2 ActionGraphEvent (com.facebook.buck.event.ActionGraphEvent)1 Pair (com.facebook.buck.model.Pair)1 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)1 ActionGraph (com.facebook.buck.rules.ActionGraph)1 ActionGraphAndResolver (com.facebook.buck.rules.ActionGraphAndResolver)1 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)1 SourcePath (com.facebook.buck.rules.SourcePath)1 ContentAgnosticRuleKeyFactory (com.facebook.buck.rules.keys.ContentAgnosticRuleKeyFactory)1 HumanReadableException (com.facebook.buck.util.HumanReadableException)1 ImmutableMap (com.google.common.collect.ImmutableMap)1