use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class DependencyFileRuleKeyFactoryTest method testKeysGetHashed.
@Test
public void testKeysGetHashed() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(0);
BuildRuleResolver ruleResolver = newRuleResolver();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
SourcePath unusedSourcePath = new PathSourcePath(filesystem, Paths.get("input0"));
SourcePath sourcePath = new PathSourcePath(filesystem, Paths.get("input"));
DependencyFileEntry dependencyFileEntry = DependencyFileEntry.fromSourcePath(sourcePath, pathResolver);
ImmutableMap<Path, HashCode> hashes = ImmutableMap.of(pathResolver.getAbsolutePath(sourcePath), HashCode.fromInt(42));
Predicate<SourcePath> coveredPredicate = ImmutableSet.of(sourcePath, unusedSourcePath)::contains;
FakeDepFileBuildRule rule1 = new FakeDepFileBuildRule("//:rule") {
@AddToRuleKey
final Object myField1 = sourcePath;
@AddToRuleKey
final Object myField2 = unusedSourcePath;
};
rule1.setCoveredByDepFilePredicate(coveredPredicate);
FakeFileHashCache hashCache = new FakeFileHashCache(hashes, true, ImmutableMap.of());
RuleKeyAndInputs res1 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).build(rule1, ImmutableList.of(dependencyFileEntry));
FakeDepFileBuildRule rule2 = new FakeDepFileBuildRule("//:rule") {
@AddToRuleKey
final Object myField1 = unusedSourcePath;
@AddToRuleKey
final Object myField2 = sourcePath;
};
rule2.setCoveredByDepFilePredicate(coveredPredicate);
hashCache = new FakeFileHashCache(hashes, true, ImmutableMap.of());
RuleKeyAndInputs res2 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).build(rule2, ImmutableList.of(dependencyFileEntry));
assertThat(res2.getRuleKey(), Matchers.not(Matchers.equalTo(res1.getRuleKey())));
assertThat(res2.getInputs(), Matchers.equalTo(ImmutableSet.of(sourcePath)));
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class DependencyFileRuleKeyFactoryTest method testKeysWhenInputPathContentsChanges.
@Test
public void testKeysWhenInputPathContentsChanges() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver ruleResolver = newRuleResolver();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
SourcePath usedSourcePath = new PathSourcePath(filesystem, Paths.get("usedInput"));
SourcePath unusedSourcePath = new PathSourcePath(filesystem, Paths.get("unusedInput"));
SourcePath noncoveredSourcePath = new PathSourcePath(filesystem, Paths.get("noncoveredInput"));
SourcePath interestingSourcePath = new PathSourcePath(filesystem, Paths.get("interestingIn"));
testKeysWhenInputContentsChanges(ruleFinder, pathResolver, usedSourcePath, unusedSourcePath, noncoveredSourcePath, interestingSourcePath, pathResolver.getAbsolutePath(usedSourcePath), pathResolver.getAbsolutePath(unusedSourcePath), pathResolver.getAbsolutePath(noncoveredSourcePath), pathResolver.getAbsolutePath(interestingSourcePath), DependencyFileEntry.fromSourcePath(usedSourcePath, pathResolver));
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeysForUndersizedRules.
@Test
public void ruleKeysForUndersizedRules() 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 a rule that doesn't pass the size limit and verify it creates a rule key.
final int smallEnoughRuleSize = 100;
assertThat(smallEnoughRuleSize, Matchers.lessThan(sizeLimit));
Path input = filesystem.getPath("small_enough_input");
filesystem.writeBytesToPath(new byte[smallEnoughRuleSize], input);
BuildRule smallEnoughRule = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:small_rule")).setOut("out").setSrc(new PathSourcePath(filesystem, input)).build(resolver, filesystem);
factory.build(smallEnoughRule);
}
use of com.facebook.buck.rules.PathSourcePath in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyNotCalculatedIfSizeLimitHit.
@Test
public void ruleKeyNotCalculatedIfSizeLimitHit() 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 input that passes size limit.
Path input = filesystem.getPath("input");
filesystem.writeBytesToPath(new byte[1024], input);
// Construct rule which uses input.
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.rules.PathSourcePath in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyChangesIfInputContentsFromPathSourceChanges.
@Test
public void ruleKeyChangesIfInputContentsFromPathSourceChanges() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
Path output = Paths.get("output");
BuildRule rule = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("out").setSrc(new PathSourcePath(filesystem, output)).build(resolver, filesystem);
// Build a rule key with a particular hash set for the output for the above rule.
FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(0)));
RuleKey inputKey1 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
// Now, build a rule key with a different hash for the output for the above rule.
hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(output), HashCode.fromInt(1)));
RuleKey inputKey2 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
assertThat(inputKey1, Matchers.not(Matchers.equalTo(inputKey2)));
}
Aggregations