Search in sources :

Example 36 with DefaultRuleKeyFactory

use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory 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)

Example 37 with DefaultRuleKeyFactory

use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.

the class RuleKeyTest method changingRuleKeyFieldChangesKeyWhenClassImplementsAppendToRuleKey.

@Test
public void changingRuleKeyFieldChangesKeyWhenClassImplementsAppendToRuleKey() {
    BuildTarget target = BuildTargetFactory.newInstance("//cheese:peas");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(new FakeProjectFilesystem())));
    BuildRule buildRule1 = new TestRuleKeyAppendableBuildRule(params, "foo", "bar");
    BuildRule buildRule2 = new TestRuleKeyAppendableBuildRule(params, "foo", "xyzzy");
    RuleKey ruleKey1 = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(buildRule1);
    RuleKey ruleKey2 = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(buildRule2);
    assertNotEquals(ruleKey1, ruleKey2);
}
Also used : NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) Test(org.junit.Test)

Example 38 with DefaultRuleKeyFactory

use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.

the class RuleKeyTest method createEmptyRuleKey.

private RuleKeyBuilder<RuleKeyResult<RuleKey>> createEmptyRuleKey(SourcePathResolver resolver, SourcePathRuleFinder ruleFinder) {
    FileHashCache fileHashCache = new FileHashCache() {

        @Override
        public void invalidate(Path path) {
        }

        @Override
        public void invalidateAll() {
        }

        @Override
        public HashCode get(Path path) {
            return HashCode.fromString("deadbeef");
        }

        @Override
        public HashCode get(ArchiveMemberPath archiveMemberPath) {
            return HashCode.fromString("deadbeef");
        }

        @Override
        public long getSize(Path path) {
            return 0;
        }

        @Override
        public void set(Path path, HashCode hashCode) {
        }
    };
    BuildTarget buildTarget = BuildTargetFactory.newInstance("//some:example");
    BuildRule buildRule = new FakeBuildRule(buildTarget, resolver);
    return new DefaultRuleKeyFactory(0, fileHashCache, resolver, ruleFinder).newBuilderForTesting(buildRule);
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) HashCode(com.google.common.hash.HashCode) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) BuildTarget(com.facebook.buck.model.BuildTarget)

Example 39 with DefaultRuleKeyFactory

use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.

the class RuleKeyTest method subclassWithNoopSetter.

@Test
public void subclassWithNoopSetter() {
    class NoopSetterRuleKeyBuilder extends UncachedRuleKeyBuilder {

        public NoopSetterRuleKeyBuilder(SourcePathRuleFinder ruleFinder, SourcePathResolver pathResolver, FileHashCache hashCache, RuleKeyFactory<RuleKey> defaultRuleKeyFactory) {
            super(ruleFinder, pathResolver, hashCache, defaultRuleKeyFactory);
        }

        @Override
        protected NoopSetterRuleKeyBuilder setSourcePath(SourcePath sourcePath) {
            return this;
        }
    }
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    FileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of());
    RuleKeyFactory<RuleKey> ruleKeyFactory = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder);
    RuleKey nullRuleKey = new NoopSetterRuleKeyBuilder(ruleFinder, pathResolver, hashCache, ruleKeyFactory).build();
    RuleKey noopRuleKey = new NoopSetterRuleKeyBuilder(ruleFinder, pathResolver, hashCache, ruleKeyFactory).setReflectively("key", new FakeSourcePath("value")).build();
    assertThat(noopRuleKey, is(equalTo(nullRuleKey)));
}
Also used : NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) UncachedRuleKeyBuilder(com.facebook.buck.rules.keys.UncachedRuleKeyBuilder) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKeyFactory(com.facebook.buck.rules.keys.RuleKeyFactory) Test(org.junit.Test)

Example 40 with DefaultRuleKeyFactory

use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.

the class AppleCxxPlatformsTest method constructLinkRuleKeys.

// Create and return some rule keys from a dummy source for the given platforms.
private ImmutableMap<Flavor, RuleKey> constructLinkRuleKeys(ImmutableMap<Flavor, AppleCxxPlatform> cxxPlatforms) throws NoSuchBuildTargetException {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put("input.o", Strings.repeat("a", 40)).build()), pathResolver, ruleFinder);
    BuildTarget target = BuildTargetFactory.newInstance("//:target");
    ImmutableMap.Builder<Flavor, RuleKey> ruleKeys = ImmutableMap.builder();
    for (Map.Entry<Flavor, AppleCxxPlatform> entry : cxxPlatforms.entrySet()) {
        BuildRule rule = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, entry.getValue().getCxxPlatform(), new FakeBuildRuleParamsBuilder(target).build(), resolver, pathResolver, ruleFinder, target, Linker.LinkType.EXECUTABLE, Optional.empty(), Paths.get("output"), Linker.LinkableDepType.SHARED, ImmutableList.of(), Optional.empty(), Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(SourcePathArg.from(new FakeSourcePath("input.o"))).build());
        ruleKeys.put(entry.getKey(), ruleKeyFactory.build(rule));
    }
    return ruleKeys.build();
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) Matchers.containsString(org.hamcrest.Matchers.containsString) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) InternalFlavor(com.facebook.buck.model.InternalFlavor) Flavor(com.facebook.buck.model.Flavor) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ImmutableMap(com.google.common.collect.ImmutableMap) BuildTarget(com.facebook.buck.model.BuildTarget) BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)58 Test (org.junit.Test)43 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)42 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)42 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)35 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)34 RuleKey (com.facebook.buck.rules.RuleKey)34 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)27 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)27 Path (java.nio.file.Path)26 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)24 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)23 BuildTarget (com.facebook.buck.model.BuildTarget)22 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)21 PathSourcePath (com.facebook.buck.rules.PathSourcePath)20 FileHashCache (com.facebook.buck.util.cache.FileHashCache)18 BuildRule (com.facebook.buck.rules.BuildRule)17 SourcePath (com.facebook.buck.rules.SourcePath)16 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)11 ImmutableMap (com.google.common.collect.ImmutableMap)10