use of com.facebook.buck.rules.keys.InputBasedRuleKeyFactory in project buck by facebook.
the class SymlinkTreeTest method testSymlinkTreeRuleKeyDoesNotChangeIfLinkTargetsChangeOnUnix.
@Test
public void testSymlinkTreeRuleKeyDoesNotChangeIfLinkTargetsChangeOnUnix() throws IOException {
ruleResolver.addToIndex(symlinkTreeBuildRule);
InputBasedRuleKeyFactory ruleKeyFactory = new InputBasedRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.of()), pathResolver, ruleFinder);
// Calculate the rule key
RuleKey key1 = ruleKeyFactory.build(symlinkTreeBuildRule);
// Change the contents of the target of the link.
Path existingFile = pathResolver.getAbsolutePath(links.values().asList().get(0));
Files.write(existingFile, "something new".getBytes(Charsets.UTF_8));
// Re-calculate the rule key
RuleKey key2 = ruleKeyFactory.build(symlinkTreeBuildRule);
// Verify that the rules keys are the same.
assertEquals(key1, key2);
}
use of com.facebook.buck.rules.keys.InputBasedRuleKeyFactory in project buck by facebook.
the class GenruleTest method inputBasedRuleKeyExecutableMacro.
@Test
public void inputBasedRuleKeyExecutableMacro() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
GenruleBuilder ruleBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setCmd("run $(exe //:dep)").setOut("output");
// Create an initial input-based rule key
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRule dep = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:dep")).setMain(new PathSourcePath(filesystem, Paths.get("dep.exe"))).build(resolver, filesystem);
filesystem.writeContentsToPath("something", Paths.get("dep.exe"));
filesystem.writeContentsToPath("something", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
BuildRule rule = ruleBuilder.build(resolver);
DefaultRuleKeyFactory defaultRuleKeyFactory = new DefaultRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
InputBasedRuleKeyFactory inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
RuleKey originalRuleKey = defaultRuleKeyFactory.build(rule);
RuleKey originalInputRuleKey = inputBasedRuleKeyFactory.build(rule);
// Change the dep's resource list, which will change its normal rule key, but since we're
// keeping its output the same, the input-based rule key for the consuming rule will stay the
// same. This is because the input-based rule key for the consuming rule only cares about the
// contents of the output this rule produces.
resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
Genrule extra = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:extra")).setOut("something").build(resolver);
new ShBinaryBuilder(BuildTargetFactory.newInstance("//:dep")).setMain(new PathSourcePath(filesystem, Paths.get("dep.exe"))).setDeps(ImmutableSortedSet.of(extra.getBuildTarget())).build(resolver, filesystem);
rule = ruleBuilder.build(resolver);
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
defaultRuleKeyFactory = new DefaultRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
RuleKey unchangedRuleKey = defaultRuleKeyFactory.build(rule);
RuleKey unchangedInputBasedRuleKey = inputBasedRuleKeyFactory.build(rule);
assertThat(unchangedRuleKey, Matchers.not(Matchers.equalTo(originalRuleKey)));
assertThat(unchangedInputBasedRuleKey, Matchers.equalTo(originalInputRuleKey));
// Make a change to the dep's output, which *should* affect the input-based rule key.
resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
dep = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:dep")).setMain(new PathSourcePath(filesystem, Paths.get("dep.exe"))).build(resolver, filesystem);
filesystem.writeContentsToPath("something else", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
rule = ruleBuilder.build(resolver);
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
RuleKey changedInputBasedRuleKey = inputBasedRuleKeyFactory.build(rule);
assertThat(changedInputBasedRuleKey, Matchers.not(Matchers.equalTo(originalInputRuleKey)));
}
use of com.facebook.buck.rules.keys.InputBasedRuleKeyFactory in project buck by facebook.
the class GenruleTest method inputBasedRuleKeyClasspathMacro.
@Test
public void inputBasedRuleKeyClasspathMacro() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
GenruleBuilder ruleBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setCmd("run $(classpath //:dep)").setOut("output");
// Create an initial input-based rule key
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
JavaLibrary dep = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep")).addSrc(Paths.get("source.java")).build(resolver, filesystem);
filesystem.writeContentsToPath("something", Paths.get("source.java"));
filesystem.writeContentsToPath("something", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
BuildRule rule = ruleBuilder.build(resolver);
DefaultRuleKeyFactory defaultRuleKeyFactory = new DefaultRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
InputBasedRuleKeyFactory inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
RuleKey originalRuleKey = defaultRuleKeyFactory.build(rule);
RuleKey originalInputRuleKey = inputBasedRuleKeyFactory.build(rule);
// Change the dep's resource root, which will change its normal rule key, but since we're
// keeping its output JAR the same, the input-based rule key for the consuming rule will stay
// the same. This is because the input-based rule key for the consuming rule only cares about
// the contents of the output this rule produces.
resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep")).addSrc(Paths.get("source.java")).setResourcesRoot(Paths.get("resource_root")).build(resolver, filesystem);
rule = ruleBuilder.build(resolver);
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
defaultRuleKeyFactory = new DefaultRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
RuleKey unchangedRuleKey = defaultRuleKeyFactory.build(rule);
RuleKey unchangedInputBasedRuleKey = inputBasedRuleKeyFactory.build(rule);
assertThat(unchangedRuleKey, Matchers.not(Matchers.equalTo(originalRuleKey)));
assertThat(unchangedInputBasedRuleKey, Matchers.equalTo(originalInputRuleKey));
// Make a change to the dep's output, which *should* affect the input-based rule key.
resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
dep = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep")).addSrc(Paths.get("source.java")).build(resolver, filesystem);
filesystem.writeContentsToPath("something else", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
rule = ruleBuilder.build(resolver);
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
inputBasedRuleKeyFactory = new InputBasedRuleKeyFactory(0, new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder);
RuleKey changedInputBasedRuleKey = inputBasedRuleKeyFactory.build(rule);
assertThat(changedInputBasedRuleKey, Matchers.not(Matchers.equalTo(originalInputRuleKey)));
}
use of com.facebook.buck.rules.keys.InputBasedRuleKeyFactory in project buck by facebook.
the class HeaderSymlinkTreeWithHeaderMapTest method testSymlinkTreeInputBasedRuleKeyDoesNotChangeIfLinkTargetsChange.
@Test
public void testSymlinkTreeInputBasedRuleKeyDoesNotChangeIfLinkTargetsChange() throws IOException {
ruleResolver.addToIndex(symlinkTreeBuildRule);
InputBasedRuleKeyFactory ruleKeyFactory = new InputBasedRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.of()), 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));
ruleKeyFactory = new InputBasedRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.of()), resolver, ruleFinder);
// Re-calculate the rule key
RuleKey key2 = ruleKeyFactory.build(symlinkTreeBuildRule);
// Verify that the rules keys are the same.
assertEquals(key1, key2);
}
use of com.facebook.buck.rules.keys.InputBasedRuleKeyFactory in project buck by facebook.
the class DefaultJavaLibraryTest method testInputBasedRuleKeyWithJavaLibraryDep.
/**
* Tests that input-based rule keys work properly with simple Java library deps.
*/
@Test
public void testInputBasedRuleKeyWithJavaLibraryDep() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
// Setup a Java library which builds against another Java library dep.
TargetNode<JavaLibraryDescription.Arg, ?> depNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep"), filesystem).addSrc(Paths.get("Source.java")).build();
TargetNode<?, ?> libraryNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:lib"), filesystem).addDep(depNode.getBuildTarget()).build();
TargetGraph targetGraph = TargetGraphFactory.newInstance(depNode, libraryNode);
ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
JavaLibrary dep = (JavaLibrary) ruleResolver.requireRule(depNode.getBuildTarget());
JavaLibrary library = (JavaLibrary) ruleResolver.requireRule(libraryNode.getBuildTarget());
filesystem.writeContentsToPath("JAR contents", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
writeAbiJar(filesystem, pathResolver.getRelativePath(ruleResolver.requireRule(dep.getAbiJar().get()).getSourcePathToOutput()), "Source.class", "ABI JAR contents");
FileHashCache originalHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
InputBasedRuleKeyFactory factory = new InputBasedRuleKeyFactory(0, originalHashCache, pathResolver, ruleFinder);
RuleKey originalRuleKey = factory.build(library);
// Now change the Java library dependency such that its rule key changes, and change its JAR
// contents, but keep its ABI JAR the same. This should *not* affect the input-based rule key
// of the consuming java library, since it only cares about the contents of the ABI JAR.
depNode = JavaLibraryBuilder.createBuilder(BuildTargetFactory.newInstance("//:dep")).addSrc(Paths.get("Source.java")).setResourcesRoot(Paths.get("some root that changes the rule key")).build();
targetGraph = TargetGraphFactory.newInstance(depNode, libraryNode);
ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
ruleFinder = new SourcePathRuleFinder(ruleResolver);
pathResolver = new SourcePathResolver(ruleFinder);
dep = (JavaLibrary) ruleResolver.requireRule(depNode.getBuildTarget());
library = (JavaLibrary) ruleResolver.requireRule(libraryNode.getBuildTarget());
filesystem.writeContentsToPath("different JAR contents", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
FileHashCache unaffectedHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
factory = new InputBasedRuleKeyFactory(0, unaffectedHashCache, pathResolver, ruleFinder);
RuleKey unaffectedRuleKey = factory.build(library);
assertThat(originalRuleKey, equalTo(unaffectedRuleKey));
// Now actually change the Java library dependency's ABI JAR. This *should* affect the
// input-based rule key of the consuming java library.
ruleResolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
ruleFinder = new SourcePathRuleFinder(ruleResolver);
pathResolver = new SourcePathResolver(ruleFinder);
dep = (JavaLibrary) ruleResolver.requireRule(depNode.getBuildTarget());
library = (JavaLibrary) ruleResolver.requireRule(libraryNode.getBuildTarget());
writeAbiJar(filesystem, pathResolver.getRelativePath(ruleResolver.requireRule(dep.getAbiJar().get()).getSourcePathToOutput()), "Source.class", "changed ABI JAR contents");
FileHashCache affectedHashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
factory = new InputBasedRuleKeyFactory(0, affectedHashCache, pathResolver, ruleFinder);
RuleKey affectedRuleKey = factory.build(library);
assertThat(originalRuleKey, Matchers.not(equalTo(affectedRuleKey)));
}
Aggregations