use of com.facebook.buck.util.cache.StackedFileHashCache in project buck by facebook.
the class ShTestDescriptionTest method getRuleKey.
private RuleKey getRuleKey(BuildRule rule) {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(rule.getProjectFilesystem())));
DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder);
return factory.build(rule);
}
use of com.facebook.buck.util.cache.StackedFileHashCache 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);
}
use of com.facebook.buck.util.cache.StackedFileHashCache in project buck by facebook.
the class DefaultJavaLibraryTest method testInputBasedRuleKeyWithJavaLibraryDep.
/**
* Tests that input-based rule keys work properly with simple Java library deps.
*/
@Test
public void testInputBasedRuleKeyWithJavaLibraryDep() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
// Setup a Java library which builds against another Java library dep.
TargetNode<JavaLibraryDescription.Arg, ?> depNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep"), filesystem).addSrc(Paths.get("Source.java")).build();
TargetNode<?, ?> libraryNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib"), filesystem).addDep(depNode.getBuildTarget()).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(depNode, libraryNode);
ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
JavaLibrary dep = (JavaLibrary) ruleResolver.requireRule(depNode.getBuildTarget());
JavaLibrary library = (JavaLibrary) ruleResolver.requireRule(libraryNode.getBuildTarget());
filesystem.writeContentsToPath("JAR contents", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
writeAbiJar(filesystem, pathResolver.getRelativePath(ruleResolver.requireRule(dep.getAbiJar().get()).getSourcePathToOutput()), "Source.class", "ABI JAR contents");
FileHashCache originalHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
InputBasedRuleKeyFactory factory = new InputBasedRuleKeyFactory(0, originalHashCache, pathResolver, ruleFinder);
RuleKey originalRuleKey = factory.build(library);
// Now change the Java library dependency such that its rule key changes, and change its JAR
// contents, but keep its ABI JAR the same. This should *not* affect the input-based rule key
// of the consuming java library, since it only cares about the contents of the ABI JAR.
depNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep")).addSrc(Paths.get("Source.java")).setResourcesRoot(Paths.get("some root that changes the rule key")).build();
targetGraph = TargetGraphFactory.newInstance(depNode, libraryNode);
ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
ruleFinder = new SourcePathRuleFinder(ruleResolver);
pathResolver = new SourcePathResolver(ruleFinder);
dep = (JavaLibrary) ruleResolver.requireRule(depNode.getBuildTarget());
library = (JavaLibrary) ruleResolver.requireRule(libraryNode.getBuildTarget());
filesystem.writeContentsToPath("different JAR contents", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
FileHashCache unaffectedHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
factory = new InputBasedRuleKeyFactory(0, unaffectedHashCache, pathResolver, ruleFinder);
RuleKey unaffectedRuleKey = factory.build(library);
assertThat(originalRuleKey, equalTo(unaffectedRuleKey));
// Now actually change the Java library dependency's ABI JAR. This *should* affect the
// input-based rule key of the consuming java library.
ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
ruleFinder = new SourcePathRuleFinder(ruleResolver);
pathResolver = new SourcePathResolver(ruleFinder);
dep = (JavaLibrary) ruleResolver.requireRule(depNode.getBuildTarget());
library = (JavaLibrary) ruleResolver.requireRule(libraryNode.getBuildTarget());
writeAbiJar(filesystem, pathResolver.getRelativePath(ruleResolver.requireRule(dep.getAbiJar().get()).getSourcePathToOutput()), "Source.class", "changed ABI JAR contents");
FileHashCache affectedHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
factory = new InputBasedRuleKeyFactory(0, affectedHashCache, pathResolver, ruleFinder);
RuleKey affectedRuleKey = factory.build(library);
assertThat(originalRuleKey, Matchers.not(equalTo(affectedRuleKey)));
}
use of com.facebook.buck.util.cache.StackedFileHashCache in project buck by facebook.
the class DefaultJavaLibraryTest method testInputBasedRuleKeySourceChange.
/**
* Tests that input-based rule keys work properly with generated sources.
*/
@Test
public void testInputBasedRuleKeySourceChange() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
// Setup a Java library consuming a source generated by a genrule and grab its rule key.
BuildRule genSrc = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:gen_srcs")).setOut("Test.java").setCmd("something").build(ruleResolver, filesystem);
filesystem.writeContentsToPath("class Test {}", pathResolver.getRelativePath(genSrc.getSourcePathToOutput()));
JavaLibrary library = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib")).addSrc(genSrc.getSourcePathToOutput()).build(ruleResolver, filesystem);
FileHashCache originalHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
InputBasedRuleKeyFactory factory = new InputBasedRuleKeyFactory(0, originalHashCache, pathResolver, ruleFinder);
RuleKey originalRuleKey = factory.build(library);
// Now change the genrule such that its rule key changes, but it's output stays the same (since
// we don't change it). This should *not* affect the input-based rule key of the consuming
// java library, since it only cares about the contents of the source.
ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
genSrc = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:gen_srcs")).setOut("Test.java").setCmd("something else").build(ruleResolver, filesystem);
library = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib")).addSrc(genSrc.getSourcePathToOutput()).build(ruleResolver, filesystem);
FileHashCache unaffectedHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
factory = new InputBasedRuleKeyFactory(0, unaffectedHashCache, pathResolver, ruleFinder);
RuleKey unaffectedRuleKey = factory.build(library);
assertThat(originalRuleKey, equalTo(unaffectedRuleKey));
// Now actually modify the source, which should make the input-based rule key change.
ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
genSrc = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:gen_srcs")).setOut("Test.java").setCmd("something else").build(ruleResolver, filesystem);
filesystem.writeContentsToPath("class Test2 {}", pathResolver.getRelativePath(genSrc.getSourcePathToOutput()));
library = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib")).addSrc(genSrc.getSourcePathToOutput()).build(ruleResolver, filesystem);
FileHashCache affectedHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
factory = new InputBasedRuleKeyFactory(0, affectedHashCache, pathResolver, ruleFinder);
RuleKey affectedRuleKey = factory.build(library);
assertThat(originalRuleKey, Matchers.not(equalTo(affectedRuleKey)));
}
use of com.facebook.buck.util.cache.StackedFileHashCache in project buck by facebook.
the class SanitizedArgTest method createRuleKeyBuilder.
private RuleKeyBuilder<RuleKey> createRuleKeyBuilder() {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(projectFilesystem)));
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
return new UncachedRuleKeyBuilder(ruleFinder, resolver, fileHashCache, new DefaultRuleKeyFactory(0, fileHashCache, resolver, ruleFinder));
}
Aggregations