use of com.facebook.buck.util.cache.NullFileHashCache in project buck by facebook.
the class DefaultRuleKeyFactoryTest method fieldsFromParentClassesShouldBeAddedAndFieldsRetainOverallAlphabeticalOrdering.
@Test
public void fieldsFromParentClassesShouldBeAddedAndFieldsRetainOverallAlphabeticalOrdering() {
BuildTarget topLevelTarget = BuildTargetFactory.newInstance("//cheese:peas");
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRule rule = new EmptyRule(topLevelTarget);
DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(0, new NullFileHashCache(), pathResolver, ruleFinder);
RuleKeyBuilder<RuleKeyResult<RuleKey>> builder = factory.newBuilderForTesting(rule);
builder.setReflectively("exoticCheese", "bavarian smoked");
builder.setReflectively("target", topLevelTarget);
RuleKey expected = builder.build().result;
class Parent extends EmptyRule {
@AddToRuleKey
private BuildTarget target;
public Parent(BuildTarget target) {
super(target);
this.target = target;
}
}
class Child extends Parent {
@AddToRuleKey
private String exoticCheese = "bavarian smoked";
public Child(BuildTarget target) {
super(target);
}
}
RuleKey seen = factory.build(new Child(topLevelTarget));
assertEquals(expected, seen);
}
use of com.facebook.buck.util.cache.NullFileHashCache in project buck by facebook.
the class DefaultRuleKeyFactoryTest method stringifiedRuleKeyAppendablesGetAddedToRuleKeyAsStrings.
@Test
public void stringifiedRuleKeyAppendablesGetAddedToRuleKeyAsStrings() {
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("field", "cheddar");
RuleKey expected = builder.build().result;
class AppendingField extends EmptyRule {
@AddToRuleKey(stringify = true)
private Appender field = new Appender();
public AppendingField(BuildTarget target) {
super(target);
}
}
RuleKey seen = factory.build(new AppendingField(target));
assertEquals(expected, seen);
}
use of com.facebook.buck.util.cache.NullFileHashCache in project buck by facebook.
the class DefaultRuleKeyFactoryTest method shouldNotAddUnannotatedFieldsToRuleKey.
@Test
public void shouldNotAddUnannotatedFieldsToRuleKey() {
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 expected = factory.build(rule);
class UndecoratedFields extends EmptyRule {
private String field = "cake-walk";
public UndecoratedFields(BuildTarget target) {
super(target);
}
}
RuleKey seen = factory.build(new UndecoratedFields(target));
assertEquals(expected, seen);
}
use of com.facebook.buck.util.cache.NullFileHashCache in project buck by facebook.
the class GenruleTest method thatChangingOutChangesRuleKey.
@Test
public void thatChangingOutChangesRuleKey() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, new NullFileHashCache(), pathResolver, ruleFinder);
// Get a rule key for two genrules using two different output names, but are otherwise the
// same.
RuleKey key1 = ruleKeyFactory.build(GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule1")).setOut("foo").build(resolver));
RuleKey key2 = ruleKeyFactory.build(GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:genrule2")).setOut("bar").build(resolver));
// Verify that just the difference in output name is enough to make the rule key different.
assertNotEquals(key1, key2);
}
use of com.facebook.buck.util.cache.NullFileHashCache in project buck by facebook.
the class RuleKeyTest method differentSeedsMakeDifferentKeys.
@Test
public void differentSeedsMakeDifferentKeys() {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
BuildTarget buildTarget = BuildTargetFactory.newInstance("//some:example");
BuildRule buildRule = new FakeBuildRule(buildTarget, resolver);
RuleKey empty1 = new DefaultRuleKeyFactory(0, new NullFileHashCache(), resolver, ruleFinder).build(buildRule);
RuleKey empty2 = new DefaultRuleKeyFactory(0, new NullFileHashCache(), resolver, ruleFinder).build(buildRule);
RuleKey empty3 = new DefaultRuleKeyFactory(1, new NullFileHashCache(), resolver, ruleFinder).build(buildRule);
assertThat(empty1, is(equalTo(empty2)));
assertThat(empty1, is(not(equalTo(empty3))));
}
Aggregations