Search in sources :

Example 1 with NullFileHashCache

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);
}
Also used : RuleKey(com.facebook.buck.rules.RuleKey) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 2 with NullFileHashCache

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);
}
Also used : RuleKey(com.facebook.buck.rules.RuleKey) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 3 with NullFileHashCache

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);
}
Also used : RuleKey(com.facebook.buck.rules.RuleKey) AddToRuleKey(com.facebook.buck.rules.AddToRuleKey) BuildTarget(com.facebook.buck.model.BuildTarget) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 4 with NullFileHashCache

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);
}
Also used : DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 5 with NullFileHashCache

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))));
}
Also used : DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) BuildTarget(com.facebook.buck.model.BuildTarget) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) Test(org.junit.Test)

Aggregations

NullFileHashCache (com.facebook.buck.util.cache.NullFileHashCache)14 BuildTarget (com.facebook.buck.model.BuildTarget)12 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)12 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)12 RuleKey (com.facebook.buck.rules.RuleKey)12 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)12 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)12 Test (org.junit.Test)12 AddToRuleKey (com.facebook.buck.rules.AddToRuleKey)11 BuildRule (com.facebook.buck.rules.BuildRule)11 NoopBuildRule (com.facebook.buck.rules.NoopBuildRule)11 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)2 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)2 FileHashCache (com.facebook.buck.util.cache.FileHashCache)2 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)2 BuckEventBus (com.facebook.buck.event.BuckEventBus)1 BuildId (com.facebook.buck.model.BuildId)1 RuleKeyObjectSink (com.facebook.buck.rules.RuleKeyObjectSink)1 IncrementingFakeClock (com.facebook.buck.timing.IncrementingFakeClock)1