Search in sources :

Example 6 with FileHashLoader

use of com.facebook.buck.hashing.FileHashLoader 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 7 with FileHashLoader

use of com.facebook.buck.hashing.FileHashLoader 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)7 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)6 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)6 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)6 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)6 Test (org.junit.Test)6 DefaultFileHashCache (com.facebook.buck.util.cache.DefaultFileHashCache)5 Path (java.nio.file.Path)5 RuleKey (com.facebook.buck.rules.RuleKey)4 PathSourcePath (com.facebook.buck.rules.PathSourcePath)3 SourcePath (com.facebook.buck.rules.SourcePath)3 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)2 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)2 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)2 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)2 InputBasedRuleKeyFactory (com.facebook.buck.rules.keys.InputBasedRuleKeyFactory)2 BuildTarget (com.facebook.buck.model.BuildTarget)1 TargetGraph (com.facebook.buck.rules.TargetGraph)1 TargetGraphAndTargetNodes (com.facebook.buck.rules.TargetGraphAndTargetNodes)1 TargetGraphHashing (com.facebook.buck.rules.TargetGraphHashing)1