use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class TargetGraphHashingTest method hashChangesForDependentNodeWhenDepsChange.
@Test
public void hashChangesForDependentNodeWhenDepsChange() throws IOException, InterruptedException, AcyclicDepthFirstPostOrderTraversal.CycleException {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
BuckEventBus eventBus = new BuckEventBus(new IncrementingFakeClock(), new BuildId());
BuildTarget nodeTarget = BuildTargetFactory.newInstance("//foo:lib");
BuildTarget depTarget = BuildTargetFactory.newInstance("//dep:lib");
TargetGraph targetGraphA = createGraphWithANodeAndADep(nodeTarget, HashCode.fromLong(12345), depTarget, HashCode.fromLong(64738));
TargetGraph targetGraphB = createGraphWithANodeAndADep(nodeTarget, HashCode.fromLong(12345), depTarget, HashCode.fromLong(84552));
FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(projectFilesystem.resolve("foo/FooLib.java"), HashCode.fromString("abcdef"), projectFilesystem.resolve("dep/DepLib.java"), HashCode.fromString("123456")));
Map<BuildTarget, HashCode> resultA = new TargetGraphHashing(eventBus, targetGraphA, fileHashCache, ImmutableList.of(targetGraphA.get(nodeTarget))).hashTargetGraph();
Map<BuildTarget, HashCode> resultB = new TargetGraphHashing(eventBus, targetGraphB, fileHashCache, ImmutableList.of(targetGraphB.get(nodeTarget))).hashTargetGraph();
assertThat(resultA, aMapWithSize(2));
assertThat(resultA, hasKey(nodeTarget));
assertThat(resultA, hasKey(depTarget));
assertThat(resultB, aMapWithSize(2));
assertThat(resultB, hasKey(nodeTarget));
assertThat(resultB, hasKey(depTarget));
assertThat(resultA.get(nodeTarget), not(equalTo(resultB.get(nodeTarget))));
assertThat(resultA.get(depTarget), not(equalTo(resultB.get(depTarget))));
}
use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyDoesNotChangeIfNonHashingSourcePathContentChanges.
@Test
public void ruleKeyDoesNotChangeIfNonHashingSourcePathContentChanges() throws NoSuchBuildTargetException {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
final ProjectFilesystem fileSystem = new FakeProjectFilesystem();
// Build a rule key with a particular hash set for the output for the above rule.
Path filePath = fileSystem.getPath("file.txt");
FakeFileHashCache hashCache = new FakeFileHashCache(new HashMap<>());
hashCache.set(filePath.toAbsolutePath(), HashCode.fromInt(0));
PathSourcePath sourcePath = new PathSourcePath(fileSystem, filePath);
NonHashableSourcePathContainer nonHashablePath = new NonHashableSourcePathContainer(sourcePath);
RuleKey inputKey1 = computeRuleKey(hashCache, pathResolver, ruleFinder, nonHashablePath);
hashCache.set(filePath.toAbsolutePath(), HashCode.fromInt(1));
RuleKey inputKey2 = computeRuleKey(hashCache, pathResolver, ruleFinder, nonHashablePath);
assertThat(inputKey1, Matchers.equalTo(inputKey2));
}
use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyDoesNotChangeWhenOnlyDependencyRuleKeyChanges.
@Test
public void ruleKeyDoesNotChangeWhenOnlyDependencyRuleKeyChanges() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
Path depOutput = Paths.get("output");
FakeBuildRule dep = resolver.addToIndex(new FakeBuildRule(BuildTargetFactory.newInstance("//:dep"), filesystem, pathResolver));
dep.setOutputFile(depOutput.toString());
filesystem.writeContentsToPath("hello", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(filesystem.resolve(depOutput), HashCode.fromInt(0)));
BuildRule rule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("out").setSrcs(ImmutableList.of(dep.getSourcePathToOutput())).build(resolver, filesystem);
RuleKey inputKey1 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
RuleKey inputKey2 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
assertThat(inputKey1, Matchers.equalTo(inputKey2));
}
use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyChangesIfInputContentsFromBuildTargetSourcePathChanges.
@Test
public void ruleKeyChangesIfInputContentsFromBuildTargetSourcePathChanges() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
BuildRule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver, filesystem);
BuildRule rule = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("out").setSrc(dep.getSourcePathToOutput()).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(pathResolver.getAbsolutePath(Preconditions.checkNotNull(dep.getSourcePathToOutput())), 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(pathResolver.getAbsolutePath((Preconditions.checkNotNull(dep.getSourcePathToOutput()))), HashCode.fromInt(1)));
RuleKey inputKey2 = new InputBasedRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(rule);
assertThat(inputKey1, Matchers.not(Matchers.equalTo(inputKey2)));
}
use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyChangesIfInputContentsFromPathSourcePathInRuleKeyAppendableChanges.
@Test
public void ruleKeyChangesIfInputContentsFromPathSourcePathInRuleKeyAppendableChanges() {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
final FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
final Path output = Paths.get("output");
BuildRuleParams params = new FakeBuildRuleParamsBuilder("//:rule").setProjectFilesystem(filesystem).build();
BuildRule rule = new NoopBuildRule(params) {
@AddToRuleKey
RuleKeyAppendableWithInput input = new RuleKeyAppendableWithInput(new PathSourcePath(filesystem, output));
};
// 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