use of com.facebook.buck.rules.RuleKeyObjectSink in project buck by facebook.
the class DefaultRuleKeyFactoryTest method annotatedAppendableBuildRulesIncludeTheirRuleKey.
@Test
public void annotatedAppendableBuildRulesIncludeTheirRuleKey() {
BuildTarget target = BuildTargetFactory.newInstance("//cheese:peas");
BuildTarget depTarget = BuildTargetFactory.newInstance("//cheese:more-peas");
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRule rule = new EmptyRule(target);
FileHashCache fileHashCache = new NullFileHashCache();
DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder);
class AppendableRule extends EmptyRule {
public AppendableRule(BuildTarget target) {
super(target);
}
@Override
public void appendToRuleKey(RuleKeyObjectSink sink) {
sink.setReflectively("cheese", "brie");
}
}
AppendableRule appendableRule = new AppendableRule(depTarget);
RuleKey appendableSubKey = new UncachedRuleKeyBuilder(ruleFinder, pathResolver, fileHashCache, factory).setReflectively("cheese", "brie").build();
RuleKey ruleSubKey = factory.build(appendableRule);
RuleKeyBuilder<RuleKeyResult<RuleKey>> builder = factory.newBuilderForTesting(rule);
try (RuleKeyScopedHasher.Scope keyScope = builder.getScopedHasher().keyScope("field")) {
try (RuleKeyScopedHasher.Scope appendableScope = builder.getScopedHasher().wrapperScope(RuleKeyHasher.Wrapper.BUILD_RULE)) {
builder.getScopedHasher().getHasher().putRuleKey(ruleSubKey);
}
}
RuleKey expected = builder.build().result;
class RuleContainingAppendableRule extends EmptyRule {
@AddToRuleKey
private final AppendableRule field;
public RuleContainingAppendableRule(BuildTarget target, AppendableRule appendableRule) {
super(target);
this.field = appendableRule;
}
}
RuleKey seen = factory.build(new RuleContainingAppendableRule(target, appendableRule));
assertEquals(expected, seen);
}
use of com.facebook.buck.rules.RuleKeyObjectSink in project buck by facebook.
the class LuaBinaryDescription method getInPlaceBinary.
private Tool getInPlaceBinary(BuildRuleParams params, BuildRuleResolver resolver, SourcePathRuleFinder ruleFinder, CxxPlatform cxxPlatform, final SourcePath starter, final LuaPackageComponents components) {
final List<SourcePath> extraInputs = new ArrayList<>();
final SymlinkTree modulesLinkTree = resolver.addToIndex(createSymlinkTree(getModulesSymlinkTreeTarget(params.getBuildTarget()), params.getProjectFilesystem(), resolver, ruleFinder, getModulesSymlinkTreeRoot(params.getBuildTarget(), params.getProjectFilesystem()), components.getModules()));
final List<SymlinkTree> pythonModulesLinktree = new ArrayList<>();
if (!components.getPythonModules().isEmpty()) {
// Add in any missing init modules into the python components.
SourcePath emptyInit = PythonBinaryDescription.createEmptyInitModule(params, resolver);
extraInputs.add(emptyInit);
ImmutableMap<String, SourcePath> pythonModules = MoreMaps.transformKeys(PythonBinaryDescription.addMissingInitModules(MoreMaps.transformKeys(components.getPythonModules(), MorePaths.toPathFn(params.getProjectFilesystem().getRootPath().getFileSystem())), emptyInit), Object::toString);
final SymlinkTree symlinkTree = resolver.addToIndex(createSymlinkTree(getPythonModulesSymlinkTreeTarget(params.getBuildTarget()), params.getProjectFilesystem(), resolver, ruleFinder, getPythonModulesSymlinkTreeRoot(params.getBuildTarget(), params.getProjectFilesystem()), pythonModules));
pythonModulesLinktree.add(symlinkTree);
}
final List<SymlinkTree> nativeLibsLinktree = new ArrayList<>();
if (!components.getNativeLibraries().isEmpty()) {
SymlinkTree symlinkTree = resolver.addToIndex(createSymlinkTree(getNativeLibsSymlinkTreeTarget(params.getBuildTarget()), params.getProjectFilesystem(), resolver, ruleFinder, getNativeLibsSymlinkTreeRoot(params.getBuildTarget(), params.getProjectFilesystem()), addVersionLessLibraries(cxxPlatform, components.getNativeLibraries())));
nativeLibsLinktree.add(symlinkTree);
}
return new Tool() {
@Override
public ImmutableCollection<BuildRule> getDeps(SourcePathRuleFinder ruleFinder) {
return ImmutableSortedSet.<BuildRule>naturalOrder().addAll(ruleFinder.filterBuildRuleInputs(starter)).addAll(components.getDeps(ruleFinder)).add(modulesLinkTree).addAll(nativeLibsLinktree).addAll(pythonModulesLinktree).addAll(ruleFinder.filterBuildRuleInputs(extraInputs)).build();
}
@Override
public ImmutableCollection<SourcePath> getInputs() {
return ImmutableSortedSet.<SourcePath>naturalOrder().add(starter).addAll(components.getInputs()).addAll(extraInputs).build();
}
@Override
public ImmutableList<String> getCommandPrefix(SourcePathResolver resolver) {
return ImmutableList.of(resolver.getAbsolutePath(starter).toString());
}
@Override
public ImmutableMap<String, String> getEnvironment(SourcePathResolver resolver) {
return ImmutableMap.of();
}
@Override
public void appendToRuleKey(RuleKeyObjectSink sink) {
sink.setReflectively("starter", starter).setReflectively("components", components);
}
};
}
Aggregations