Search in sources :

Example 6 with NullFileHashCache

use of com.facebook.buck.util.cache.NullFileHashCache in project buck by facebook.

the class TargetGraphHashingTest method emptyTargetGraphHasEmptyHashes.

@Test
public void emptyTargetGraphHasEmptyHashes() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
    BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
    TargetGraph targetGraph = TargetGraphFactory.newInstance();
    assertThat(new TargetGraphHashing(eventBus, targetGraph, new NullFileHashCache(), ImmutableList.of()).hashTargetGraph().entrySet(), empty());
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) BuildId(com.facebook.buck.model.BuildId) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Test(org.junit.Test)

Example 7 with NullFileHashCache

use of com.facebook.buck.util.cache.NullFileHashCache in project buck by facebook.

the class DefaultRuleKeyFactoryTest method shouldAddASingleAnnotatedFieldToRuleKey.

@Test
public void shouldAddASingleAnnotatedFieldToRuleKey() {
    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", "cake-walk");
    RuleKey expected = builder.build().result;
    class DecoratedFields extends EmptyRule {

        @AddToRuleKey
        private String field = "cake-walk";

        public DecoratedFields(BuildTarget target) {
            super(target);
        }
    }
    RuleKey seen = factory.build(new DecoratedFields(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 8 with NullFileHashCache

use of com.facebook.buck.util.cache.NullFileHashCache in project buck by facebook.

the class DefaultRuleKeyFactoryTest method shouldAllowRuleKeyAppendablesToAppendToRuleKey.

@Test
public void shouldAllowRuleKeyAppendablesToAppendToRuleKey() {
    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);
    FileHashCache fileHashCache = new NullFileHashCache();
    DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder);
    RuleKey subKey = new UncachedRuleKeyBuilder(ruleFinder, pathResolver, fileHashCache, factory).setReflectively("cheese", "brie").build();
    RuleKeyBuilder<RuleKeyResult<RuleKey>> builder = factory.newBuilderForTesting(rule);
    try (RuleKeyScopedHasher.Scope keyScope = builder.getScopedHasher().keyScope("field")) {
        try (RuleKeyScopedHasher.Scope appendableScope = builder.getScopedHasher().wrapperScope(RuleKeyHasher.Wrapper.APPENDABLE)) {
            builder.getScopedHasher().getHasher().putRuleKey(subKey);
        }
    }
    RuleKey expected = builder.build().result;
    class AppendingField extends EmptyRule {

        @AddToRuleKey
        private Appender field = new Appender();

        public AppendingField(BuildTarget target) {
            super(target);
        }
    }
    RuleKey seen = factory.build(new AppendingField(target));
    assertEquals(expected, seen);
}
Also used : DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) 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 9 with NullFileHashCache

use of com.facebook.buck.util.cache.NullFileHashCache in project buck by facebook.

the class DefaultRuleKeyFactoryTest method shouldAllowAFieldToBeStringified.

@Test
public void shouldAllowAFieldToBeStringified() {
    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", "sausages");
    RuleKey expected = builder.build().result;
    class Stringifiable {

        @Override
        public String toString() {
            return "sausages";
        }
    }
    class StringifiedField extends EmptyRule {

        @AddToRuleKey(stringify = true)
        private Stringifiable field = new Stringifiable();

        public StringifiedField(BuildTarget target) {
            super(target);
        }
    }
    RuleKey seen = factory.build(new StringifiedField(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 10 with NullFileHashCache

use of com.facebook.buck.util.cache.NullFileHashCache in project buck by facebook.

the class DefaultRuleKeyFactoryTest method assertKeysGetHashed.

private void assertKeysGetHashed(@Nullable Object val) {
    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("key1", val).build().result;
    RuleKey key1again = factory.newBuilderForTesting(rule).setReflectively("key1", val).build().result;
    RuleKey key2 = factory.newBuilderForTesting(rule).setReflectively("key2", val).build().result;
    assertEquals("Rule keys should be same! " + val, key1, key1again);
    assertNotEquals("Rule keys should be different! " + val, key1, key2);
}
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)

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