use of com.facebook.buck.rules.FakeDepFileBuildRule in project buck by facebook.
the class DependencyFileRuleKeyFactoryTest method testDepFileRuleKeyImpl.
private void testDepFileRuleKeyImpl(SourcePathRuleFinder ruleFinder, SourcePathResolver pathResolver, Object fieldValueBefore, Object fieldValueAfter, ImmutableMap<Path, HashCode> hashesBefore, ImmutableMap<Path, HashCode> hashesAfter, Predicate<SourcePath> coveredInputPaths, ImmutableSet<SourcePath> interestingInputPaths, ImmutableList<DependencyFileEntry> depFileEntries, boolean expectSameKeys, ImmutableSet<SourcePath> expectedDepFileInputsAfter, String failureMessage) throws Exception {
RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(0);
FakeDepFileBuildRule rule1 = new FakeDepFileBuildRule("//:rule") {
@AddToRuleKey
final Object myField = fieldValueBefore;
};
rule1.setCoveredByDepFilePredicate(coveredInputPaths);
rule1.setExistenceOfInterestPredicate(interestingInputPaths);
FakeFileHashCache hashCache = new FakeFileHashCache(hashesBefore, true, ImmutableMap.of());
RuleKeyAndInputs res1 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).build(rule1, depFileEntries);
FakeDepFileBuildRule rule2 = new FakeDepFileBuildRule("//:rule") {
@AddToRuleKey
final Object myField = fieldValueAfter;
};
rule2.setCoveredByDepFilePredicate(coveredInputPaths);
rule2.setExistenceOfInterestPredicate(interestingInputPaths);
hashCache = new FakeFileHashCache(hashesAfter, true, ImmutableMap.of());
RuleKeyAndInputs res2 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).build(rule2, depFileEntries);
if (expectSameKeys) {
assertThat(failureMessage, res2.getRuleKey(), Matchers.equalTo(res1.getRuleKey()));
} else {
assertThat(failureMessage, res2.getRuleKey(), Matchers.not(Matchers.equalTo(res1.getRuleKey())));
}
assertThat(res2.getInputs(), Matchers.equalTo(expectedDepFileInputsAfter));
}
use of com.facebook.buck.rules.FakeDepFileBuildRule 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.FakeDepFileBuildRule in project buck by facebook.
the class DependencyFileRuleKeyFactoryTest method testManifestKeyImpl.
private void testManifestKeyImpl(SourcePathRuleFinder ruleFinder, SourcePathResolver pathResolver, Object fieldValueBefore, Object fieldValueAfter, ImmutableMap<Path, HashCode> hashesBefore, ImmutableMap<Path, HashCode> hashesAfter, Predicate<SourcePath> coveredInputPaths, ImmutableSet<SourcePath> interestingInputPaths, boolean expectSameKeys, ImmutableSet<SourcePath> expectedDepFileInputsAfter, String failureMessage) throws Exception {
RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(0);
FakeDepFileBuildRule rule1 = new FakeDepFileBuildRule("//:rule") {
@AddToRuleKey
final Object myField = fieldValueBefore;
};
rule1.setCoveredByDepFilePredicate(coveredInputPaths);
rule1.setExistenceOfInterestPredicate(interestingInputPaths);
FakeFileHashCache hashCache = new FakeFileHashCache(hashesBefore, true, ImmutableMap.of());
RuleKeyAndInputs res1 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).buildManifestKey(rule1);
FakeDepFileBuildRule rule2 = new FakeDepFileBuildRule("//:rule") {
@AddToRuleKey
final Object myField = fieldValueAfter;
};
rule2.setCoveredByDepFilePredicate(coveredInputPaths);
rule2.setExistenceOfInterestPredicate(interestingInputPaths);
hashCache = new FakeFileHashCache(hashesAfter, true, ImmutableMap.of());
RuleKeyAndInputs res2 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).buildManifestKey(rule2);
if (expectSameKeys) {
assertThat(failureMessage, res2.getRuleKey(), Matchers.equalTo(res1.getRuleKey()));
} else {
assertThat(failureMessage, res2.getRuleKey(), Matchers.not(Matchers.equalTo(res1.getRuleKey())));
}
assertThat(res2.getInputs(), Matchers.equalTo(expectedDepFileInputsAfter));
}
Aggregations