use of com.facebook.buck.util.cache.StackedFileHashCache in project buck by facebook.
the class RuleKeyTest method changingRuleKeyFieldOfDepChangesKeyWhenClassImplementsAppendToRuleKey.
@Test
public void changingRuleKeyFieldOfDepChangesKeyWhenClassImplementsAppendToRuleKey() {
BuildTarget target = BuildTargetFactory.newInstance("//cheese:peas");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(new FakeProjectFilesystem())));
BuildRule buildRule1 = new TestRuleKeyAppendableBuildRule(params, "foo", "bar");
BuildRule buildRule2 = new TestRuleKeyAppendableBuildRule(params, "foo", "xyzzy");
BuildTarget parentTarget = BuildTargetFactory.newInstance("//cheese:milk");
BuildRuleParams parentParams1 = new FakeBuildRuleParamsBuilder(parentTarget).setDeclaredDeps(ImmutableSortedSet.of(buildRule1)).build();
BuildRule parentRule1 = new NoopBuildRule(parentParams1);
BuildRuleParams parentParams2 = new FakeBuildRuleParamsBuilder(parentTarget).setDeclaredDeps(ImmutableSortedSet.of(buildRule2)).build();
BuildRule parentRule2 = new NoopBuildRule(parentParams2);
RuleKey ruleKey1 = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(parentRule1);
RuleKey ruleKey2 = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(parentRule2);
assertNotEquals(ruleKey1, ruleKey2);
}
use of com.facebook.buck.util.cache.StackedFileHashCache in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeysForOversizedRules.
@Test
public void ruleKeysForOversizedRules() 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)));
final int sizeLimit = 200;
InputBasedRuleKeyFactory factory = new InputBasedRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder, sizeLimit);
// Create rule with inputs that make it go past the size limit, and verify the rule key factory
// doesn't create a rule key.
final int tooLargeRuleSize = 300;
assertThat(tooLargeRuleSize, Matchers.greaterThan(sizeLimit));
Path tooLargeInput = filesystem.getPath("too_large_input");
filesystem.writeBytesToPath(new byte[tooLargeRuleSize], tooLargeInput);
BuildRule tooLargeRule = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:large_rule")).setOut("out").setSrc(new PathSourcePath(filesystem, tooLargeInput)).build(resolver, filesystem);
expectedException.expect(SizeLimiter.SizeLimitException.class);
factory.build(tooLargeRule);
}
use of com.facebook.buck.util.cache.StackedFileHashCache 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.StackedFileHashCache in project buck by facebook.
the class GenruleTest method inputBasedRuleKeyExecutableMacro.
@Test
public void inputBasedRuleKeyExecutableMacro() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
GenruleBuilder ruleBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setCmd("run $(exe //:dep)").setOut("output");
// Create an initial input-based rule key
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRule dep = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:dep")).setMain(new PathSourcePath(filesystem, Paths.get("dep.exe"))).build(resolver, filesystem);
filesystem.writeContentsToPath("something", Paths.get("dep.exe"));
filesystem.writeContentsToPath("something", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
BuildRule rule = ruleBuilder.build(resolver);
DefaultRuleKeyFactory defaultRuleKeyFactory = new DefaultRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
InputBasedRuleKeyFactory inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
RuleKey originalRuleKey = defaultRuleKeyFactory.build(rule);
RuleKey originalInputRuleKey = inputBasedRuleKeyFactory.build(rule);
// Change the dep's resource list, which will change its normal rule key, but since we're
// keeping its output the same, the input-based rule key for the consuming rule will stay the
// same. This is because the input-based rule key for the consuming rule only cares about the
// contents of the output this rule produces.
resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
Genrule extra = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:extra")).setOut("something").build(resolver);
new ShBinaryBuilder(BuildTargetFactory.newInstance("//:dep")).setMain(new PathSourcePath(filesystem, Paths.get("dep.exe"))).setDeps(ImmutableSortedSet.of(extra.getBuildTarget())).build(resolver, filesystem);
rule = ruleBuilder.build(resolver);
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
defaultRuleKeyFactory = new DefaultRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
RuleKey unchangedRuleKey = defaultRuleKeyFactory.build(rule);
RuleKey unchangedInputBasedRuleKey = inputBasedRuleKeyFactory.build(rule);
assertThat(unchangedRuleKey, Matchers.not(Matchers.equalTo(originalRuleKey)));
assertThat(unchangedInputBasedRuleKey, Matchers.equalTo(originalInputRuleKey));
// Make a change to the dep's output, which *should* affect the input-based rule key.
resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
dep = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:dep")).setMain(new PathSourcePath(filesystem, Paths.get("dep.exe"))).build(resolver, filesystem);
filesystem.writeContentsToPath("something else", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
rule = ruleBuilder.build(resolver);
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
RuleKey changedInputBasedRuleKey = inputBasedRuleKeyFactory.build(rule);
assertThat(changedInputBasedRuleKey, Matchers.not(Matchers.equalTo(originalInputRuleKey)));
}
use of com.facebook.buck.util.cache.StackedFileHashCache in project buck by facebook.
the class GenruleTest method inputBasedRuleKeyClasspathMacro.
@Test
public void inputBasedRuleKeyClasspathMacro() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
GenruleBuilder ruleBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setCmd("run $(classpath //:dep)").setOut("output");
// Create an initial input-based rule key
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
JavaLibrary dep = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep")).addSrc(Paths.get("source.java")).build(resolver, filesystem);
filesystem.writeContentsToPath("something", Paths.get("source.java"));
filesystem.writeContentsToPath("something", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
BuildRule rule = ruleBuilder.build(resolver);
DefaultRuleKeyFactory defaultRuleKeyFactory = new DefaultRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
InputBasedRuleKeyFactory inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
RuleKey originalRuleKey = defaultRuleKeyFactory.build(rule);
RuleKey originalInputRuleKey = inputBasedRuleKeyFactory.build(rule);
// Change the dep's resource root, which will change its normal rule key, but since we're
// keeping its output JAR the same, the input-based rule key for the consuming rule will stay
// the same. This is because the input-based rule key for the consuming rule only cares about
// the contents of the output this rule produces.
resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep")).addSrc(Paths.get("source.java")).setResourcesRoot(Paths.get("resource_root")).build(resolver, filesystem);
rule = ruleBuilder.build(resolver);
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
defaultRuleKeyFactory = new DefaultRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
RuleKey unchangedRuleKey = defaultRuleKeyFactory.build(rule);
RuleKey unchangedInputBasedRuleKey = inputBasedRuleKeyFactory.build(rule);
assertThat(unchangedRuleKey, Matchers.not(Matchers.equalTo(originalRuleKey)));
assertThat(unchangedInputBasedRuleKey, Matchers.equalTo(originalInputRuleKey));
// Make a change to the dep's output, which *should* affect the input-based rule key.
resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
dep = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep")).addSrc(Paths.get("source.java")).build(resolver, filesystem);
filesystem.writeContentsToPath("something else", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
rule = ruleBuilder.build(resolver);
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
RuleKey changedInputBasedRuleKey = inputBasedRuleKeyFactory.build(rule);
assertThat(changedInputBasedRuleKey, Matchers.not(Matchers.equalTo(originalInputRuleKey)));
}
Aggregations