Search in sources :

Example 16 with FileHashCache

use of com.facebook.buck.util.cache.FileHashCache 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 17 with FileHashCache

use of com.facebook.buck.util.cache.FileHashCache 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 18 with FileHashCache

use of com.facebook.buck.util.cache.FileHashCache 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)

Example 19 with FileHashCache

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

the class TargetGraphHashingTest method hashChangesForDependentNodeWhenDepsChange.

@Test
public void hashChangesForDependentNodeWhenDepsChange() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
    FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
    BuildTarget nodeTarget = BuildTargetFactory.newInstance("//foo:lib");
    BuildTarget depTarget = BuildTargetFactory.newInstance("//dep:lib");
    TargetGraph targetGraphA = createGraphWithANodeAndADep(nodeTarget, HashCode.fromLong(12345), depTarget, HashCode.fromLong(64738));
    TargetGraph targetGraphB = createGraphWithANodeAndADep(nodeTarget, HashCode.fromLong(12345), depTarget, HashCode.fromLong(84552));
    FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abcdef"), projectFilesystem.resolve("dep/DepLib.java"), HashCode.fromString("123456")));
    Map<BuildTarget, HashCode> resultA = new TargetGraphHashing(eventBus, targetGraphA, fileHashCache, ImmutableList.of(targetGraphA.get(nodeTarget))).hashTargetGraph();
    Map<BuildTarget, HashCode> resultB = new TargetGraphHashing(eventBus, targetGraphB, fileHashCache, ImmutableList.of(targetGraphB.get(nodeTarget))).hashTargetGraph();
    assertThat(resultA, aMapWithSize(2));
    assertThat(resultA, hasKey(nodeTarget));
    assertThat(resultA, hasKey(depTarget));
    assertThat(resultB, aMapWithSize(2));
    assertThat(resultB, hasKey(nodeTarget));
    assertThat(resultB, hasKey(depTarget));
    assertThat(resultA.get(nodeTarget), not(equalTo(resultB.get(nodeTarget))));
    assertThat(resultA.get(depTarget), not(equalTo(resultB.get(depTarget))));
}
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)

Example 20 with FileHashCache

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

the class InputBasedRuleKeyFactoryTest method ruleKeysForOversizedRules.

@Test
public void ruleKeysForOversizedRules() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(0);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
    FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    final int sizeLimit = 200;
    InputBasedRuleKeyFactory factory = new InputBasedRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder, sizeLimit);
    // Create rule with inputs that make it go past the size limit, and verify the rule key factory
    // doesn't create a rule key.
    final int tooLargeRuleSize = 300;
    assertThat(tooLargeRuleSize, Matchers.greaterThan(sizeLimit));
    Path tooLargeInput = filesystem.getPath("too_large_input");
    filesystem.writeBytesToPath(new byte[tooLargeRuleSize], tooLargeInput);
    BuildRule tooLargeRule = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:large_rule")).setOut("out").setSrc(new PathSourcePath(filesystem, tooLargeInput)).build(resolver, filesystem);
    expectedException.expect(SizeLimiter.SizeLimitException.class);
    factory.build(tooLargeRule);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) 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) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Aggregations

FileHashCache (com.facebook.buck.util.cache.FileHashCache)46 Test (org.junit.Test)37 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)31 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)30 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)30 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)27 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)25 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)25 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)22 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)22 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)18 Path (java.nio.file.Path)17 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)14 BuildTarget (com.facebook.buck.model.BuildTarget)14 RuleKey (com.facebook.buck.rules.RuleKey)14 NullFileHashCache (com.facebook.buck.util.cache.NullFileHashCache)12 HashCode (com.google.common.hash.HashCode)12 BuildRule (com.facebook.buck.rules.BuildRule)11 PathSourcePath (com.facebook.buck.rules.PathSourcePath)11 SourcePath (com.facebook.buck.rules.SourcePath)10