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;
}
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));
}
}
}
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;
}
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);
}
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);
}
Aggregations