use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class RuleKeyTest method declaredDepsAndExtraDepsGenerateDifferentRuleKeys.
@Test
public void declaredDepsAndExtraDepsGenerateDifferentRuleKeys() {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
FileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of());
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, hashCache, sourcePathResolver, ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//a:target");
BuildTarget depTarget = BuildTargetFactory.newInstance("//some:dep");
BuildRuleParams depParams = new FakeBuildRuleParamsBuilder(depTarget).build();
NoopBuildRule dep = new NoopBuildRule(depParams);
BuildRuleParams paramsWithDeclaredDep = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(dep)).build();
NoopBuildRule ruleWithDeclaredDep = new NoopBuildRule(paramsWithDeclaredDep);
BuildRuleParams paramsWithExtraDep = new FakeBuildRuleParamsBuilder(target).setExtraDeps(ImmutableSortedSet.of(dep)).build();
NoopBuildRule ruleWithExtraDep = new NoopBuildRule(paramsWithExtraDep);
BuildRuleParams paramsWithBothDeps = new FakeBuildRuleParamsBuilder(target).setDeclaredDeps(ImmutableSortedSet.of(dep)).setExtraDeps(ImmutableSortedSet.of(dep)).build();
NoopBuildRule ruleWithBothDeps = new NoopBuildRule(paramsWithBothDeps);
assertNotEquals(ruleKeyFactory.build(ruleWithDeclaredDep), ruleKeyFactory.build(ruleWithExtraDep));
assertNotEquals(ruleKeyFactory.build(ruleWithDeclaredDep), ruleKeyFactory.build(ruleWithBothDeps));
assertNotEquals(ruleKeyFactory.build(ruleWithExtraDep), ruleKeyFactory.build(ruleWithBothDeps));
}
use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class ManifestTest method lookupMissingHeader.
@Test
public void lookupMissingHeader() throws IOException {
RuleKey key = new RuleKey("aa");
SourcePath input = new FakeSourcePath("input.h");
Manifest manifest = Manifest.fromMap(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input).toString(), HashCode.fromInt(1))));
FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of());
assertThat(manifest.lookup(fileHashCache, RESOLVER, ImmutableSet.of(input)), Matchers.equalTo(Optional.empty()));
}
use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class ManifestTest method lookupHashMismatch.
@Test
public void lookupHashMismatch() throws IOException {
RuleKey key = new RuleKey("aa");
SourcePath input = new FakeSourcePath("input.h");
Manifest manifest = Manifest.fromMap(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input).toString(), HashCode.fromInt(1))));
FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(RESOLVER.getAbsolutePath(input), HashCode.fromInt(2)));
assertThat(manifest.lookup(fileHashCache, RESOLVER, ImmutableSet.of(input)), Matchers.equalTo(Optional.empty()));
}
use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class ManifestTest method lookupMatchWithSourcePathsThatHaveSameRelativePaths.
@Test
public void lookupMatchWithSourcePathsThatHaveSameRelativePaths() throws IOException {
RuleKey key = new RuleKey("aa");
Path tmp1 = Files.createTempDirectory("tmp1");
ProjectFilesystem filesystem1 = new FakeProjectFilesystem(tmp1);
SourcePath input1 = new PathSourcePath(filesystem1, Paths.get("input.h"));
HashCode hashCode1 = HashCode.fromInt(1);
Path tmp2 = Files.createTempDirectory("tmp2");
ProjectFilesystem filesystem2 = new FakeProjectFilesystem(tmp2);
SourcePath input2 = new PathSourcePath(filesystem2, Paths.get("input.h"));
HashCode hashCode2 = HashCode.fromInt(1);
FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(RESOLVER.getAbsolutePath(input1), hashCode1, RESOLVER.getAbsolutePath(input2), hashCode2));
Manifest manifest1 = Manifest.fromMap(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input1).toString(), Manifest.hashSourcePathGroup(fileHashCache, RESOLVER, ImmutableList.of(input1, input2)))));
assertThat(manifest1.lookup(fileHashCache, RESOLVER, ImmutableSet.of(input1, input2)), Matchers.equalTo(Optional.of(key)));
Manifest manifest2 = Manifest.fromMap(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input2).toString(), Manifest.hashSourcePathGroup(fileHashCache, RESOLVER, ImmutableList.of(input1, input2)))));
assertThat(manifest2.lookup(fileHashCache, RESOLVER, ImmutableSet.of(input1, input2)), Matchers.equalTo(Optional.of(key)));
}
use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class TargetGraphHashingTest method hashChangesWhenSrcContentChanges.
@Test
public void hashChangesWhenSrcContentChanges() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
TargetNode<?, ?> node = createJavaLibraryTargetNodeWithSrcs(BuildTargetFactory.newInstance("//foo:lib"), HashCode.fromLong(64738), ImmutableSet.of(Paths.get("foo/FooLib.java")));
TargetGraph targetGraph = TargetGraphFactory.newInstance(node);
FileHashCache baseCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abcdef")));
FileHashCache modifiedCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abc1ef")));
Map<BuildTarget, HashCode> baseResult = new TargetGraphHashing(eventBus, targetGraph, baseCache, ImmutableList.of(node)).hashTargetGraph();
Map<BuildTarget, HashCode> modifiedResult = new TargetGraphHashing(eventBus, targetGraph, modifiedCache, ImmutableList.of(node)).hashTargetGraph();
assertThat(baseResult, aMapWithSize(1));
assertThat(baseResult, hasKey(node.getBuildTarget()));
assertThat(modifiedResult, aMapWithSize(1));
assertThat(modifiedResult, hasKey(node.getBuildTarget()));
assertThat(modifiedResult.get(node.getBuildTarget()), not(equalTo(baseResult.get(node.getBuildTarget()))));
}
Aggregations