use of com.facebook.buck.util.cache.FileHashCache in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyNotCalculatedIfSizeLimitHitWithDirectory.
@Test
public void ruleKeyNotCalculatedIfSizeLimitHitWithDirectory() 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)));
// Create a directory of files which combine to pass size limit.
Path input = filesystem.getPath("input");
filesystem.mkdirs(input);
filesystem.writeBytesToPath(new byte[150], input.resolve("file1"));
filesystem.writeBytesToPath(new byte[150], input.resolve("file2"));
// Construct rule which uses inputs.
BuildRule rule = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("out").setSrc(new PathSourcePath(filesystem, input)).build(resolver, filesystem);
// Verify rule key isn't calculated.
expectedException.expect(SizeLimiter.SizeLimitException.class);
new InputBasedRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder, 200).build(rule);
}
use of com.facebook.buck.util.cache.FileHashCache 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.FileHashCache 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.FileHashCache 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.FileHashCache 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