use of com.facebook.buck.rules.keys.RuleKeyFieldLoader in project buck by facebook.
the class ActionGraphCacheTest method getRuleKeysFromBuildRules.
private Map<BuildRule, RuleKey> getRuleKeysFromBuildRules(Iterable<BuildRule> buildRules, BuildRuleResolver buildRuleResolver) {
RuleKeyFieldLoader ruleKeyFieldLoader = new RuleKeyFieldLoader(0);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(buildRuleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
ContentAgnosticRuleKeyFactory factory = new ContentAgnosticRuleKeyFactory(ruleKeyFieldLoader, pathResolver, ruleFinder);
HashMap<BuildRule, RuleKey> ruleKeysMap = new HashMap<>();
for (BuildRule rule : buildRules) {
ruleKeysMap.put(rule, factory.build(rule));
}
return ruleKeysMap;
}
use of com.facebook.buck.rules.keys.RuleKeyFieldLoader in project buck by facebook.
the class TargetsCommand method computeShowRules.
/**
* Assumes at least one target is specified. Computes each of the
* specified targets, followed by the rule key, output path, and/or
* target hash, depending on what flags are passed in.
* @return An immutable map consisting of result of show options
* for to each target rule
*/
private ImmutableMap<BuildTarget, ShowOptions> computeShowRules(CommandRunnerParams params, ListeningExecutorService executor, TargetGraphAndTargetNodes targetGraphAndTargetNodes) throws IOException, InterruptedException, BuildFileParseException, BuildTargetException, CycleException {
Map<BuildTarget, ShowOptions.Builder> showOptionBuilderMap = new HashMap<>();
if (isShowTargetHash()) {
computeShowTargetHash(params, executor, targetGraphAndTargetNodes, showOptionBuilderMap);
}
// We only need the action graph if we're showing the output or the keys, and the
// RuleKeyFactory if we're showing the keys.
Optional<ActionGraph> actionGraph = Optional.empty();
Optional<BuildRuleResolver> buildRuleResolver = Optional.empty();
Optional<DefaultRuleKeyFactory> ruleKeyFactory = Optional.empty();
if (isShowRuleKey() || isShowOutput() || isShowFullOutput()) {
ActionGraphAndResolver result = Preconditions.checkNotNull(ActionGraphCache.getFreshActionGraph(params.getBuckEventBus(), targetGraphAndTargetNodes.getTargetGraph()));
actionGraph = Optional.of(result.getActionGraph());
buildRuleResolver = Optional.of(result.getResolver());
if (isShowRuleKey()) {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(result.getResolver());
ruleKeyFactory = Optional.of(new DefaultRuleKeyFactory(new RuleKeyFieldLoader(params.getBuckConfig().getKeySeed()), params.getFileHashCache(), new SourcePathResolver(ruleFinder), ruleFinder));
}
}
for (TargetNode<?, ?> targetNode : targetGraphAndTargetNodes.getTargetNodes()) {
ShowOptions.Builder showOptionsBuilder = getShowOptionBuilder(showOptionBuilderMap, targetNode.getBuildTarget());
Preconditions.checkNotNull(showOptionsBuilder);
if (actionGraph.isPresent()) {
BuildRule rule = buildRuleResolver.get().requireRule(targetNode.getBuildTarget());
if (isShowRuleKey()) {
showOptionsBuilder.setRuleKey(ruleKeyFactory.get().build(rule).toString());
}
if (isShowOutput() || isShowFullOutput()) {
Optional<Path> outputPath = getUserFacingOutputPath(new SourcePathResolver(new SourcePathRuleFinder(buildRuleResolver.get())), rule, isShowFullOutput(), params.getBuckConfig().getBuckOutCompatLink());
if (outputPath.isPresent()) {
showOptionsBuilder.setOutputPath(outputPath.get().toString());
}
}
}
}
ImmutableMap.Builder<BuildTarget, ShowOptions> builder = new ImmutableMap.Builder<>();
for (Entry<BuildTarget, ShowOptions.Builder> entry : showOptionBuilderMap.entrySet()) {
builder.put(entry.getKey(), entry.getValue().build());
}
return builder.build();
}
Aggregations