Search in sources :

Example 1 with DefaultFileHashCache

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

the class DirectHeaderMapTest method testRuleKeyDoesNotChangeIfLinkTargetsChange.

@Test
public void testRuleKeyDoesNotChangeIfLinkTargetsChange() throws IOException {
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    ruleResolver.addToIndex(buildRule);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    // Calculate their rule keys and verify they're different.
    DefaultFileHashCache hashCache = DefaultFileHashCache.createDefaultFileHashCache(new ProjectFilesystem(tmpDir.getRoot()));
    FileHashLoader hashLoader = new StackedFileHashCache(ImmutableList.of(hashCache));
    RuleKey defaultKey1 = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(buildRule);
    RuleKey inputKey1 = new InputBasedRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(buildRule);
    Files.write(file1, "hello other world".getBytes());
    hashCache.invalidateAll();
    RuleKey defaultKey2 = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(buildRule);
    RuleKey inputKey2 = new InputBasedRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(buildRule);
    // When the file content changes, the rulekey should change but the input rulekey should be
    // unchanged. This ensures that a dependent's rulekey changes correctly.
    assertNotEquals(defaultKey1, defaultKey2);
    assertEquals(inputKey1, inputKey2);
}
Also used : DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) FileHashLoader(com.facebook.buck.hashing.FileHashLoader) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) InputBasedRuleKeyFactory(com.facebook.buck.rules.keys.InputBasedRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 2 with DefaultFileHashCache

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

the class HeaderSymlinkTreeWithHeaderMapTest method testSymlinkTreeRuleKeyChangesIfLinkMapChanges.

@Test
public void testSymlinkTreeRuleKeyChangesIfLinkMapChanges() throws Exception {
    Path aFile = tmpDir.newFile();
    Files.write(aFile, "hello world".getBytes(Charsets.UTF_8));
    HeaderSymlinkTreeWithHeaderMap modifiedSymlinkTreeBuildRule = HeaderSymlinkTreeWithHeaderMap.create(buildTarget, projectFilesystem, symlinkTreeRoot, ImmutableMap.of(Paths.get("different/link"), new PathSourcePath(projectFilesystem, MorePaths.relativize(tmpDir.getRoot(), aFile))), ruleFinder);
    // Calculate their rule keys and verify they're different.
    DefaultFileHashCache hashCache = DefaultFileHashCache.createDefaultFileHashCache(new ProjectFilesystem(tmpDir.getRoot()));
    FileHashLoader hashLoader = new StackedFileHashCache(ImmutableList.of(hashCache));
    RuleKey key1 = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(symlinkTreeBuildRule);
    RuleKey key2 = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(modifiedSymlinkTreeBuildRule);
    assertNotEquals(key1, key2);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) FileHashLoader(com.facebook.buck.hashing.FileHashLoader) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) PathSourcePath(com.facebook.buck.rules.PathSourcePath) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 3 with DefaultFileHashCache

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

the class HeaderSymlinkTreeWithHeaderMapTest method testSymlinkTreeRuleKeyChangesIfLinkTargetsChange.

@Test
public void testSymlinkTreeRuleKeyChangesIfLinkTargetsChange() throws IOException {
    ruleResolver.addToIndex(symlinkTreeBuildRule);
    DefaultFileHashCache hashCache = DefaultFileHashCache.createDefaultFileHashCache(new ProjectFilesystem(tmpDir.getRoot()));
    FileHashLoader hashLoader = new StackedFileHashCache(ImmutableList.of(hashCache));
    DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder);
    // Calculate the rule key
    RuleKey key1 = ruleKeyFactory.build(symlinkTreeBuildRule);
    // Change the contents of the target of the link.
    Path existingFile = resolver.getAbsolutePath(links.values().asList().get(0));
    Files.write(existingFile, "something new".getBytes(Charsets.UTF_8));
    hashCache.invalidateAll();
    ruleKeyFactory = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder);
    // Re-calculate the rule key
    RuleKey key2 = ruleKeyFactory.build(symlinkTreeBuildRule);
    // Verify that the rules keys are the same.
    assertNotEquals(key1, key2);
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) FileHashLoader(com.facebook.buck.hashing.FileHashLoader) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 4 with DefaultFileHashCache

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

the class SymlinkTreeTest method testSymlinkTreeDependentRuleKeyChangesWhenLinkSourceContentChanges.

@Test
public void testSymlinkTreeDependentRuleKeyChangesWhenLinkSourceContentChanges() throws Exception {
    // If a dependent of a symlink tree uses the symlink tree's output as an input, that dependent's
    // rulekey must change when the link contents change.
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    ruleResolver.addToIndex(symlinkTreeBuildRule);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    Genrule genrule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setSrcs(ImmutableList.of(symlinkTreeBuildRule.getSourcePathToOutput())).setOut("out").build(ruleResolver);
    DefaultFileHashCache hashCache = DefaultFileHashCache.createDefaultFileHashCache(new ProjectFilesystem(tmpDir.getRoot()));
    FileHashLoader hashLoader = new StackedFileHashCache(ImmutableList.of(hashCache));
    RuleKey ruleKey1 = new DefaultRuleKeyFactory(0, hashLoader, pathResolver, ruleFinder).build(genrule);
    Path existingFile = pathResolver.getAbsolutePath(links.values().asList().get(0));
    Files.write(existingFile, "something new".getBytes(Charsets.UTF_8));
    hashCache.invalidateAll();
    RuleKey ruleKey2 = new DefaultRuleKeyFactory(0, hashLoader, pathResolver, ruleFinder).build(genrule);
    // Verify that the rules keys are different.
    assertNotEquals(ruleKey1, ruleKey2);
}
Also used : Path(java.nio.file.Path) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) FileHashLoader(com.facebook.buck.hashing.FileHashLoader) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) Genrule(com.facebook.buck.shell.Genrule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 5 with DefaultFileHashCache

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

the class SymlinkTreeTest method testSymlinkTreeRuleKeyChangesIfLinkMapChanges.

@Test
public void testSymlinkTreeRuleKeyChangesIfLinkMapChanges() throws Exception {
    // Create a BuildRule wrapping the stock SymlinkTree buildable.
    //BuildRule rule1 = symlinkTreeBuildable;
    // Also create a new BuildRule based around a SymlinkTree buildable with a different
    // link map.
    Path aFile = tmpDir.newFile();
    Files.write(aFile, "hello world".getBytes(Charsets.UTF_8));
    SymlinkTree modifiedSymlinkTreeBuildRule = new SymlinkTree(buildTarget, projectFilesystem, outputPath, ImmutableMap.of(Paths.get("different/link"), new PathSourcePath(projectFilesystem, MorePaths.relativize(tmpDir.getRoot(), aFile))), ruleFinder);
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
    // Calculate their rule keys and verify they're different.
    DefaultFileHashCache hashCache = DefaultFileHashCache.createDefaultFileHashCache(new ProjectFilesystem(tmpDir.getRoot()));
    FileHashLoader hashLoader = new StackedFileHashCache(ImmutableList.of(hashCache));
    RuleKey key1 = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(symlinkTreeBuildRule);
    RuleKey key2 = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(modifiedSymlinkTreeBuildRule);
    assertNotEquals(key1, key2);
}
Also used : Path(java.nio.file.Path) DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) DefaultFileHashCache(com.facebook.buck.util.cache.DefaultFileHashCache) FileHashLoader(com.facebook.buck.hashing.FileHashLoader) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Aggregations

FileHashLoader (com.facebook.buck.hashing.FileHashLoader)5 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)5 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)5 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)5 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)5 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)5 Test (org.junit.Test)5 Path (java.nio.file.Path)4 RuleKey (com.facebook.buck.rules.RuleKey)3 PathSourcePath (com.facebook.buck.rules.PathSourcePath)2 SourcePath (com.facebook.buck.rules.SourcePath)2 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)1 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)1 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)1 InputBasedRuleKeyFactory (com.facebook.buck.rules.keys.InputBasedRuleKeyFactory)1 Genrule (com.facebook.buck.shell.Genrule)1