use of com.facebook.buck.util.cache.NullFileHashCache in project buck by facebook.
the class DefaultRuleKeyFactoryTest method fieldsFromParentClassesAreAlsoAdded.
@Test
public void fieldsFromParentClassesAreAlsoAdded() {
BuildTarget target = BuildTargetFactory.newInstance("//cheese:peas");
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRule rule = new EmptyRule(target);
DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(0, new NullFileHashCache(), pathResolver, ruleFinder);
RuleKeyBuilder<RuleKeyResult<RuleKey>> builder = factory.newBuilderForTesting(rule);
builder.setReflectively("key", "child");
builder.setReflectively("key", "parent");
RuleKey expected = builder.build().result;
class Parent extends EmptyRule {
@AddToRuleKey
private String key = "parent";
public Parent(BuildTarget target) {
super(target);
}
}
class Child extends Parent {
@AddToRuleKey
private String key = "child";
public Child(BuildTarget target) {
super(target);
}
}
RuleKey seen = factory.build(new Child(target));
assertEquals(expected, seen);
}
use of com.facebook.buck.util.cache.NullFileHashCache in project buck by facebook.
the class DefaultRuleKeyFactoryTest method assertValuesGetHashed.
private void assertValuesGetHashed(@Nullable Object val1, @Nullable Object val2) {
Preconditions.checkArgument(!Objects.equal(val1, val2), "Values should be different!");
BuildTarget target = BuildTargetFactory.newInstance("//cheese:peas");
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRule rule = new EmptyRule(target);
DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(0, new NullFileHashCache(), pathResolver, ruleFinder);
RuleKey key1 = factory.newBuilderForTesting(rule).setReflectively("key", val1).build().result;
RuleKey key1again = factory.newBuilderForTesting(rule).setReflectively("key", val1).build().result;
RuleKey key2 = factory.newBuilderForTesting(rule).setReflectively("key", val2).build().result;
assertEquals("Rule keys should be same! " + val1, key1, key1again);
assertNotEquals("Rule keys should be different! " + val1 + " != " + val2, key1, key2);
}
use of com.facebook.buck.util.cache.NullFileHashCache 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.util.cache.NullFileHashCache in project buck by facebook.
the class DefaultRuleKeyFactoryTest method fieldsAreAddedInAlphabeticalOrder.
@Test
public void fieldsAreAddedInAlphabeticalOrder() {
BuildTarget target = BuildTargetFactory.newInstance("//cheese:peas");
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRule rule = new EmptyRule(target);
DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(0, new NullFileHashCache(), pathResolver, ruleFinder);
RuleKeyBuilder<RuleKeyResult<RuleKey>> builder = factory.newBuilderForTesting(rule);
builder.setReflectively("alpha", "stilton");
builder.setReflectively("beta", 1);
builder.setReflectively("gamma", "stinking bishop");
RuleKey expected = builder.build().result;
class UnsortedFields extends EmptyRule {
@AddToRuleKey
private String gamma = "stinking bishop";
@AddToRuleKey
private int beta = 1;
@AddToRuleKey
private String alpha = "stilton";
public UnsortedFields(BuildTarget target) {
super(target);
}
}
RuleKey seen = factory.build(new UnsortedFields(target));
assertEquals(expected, seen);
}
Aggregations