use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class RuleKeyBuilderTest method newBuilder.
private RuleKeyBuilder<RuleKey> newBuilder() {
Map<BuildTarget, BuildRule> ruleMap = ImmutableMap.of(TARGET_1, RULE_1, TARGET_2, RULE_2);
Map<BuildRule, RuleKey> ruleKeyMap = ImmutableMap.of(RULE_1, RULE_KEY_1, RULE_2, RULE_KEY_2);
Map<RuleKeyAppendable, RuleKey> appendableKeys = ImmutableMap.of(APPENDABLE_1, RULE_KEY_1, APPENDABLE_2, RULE_KEY_2);
BuildRuleResolver ruleResolver = new FakeBuildRuleResolver(ruleMap);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(FILESYSTEM.resolve(PATH_1), HashCode.fromInt(0), FILESYSTEM.resolve(PATH_2), HashCode.fromInt(42)), ImmutableMap.of(pathResolver.getAbsoluteArchiveMemberPath(ARCHIVE_PATH_1), HashCode.fromInt(0), pathResolver.getAbsoluteArchiveMemberPath(ARCHIVE_PATH_2), HashCode.fromInt(42)), ImmutableMap.of());
RuleKeyHasher<HashCode> hasher = new GuavaRuleKeyHasher(Hashing.sha1().newHasher());
return new RuleKeyBuilder<RuleKey>(ruleFinder, pathResolver, hashCache, hasher) {
@Override
protected RuleKeyBuilder<RuleKey> setBuildRule(BuildRule rule) {
if (rule == IGNORED_RULE) {
return this;
}
return setBuildRuleKey(ruleKeyMap.get(rule));
}
@Override
public RuleKeyBuilder<RuleKey> setAppendableRuleKey(RuleKeyAppendable appendable) {
if (appendable == IGNORED_APPENDABLE) {
return this;
}
return setAppendableRuleKey(appendableKeys.get(appendable));
}
@Override
protected RuleKeyBuilder<RuleKey> setSourcePath(SourcePath sourcePath) throws IOException {
if (sourcePath instanceof BuildTargetSourcePath) {
return setSourcePathAsRule((BuildTargetSourcePath<?>) sourcePath);
} else {
return setSourcePathDirectly(sourcePath);
}
}
@Override
protected RuleKeyBuilder<RuleKey> setNonHashingSourcePath(SourcePath sourcePath) {
return setNonHashingSourcePathDirectly(sourcePath);
}
@Override
public RuleKey build() {
return buildRuleKey();
}
};
}
use of com.facebook.buck.testutil.FakeFileHashCache 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.testutil.FakeFileHashCache in project buck by facebook.
the class SymlinkTreeTest method testSymlinkTreeInputBasedRuleKeysAreImmuneToLinkSourceContentChanges.
@Test
public void testSymlinkTreeInputBasedRuleKeysAreImmuneToLinkSourceContentChanges() throws Exception {
Genrule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(ruleResolver);
symlinkTreeBuildRule = new SymlinkTree(buildTarget, projectFilesystem, outputPath, ImmutableMap.of(Paths.get("link"), dep.getSourcePathToOutput()), ruleFinder);
// Generate an input-based rule key for the symlink tree with the contents of the link
// target hashing to "aaaa".
FakeFileHashCache hashCache = FakeFileHashCache.createFromStrings(ImmutableMap.of("out", "aaaa"));
InputBasedRuleKeyFactory inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder);
RuleKey ruleKey1 = inputBasedRuleKeyFactory.build(symlinkTreeBuildRule);
// Generate an input-based rule key for the symlink tree with the contents of the link
// target hashing to a different value: "bbbb".
hashCache = FakeFileHashCache.createFromStrings(ImmutableMap.of("out", "bbbb"));
inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder);
RuleKey ruleKey2 = inputBasedRuleKeyFactory.build(symlinkTreeBuildRule);
// Verify that the rules keys are the same.
assertEquals(ruleKey1, ruleKey2);
}
use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class RuleKeyTest method subclassWithNoopSetter.
@Test
public void subclassWithNoopSetter() {
class NoopSetterRuleKeyBuilder extends UncachedRuleKeyBuilder {
public NoopSetterRuleKeyBuilder(SourcePathRuleFinder ruleFinder, SourcePathResolver pathResolver, FileHashCache hashCache, RuleKeyFactory<RuleKey> defaultRuleKeyFactory) {
super(ruleFinder, pathResolver, hashCache, defaultRuleKeyFactory);
}
@Override
protected NoopSetterRuleKeyBuilder setSourcePath(SourcePath sourcePath) {
return this;
}
}
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of());
RuleKeyFactory<RuleKey> ruleKeyFactory = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder);
RuleKey nullRuleKey = new NoopSetterRuleKeyBuilder(ruleFinder, pathResolver, hashCache, ruleKeyFactory).build();
RuleKey noopRuleKey = new NoopSetterRuleKeyBuilder(ruleFinder, pathResolver, hashCache, ruleKeyFactory).setReflectively("key", new FakeSourcePath("value")).build();
assertThat(noopRuleKey, is(equalTo(nullRuleKey)));
}
use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class TargetGraphHashingTest method twoNodeIndependentRootsTargetGraphHasExpectedHashes.
@Test
public void twoNodeIndependentRootsTargetGraphHasExpectedHashes() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
TargetNode<?, ?> nodeA = createJavaLibraryTargetNodeWithSrcs(BuildTargetFactory.newInstance("//foo:lib"), HashCode.fromLong(64738), ImmutableSet.of(Paths.get("foo/FooLib.java")));
TargetNode<?, ?> nodeB = createJavaLibraryTargetNodeWithSrcs(BuildTargetFactory.newInstance("//bar:lib"), HashCode.fromLong(49152), ImmutableSet.of(Paths.get("bar/BarLib.java")));
TargetGraph targetGraphA = TargetGraphFactory.newInstance(nodeA);
TargetGraph targetGraphB = TargetGraphFactory.newInstance(nodeB);
TargetGraph commonTargetGraph = TargetGraphFactory.newInstance(nodeA, nodeB);
FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abcdef"), projectFilesystem.resolve("bar/BarLib.java"), HashCode.fromString("123456")));
Map<BuildTarget, HashCode> resultsA = new TargetGraphHashing(eventBus, targetGraphA, fileHashCache, ImmutableList.of(nodeA)).hashTargetGraph();
Map<BuildTarget, HashCode> resultsB = new TargetGraphHashing(eventBus, targetGraphB, fileHashCache, ImmutableList.of(nodeB)).hashTargetGraph();
Map<BuildTarget, HashCode> commonResults = new TargetGraphHashing(eventBus, commonTargetGraph, fileHashCache, ImmutableList.of(nodeA, nodeB)).hashTargetGraph();
assertThat(resultsA, aMapWithSize(1));
assertThat(resultsA, hasKey(nodeA.getBuildTarget()));
assertThat(resultsB, aMapWithSize(1));
assertThat(resultsB, hasKey(nodeB.getBuildTarget()));
assertThat(commonResults, aMapWithSize(2));
assertThat(commonResults, hasKey(nodeA.getBuildTarget()));
assertThat(commonResults, hasKey(nodeB.getBuildTarget()));
assertThat(resultsA.get(nodeA.getBuildTarget()), equalTo(commonResults.get(nodeA.getBuildTarget())));
assertThat(resultsB.get(nodeB.getBuildTarget()), equalTo(commonResults.get(nodeB.getBuildTarget())));
}
Aggregations