use of com.facebook.buck.util.cache.FileHashCache in project buck by facebook.
the class BuildInfoRecorderTest method testGetOutputHash.
@Test
public void testGetOutputHash() throws IOException {
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
BuildInfoRecorder buildInfoRecorder = createBuildInfoRecorder(filesystem);
byte[] contents = "contents".getBytes();
Path file = Paths.get("file");
filesystem.writeBytesToPath(contents, file);
buildInfoRecorder.recordArtifact(file);
Path dir = Paths.get("dir");
filesystem.mkdirs(dir);
filesystem.writeBytesToPath(contents, dir.resolve("file1"));
filesystem.writeBytesToPath(contents, dir.resolve("file2"));
buildInfoRecorder.recordArtifact(dir);
fileHashCache.invalidateAll();
HashCode current = buildInfoRecorder.getOutputHash(fileHashCache);
// Test that getting the hash again results in the same hashcode.
fileHashCache.invalidateAll();
assertEquals(current, buildInfoRecorder.getOutputHash(fileHashCache));
// Verify that changing a file changes the hash.
filesystem.writeContentsToPath("something else", file);
fileHashCache.invalidateAll();
HashCode updated = buildInfoRecorder.getOutputHash(fileHashCache);
assertNotEquals(current, updated);
// Verify that changing a file under a directory changes the hash.
filesystem.writeContentsToPath("something else", dir.resolve("file1"));
current = updated;
fileHashCache.invalidateAll();
updated = buildInfoRecorder.getOutputHash(fileHashCache);
assertNotEquals(current, updated);
// Test that adding a file updates the hash.
Path added = Paths.get("added");
filesystem.writeBytesToPath(contents, added);
buildInfoRecorder.recordArtifact(added);
current = updated;
fileHashCache.invalidateAll();
updated = buildInfoRecorder.getOutputHash(fileHashCache);
assertNotEquals(current, updated);
// Test that adding a file under a recorded directory updates the hash.
Path addedUnderDir = dir.resolve("added");
filesystem.writeBytesToPath(contents, addedUnderDir);
current = updated;
fileHashCache.invalidateAll();
updated = buildInfoRecorder.getOutputHash(fileHashCache);
assertNotEquals(current, updated);
}
use of com.facebook.buck.util.cache.FileHashCache in project buck by facebook.
the class RuleKeyTest method testRuleKeyDependsOnDeps.
/**
* Ensure that build rules with the same inputs but different deps have unique RuleKeys.
*/
@Test
public void testRuleKeyDependsOnDeps() throws Exception {
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
BuildRuleResolver ruleResolver1 = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
BuildRuleResolver ruleResolver2 = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder1 = new SourcePathRuleFinder(ruleResolver1);
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, hashCache, new SourcePathResolver(ruleFinder1), ruleFinder1);
SourcePathRuleFinder ruleFinder2 = new SourcePathRuleFinder(ruleResolver2);
DefaultRuleKeyFactory ruleKeyFactory2 = new DefaultRuleKeyFactory(0, hashCache, new SourcePathResolver(ruleFinder2), ruleFinder2);
// Create a dependent build rule, //src/com/facebook/buck/cli:common.
JavaLibraryBuilder builder = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//src/com/facebook/buck/cli:common"));
BuildRule commonJavaLibrary = builder.build(ruleResolver1);
builder.build(ruleResolver2);
// Create a java_library() rule with no deps.
Path mainSrc = Paths.get("src/com/facebook/buck/cli/Main.java");
filesystem.mkdirs(mainSrc.getParent());
filesystem.writeContentsToPath("hello", mainSrc);
JavaLibraryBuilder javaLibraryBuilder = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//src/com/facebook/buck/cli:cli")).addSrc(mainSrc);
BuildRule libraryNoCommon = javaLibraryBuilder.build(ruleResolver1, filesystem);
// Create the same java_library() rule, but with a dep on //src/com/facebook/buck/cli:common.
javaLibraryBuilder.addDep(commonJavaLibrary.getBuildTarget());
BuildRule libraryWithCommon = javaLibraryBuilder.build(ruleResolver2, filesystem);
// Assert that the RuleKeys are distinct.
RuleKey r1 = ruleKeyFactory.build(libraryNoCommon);
RuleKey r2 = ruleKeyFactory2.build(libraryWithCommon);
assertThat("Rule keys should be distinct because the deps of the rules are different.", r1, not(equalTo(r2)));
}
use of com.facebook.buck.util.cache.FileHashCache 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.util.cache.FileHashCache in project buck by facebook.
the class RuleKeyTest method changingRuleKeyFieldOfDepChangesKeyWhenClassImplementsAppendToRuleKey.
@Test
public void changingRuleKeyFieldOfDepChangesKeyWhenClassImplementsAppendToRuleKey() {
BuildTarget target = BuildTargetFactory.newInstance("//cheese:peas");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(new FakeProjectFilesystem())));
BuildRule buildRule1 = new TestRuleKeyAppendableBuildRule(params, "foo", "bar");
BuildRule buildRule2 = new TestRuleKeyAppendableBuildRule(params, "foo", "xyzzy");
BuildTarget parentTarget = BuildTargetFactory.newInstance("//cheese:milk");
BuildRuleParams parentParams1 = new FakeBuildRuleParamsBuilder(parentTarget).setDeclaredDeps(ImmutableSortedSet.of(buildRule1)).build();
BuildRule parentRule1 = new NoopBuildRule(parentParams1);
BuildRuleParams parentParams2 = new FakeBuildRuleParamsBuilder(parentTarget).setDeclaredDeps(ImmutableSortedSet.of(buildRule2)).build();
BuildRule parentRule2 = new NoopBuildRule(parentParams2);
RuleKey ruleKey1 = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(parentRule1);
RuleKey ruleKey2 = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(parentRule2);
assertNotEquals(ruleKey1, ruleKey2);
}
use of com.facebook.buck.util.cache.FileHashCache 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()));
}
Aggregations