use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class PrebuiltJarSymbolsFinderTest method generatedBinaryJarShouldNotAffectRuleKey.
@Test
public void generatedBinaryJarShouldNotAffectRuleKey() {
SourcePathResolver pathResolver = null;
SourcePathRuleFinder ruleFinder = null;
Path jarFile = tmp.getRoot().resolve("common.jar");
Map<Path, HashCode> pathsToHashes = ImmutableMap.of(jarFile, HashCode.fromString(Strings.repeat("abcd", 10)));
FakeFileHashCache fileHashCache = new FakeFileHashCache(pathsToHashes);
JavaSymbolsRule javaSymbolsRule1 = new JavaSymbolsRule(BuildTargetFactory.newInstance("//foo:rule"), createFinderForGeneratedJar("//foo:jar_genrule1"), /* generatedSymbols */
ImmutableSortedSet.of(), ObjectMappers.newDefaultInstance(), new ProjectFilesystem(tmp.getRoot()));
RuleKey key1 = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder).build(javaSymbolsRule1);
JavaSymbolsRule javaSymbolsRule2 = new JavaSymbolsRule(BuildTargetFactory.newInstance("//foo:rule"), createFinderForGeneratedJar("//foo:jar_genrule2"), /* generatedSymbols */
ImmutableSortedSet.of(), ObjectMappers.newDefaultInstance(), new ProjectFilesystem(tmp.getRoot()));
RuleKey key2 = new DefaultRuleKeyFactory(0, fileHashCache, pathResolver, ruleFinder).build(javaSymbolsRule2);
assertNotNull(key1);
assertNotNull(key2);
assertEquals("Keys should match even though different BuildTargetSourcePaths are used.", key1, key2);
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class GenruleTest method inputBasedRuleKeyLocationMacro.
@Test
public void inputBasedRuleKeyLocationMacro() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
GenruleBuilder ruleBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:rule")).setCmd("run $(location //: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 = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("dep.out").setCmd("something").build(resolver);
filesystem.writeContentsToPath("something", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
BuildRule rule = ruleBuilder.build(resolver);
DefaultRuleKeyFactory ruleKeyFactory = 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 = ruleKeyFactory.build(rule);
RuleKey originalInputRuleKey = inputBasedRuleKeyFactory.build(rule);
// Change the genrule's command, 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());
GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("dep.out").setCmd("something else").build(resolver);
rule = ruleBuilder.build(resolver);
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
ruleKeyFactory = 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 = ruleKeyFactory.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());
ruleFinder = new SourcePathRuleFinder(resolver);
pathResolver = new SourcePathResolver(ruleFinder);
dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("dep.out").setCmd("something").build(resolver);
filesystem.writeContentsToPath("something else", pathResolver.getRelativePath(dep.getSourcePathToOutput()));
rule = ruleBuilder.build(resolver);
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.DefaultRuleKeyFactory in project buck by facebook.
the class ExportFileTest method modifyingTheContentsOfTheFileChangesTheRuleKey.
@Test
public void modifyingTheContentsOfTheFileChangesTheRuleKey() throws Exception {
Path root = Files.createTempDirectory("root");
FakeProjectFilesystem filesystem = new FakeProjectFilesystem(root);
Path temp = Paths.get("example_file");
FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder);
filesystem.writeContentsToPath("I like cheese", temp);
ExportFileBuilder builder = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//some:file")).setSrc(new PathSourcePath(filesystem, temp));
ExportFile rule = builder.build(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()), filesystem);
RuleKey original = ruleKeyFactory.build(rule);
filesystem.writeContentsToPath("I really like cheese", temp);
// Create a new rule. The FileHashCache held by the existing rule will retain a reference to the
// previous content of the file, so we need to create an identical rule.
rule = builder.build(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()), filesystem);
hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
resolver = new SourcePathResolver(ruleFinder);
ruleKeyFactory = new DefaultRuleKeyFactory(0, hashCache, resolver, ruleFinder);
RuleKey refreshed = ruleKeyFactory.build(rule);
assertNotEquals(original, refreshed);
}
Aggregations