use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class HeaderSymlinkTreeWithHeaderMapTest method testSymlinkTreeRuleKeyChangesIfLinkTargetsChange.
@Test
public void testSymlinkTreeRuleKeyChangesIfLinkTargetsChange() throws IOException {
ruleResolver.addToIndex(symlinkTreeBuildRule);
DefaultFileHashCache hashCache = DefaultFileHashCache.createDefaultFileHashCache(new ProjectFilesystem(tmpDir.getRoot()));
FileHashLoader hashLoader = new StackedFileHashCache(ImmutableList.of(hashCache));
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder);
// Calculate the rule key
RuleKey key1 = ruleKeyFactory.build(symlinkTreeBuildRule);
// Change the contents of the target of the link.
Path existingFile = resolver.getAbsolutePath(links.values().asList().get(0));
Files.write(existingFile, "something new".getBytes(Charsets.UTF_8));
hashCache.invalidateAll();
ruleKeyFactory = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder);
// Re-calculate the rule key
RuleKey key2 = ruleKeyFactory.build(symlinkTreeBuildRule);
// Verify that the rules keys are the same.
assertNotEquals(key1, key2);
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class ToolTest method shouldAssumeThatToolsInDifferentAbsoluteLocationsWithTheSameNameAreTheSame.
@Test
public void shouldAssumeThatToolsInDifferentAbsoluteLocationsWithTheSameNameAreTheSame() {
assumeTrue(Platform.detect() == Platform.MACOS || Platform.detect() == Platform.LINUX);
// Note: both file names are the same
HashedFileTool tool1 = new HashedFileTool(Paths.get("/usr/local/bin/python2.7"));
HashedFileTool tool2 = new HashedFileTool(Paths.get("/opt/bin/python2.7"));
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put("/usr/local/bin/python2.7", Strings.repeat("a", 40)).put("/opt/bin/python2.7", Strings.repeat("a", 40)).build()), pathResolver, ruleFinder);
RuleKey tool1RuleKey = createRuleKeyBuilder(ruleKeyFactory, pathResolver).setReflectively("tool", tool1).build().result;
RuleKey tool2RuleKey = createRuleKeyBuilder(ruleKeyFactory, pathResolver).setReflectively("tool", tool2).build().result;
assertEquals(tool1RuleKey, tool2RuleKey);
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class SanitizedArgTest method createRuleKeyBuilder.
private RuleKeyBuilder<RuleKey> createRuleKeyBuilder() {
FakeProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
FileHashCache fileHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(projectFilesystem)));
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
return new UncachedRuleKeyBuilder(ruleFinder, resolver, fileHashCache, new DefaultRuleKeyFactory(0, fileHashCache, resolver, ruleFinder));
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class SymlinkTreeTest method testSymlinkTreeDependentRuleKeyChangesWhenLinkSourceContentChanges.
@Test
public void testSymlinkTreeDependentRuleKeyChangesWhenLinkSourceContentChanges() throws Exception {
// If a dependent of a symlink tree uses the symlink tree's output as an input, that dependent's
// rulekey must change when the link contents change.
BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
ruleResolver.addToIndex(symlinkTreeBuildRule);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
Genrule genrule = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setSrcs(ImmutableList.of(symlinkTreeBuildRule.getSourcePathToOutput())).setOut("out").build(ruleResolver);
DefaultFileHashCache hashCache = DefaultFileHashCache.createDefaultFileHashCache(new ProjectFilesystem(tmpDir.getRoot()));
FileHashLoader hashLoader = new StackedFileHashCache(ImmutableList.of(hashCache));
RuleKey ruleKey1 = new DefaultRuleKeyFactory(0, hashLoader, pathResolver, ruleFinder).build(genrule);
Path existingFile = pathResolver.getAbsolutePath(links.values().asList().get(0));
Files.write(existingFile, "something new".getBytes(Charsets.UTF_8));
hashCache.invalidateAll();
RuleKey ruleKey2 = new DefaultRuleKeyFactory(0, hashLoader, pathResolver, ruleFinder).build(genrule);
// Verify that the rules keys are different.
assertNotEquals(ruleKey1, ruleKey2);
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class SymlinkTreeTest method testSymlinkTreeRuleKeyChangesIfLinkMapChanges.
@Test
public void testSymlinkTreeRuleKeyChangesIfLinkMapChanges() throws Exception {
// Create a BuildRule wrapping the stock SymlinkTree buildable.
//BuildRule rule1 = symlinkTreeBuildable;
// Also create a new BuildRule based around a SymlinkTree buildable with a different
// link map.
Path aFile = tmpDir.newFile();
Files.write(aFile, "hello world".getBytes(Charsets.UTF_8));
SymlinkTree modifiedSymlinkTreeBuildRule = new SymlinkTree(buildTarget, projectFilesystem, outputPath, ImmutableMap.of(Paths.get("different/link"), new PathSourcePath(projectFilesystem, MorePaths.relativize(tmpDir.getRoot(), aFile))), ruleFinder);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
// Calculate their rule keys and verify they're different.
DefaultFileHashCache hashCache = DefaultFileHashCache.createDefaultFileHashCache(new ProjectFilesystem(tmpDir.getRoot()));
FileHashLoader hashLoader = new StackedFileHashCache(ImmutableList.of(hashCache));
RuleKey key1 = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(symlinkTreeBuildRule);
RuleKey key2 = new DefaultRuleKeyFactory(0, hashLoader, resolver, ruleFinder).build(modifiedSymlinkTreeBuildRule);
assertNotEquals(key1, key2);
}
Aggregations