Search in sources :

Example 46 with FileHashCache

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

the class ExportFileTest method modifyingTheContentsOfTheFileChangesTheRuleKey.

@Test
public void modifyingTheContentsOfTheFileChangesTheRuleKey() throws Exception {
    Path root = Files.createTempDirectory("root");
    FakeProjectFilesystem filesystem = new FakeProjectFilesystem(root);
    Path temp = Paths.get("example_file");
    FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder);
    filesystem.writeContentsToPath("I like cheese", temp);
    ExportFileBuilder builder = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//some:file")).setSrc(new PathSourcePath(filesystem, temp));
    ExportFile rule = builder.build(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()), filesystem);
    RuleKey original = ruleKeyFactory.build(rule);
    filesystem.writeContentsToPath("I really like cheese", temp);
    // Create a new rule. The FileHashCache held by the existing rule will retain a reference to the
    // previous content of the file, so we need to create an identical rule.
    rule = builder.build(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()), filesystem);
    hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
    ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    resolver = new SourcePathResolver(ruleFinder);
    ruleKeyFactory = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder);
    RuleKey refreshed = ruleKeyFactory.build(rule);
    assertNotEquals(original, refreshed);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) Path(java.nio.file.Path) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) 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) RuleKey(com.facebook.buck.rules.RuleKey) 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) 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