Search in sources :

Example 6 with FakeFileHashCache

use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.

the class RuleKeyTest method declaredDepsAndExtraDepsGenerateDifferentRuleKeys.

@Test
public void declaredDepsAndExtraDepsGenerateDifferentRuleKeys() {
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    FileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of());
    DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, hashCache, sourcePathResolver, ruleFinder);
    BuildTarget target = BuildTargetFactory.newInstance("//a:target");
    BuildTarget depTarget = BuildTargetFactory.newInstance("//some:dep");
    BuildRuleParams depParams = new FakeBuildRuleParamsBuilder(depTarget).build();
    NoopBuildRule dep = new NoopBuildRule(depParams);
    BuildRuleParams paramsWithDeclaredDep = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(dep)).build();
    NoopBuildRule ruleWithDeclaredDep = new NoopBuildRule(paramsWithDeclaredDep);
    BuildRuleParams paramsWithExtraDep = new FakeBuildRuleParamsBuilder(target).setExtraDeps(ImmutableSortedSet.of(dep)).build();
    NoopBuildRule ruleWithExtraDep = new NoopBuildRule(paramsWithExtraDep);
    BuildRuleParams paramsWithBothDeps = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(dep)).setExtraDeps(ImmutableSortedSet.of(dep)).build();
    NoopBuildRule ruleWithBothDeps = new NoopBuildRule(paramsWithBothDeps);
    assertNotEquals(ruleKeyFactory.build(ruleWithDeclaredDep), ruleKeyFactory.build(ruleWithExtraDep));
    assertNotEquals(ruleKeyFactory.build(ruleWithDeclaredDep), ruleKeyFactory.build(ruleWithBothDeps));
    assertNotEquals(ruleKeyFactory.build(ruleWithExtraDep), ruleKeyFactory.build(ruleWithBothDeps));
}
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) BuildTarget(com.facebook.buck.model.BuildTarget) Test(org.junit.Test)

Example 7 with FakeFileHashCache

use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.

the class ManifestTest method lookupMissingHeader.

@Test
public void lookupMissingHeader() throws IOException {
    RuleKey key = new RuleKey("aa");
    SourcePath input = new FakeSourcePath("input.h");
    Manifest manifest = Manifest.fromMap(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input).toString(), HashCode.fromInt(1))));
    FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of());
    assertThat(manifest.lookup(fileHashCache, RESOLVER, ImmutableSet.of(input)), Matchers.equalTo(Optional.empty()));
}
Also used : FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) Test(org.junit.Test)

Example 8 with FakeFileHashCache

use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.

the class ManifestTest method lookupHashMismatch.

@Test
public void lookupHashMismatch() throws IOException {
    RuleKey key = new RuleKey("aa");
    SourcePath input = new FakeSourcePath("input.h");
    Manifest manifest = Manifest.fromMap(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input).toString(), HashCode.fromInt(1))));
    FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(RESOLVER.getAbsolutePath(input), HashCode.fromInt(2)));
    assertThat(manifest.lookup(fileHashCache, RESOLVER, ImmutableSet.of(input)), Matchers.equalTo(Optional.empty()));
}
Also used : FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) Test(org.junit.Test)

Example 9 with FakeFileHashCache

use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.

the class ManifestTest method lookupMatchWithSourcePathsThatHaveSameRelativePaths.

@Test
public void lookupMatchWithSourcePathsThatHaveSameRelativePaths() throws IOException {
    RuleKey key = new RuleKey("aa");
    Path tmp1 = Files.createTempDirectory("tmp1");
    ProjectFilesystem filesystem1 = new FakeProjectFilesystem(tmp1);
    SourcePath input1 = new PathSourcePath(filesystem1, Paths.get("input.h"));
    HashCode hashCode1 = HashCode.fromInt(1);
    Path tmp2 = Files.createTempDirectory("tmp2");
    ProjectFilesystem filesystem2 = new FakeProjectFilesystem(tmp2);
    SourcePath input2 = new PathSourcePath(filesystem2, Paths.get("input.h"));
    HashCode hashCode2 = HashCode.fromInt(1);
    FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(RESOLVER.getAbsolutePath(input1), hashCode1, RESOLVER.getAbsolutePath(input2), hashCode2));
    Manifest manifest1 = Manifest.fromMap(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input1).toString(), Manifest.hashSourcePathGroup(fileHashCache, RESOLVER, ImmutableList.of(input1, input2)))));
    assertThat(manifest1.lookup(fileHashCache, RESOLVER, ImmutableSet.of(input1, input2)), Matchers.equalTo(Optional.of(key)));
    Manifest manifest2 = Manifest.fromMap(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input2).toString(), Manifest.hashSourcePathGroup(fileHashCache, RESOLVER, ImmutableList.of(input1, input2)))));
    assertThat(manifest2.lookup(fileHashCache, RESOLVER, ImmutableSet.of(input1, input2)), Matchers.equalTo(Optional.of(key)));
}
Also used : Path(java.nio.file.Path) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) HashCode(com.google.common.hash.HashCode) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 10 with FakeFileHashCache

use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.

the class TargetGraphHashingTest method hashChangesWhenSrcContentChanges.

@Test
public void hashChangesWhenSrcContentChanges() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
    TargetNode<?, ?> node = createJavaLibraryTargetNodeWithSrcs(BuildTargetFactory.newInstance("//foo:lib"), HashCode.fromLong(64738), ImmutableSet.of(Paths.get("foo/FooLib.java")));
    TargetGraph targetGraph = TargetGraphFactory.newInstance(node);
    FileHashCache baseCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abcdef")));
    FileHashCache modifiedCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abc1ef")));
    Map<BuildTarget, HashCode> baseResult = new TargetGraphHashing(eventBus, targetGraph, baseCache, ImmutableList.of(node)).hashTargetGraph();
    Map<BuildTarget, HashCode> modifiedResult = new TargetGraphHashing(eventBus, targetGraph, modifiedCache, ImmutableList.of(node)).hashTargetGraph();
    assertThat(baseResult, aMapWithSize(1));
    assertThat(baseResult, hasKey(node.getBuildTarget()));
    assertThat(modifiedResult, aMapWithSize(1));
    assertThat(modifiedResult, hasKey(node.getBuildTarget()));
    assertThat(modifiedResult.get(node.getBuildTarget()), not(equalTo(baseResult.get(node.getBuildTarget()))));
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) NullFileHashCache(com.facebook.buck.util.cache.NullFileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) HashCode(com.google.common.hash.HashCode) BuildId(com.facebook.buck.model.BuildId) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) BuildTarget(com.facebook.buck.model.BuildTarget) IncrementingFakeClock(com.facebook.buck.timing.IncrementingFakeClock) Test(org.junit.Test)

Aggregations

FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)42 Test (org.junit.Test)38 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)24 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)24 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)22 RuleKey (com.facebook.buck.rules.RuleKey)22 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)22 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)20 Path (java.nio.file.Path)20 PathSourcePath (com.facebook.buck.rules.PathSourcePath)19 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)18 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)16 SourcePath (com.facebook.buck.rules.SourcePath)16 AddToRuleKey (com.facebook.buck.rules.AddToRuleKey)14 BuildRule (com.facebook.buck.rules.BuildRule)14 FileHashCache (com.facebook.buck.util.cache.FileHashCache)14 HashCode (com.google.common.hash.HashCode)13 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)12 BuildTarget (com.facebook.buck.model.BuildTarget)11 BorrowablePath (com.facebook.buck.io.BorrowablePath)8