use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyChangesIfInputContentsFromPathSourceChanges.
@Test
public void ruleKeyChangesIfInputContentsFromPathSourceChanges() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
Path output = Paths.get("output");
BuildRule rule = ExportFileBuilder.newExportFileBuilder(BuildTargetFactory.newInstance("//:rule")).setOut("out").setSrc(new PathSourcePath(filesystem, output)).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(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)));
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method ruleKeyChangesIfInputContentsFromBuildTargetSourcePathInRuleKeyAppendableChanges.
@Test
public void ruleKeyChangesIfInputContentsFromBuildTargetSourcePathInRuleKeyAppendableChanges() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
final FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
final BuildRule dep = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep")).setOut("out").build(resolver, filesystem);
BuildRuleParams params = new FakeBuildRuleParamsBuilder("//:rule").setDeclaredDeps(ImmutableSortedSet.of(dep)).setProjectFilesystem(filesystem).build();
BuildRule rule = new NoopBuildRule(params) {
@AddToRuleKey
RuleKeyAppendableWithInput input = new RuleKeyAppendableWithInput(dep.getSourcePathToOutput());
};
// 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.rules.RuleKey in project buck by facebook.
the class FakeRuleKeyFactory method newInstance.
private RuleKeyBuilder<RuleKey> newInstance(final BuildRule buildRule) {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
return new UncachedRuleKeyBuilder(ruleFinder, resolver, fileHashCache, this) {
@Override
protected RuleKeyBuilder<RuleKey> setReflectively(@Nullable Object val) {
return this;
}
@Override
public RuleKey build() {
return ruleKeys.get(buildRule.getBuildTarget());
}
};
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class UncachedRuleKeyBuilder method setAppendableRuleKey.
@Override
protected UncachedRuleKeyBuilder setAppendableRuleKey(RuleKeyAppendable appendable) {
RuleKeyBuilder<RuleKey> subKeyBuilder = subKeySupplier.get();
appendable.appendToRuleKey(subKeyBuilder);
RuleKey subKey = subKeyBuilder.build();
setAppendableRuleKey(subKey);
return this;
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class ContentAgnosticRuleKeyFactoryTest method ruleKeyDoesChangeWithFileRename.
@Test
public void ruleKeyDoesChangeWithFileRename() throws Exception {
ProjectFilesystem filesystem = new FakeProjectFilesystem();
// A file rename should alter the rulekey.
RuleKey ruleKey1 = createRuleKey(filesystem, "output_file", "contents");
RuleKey ruleKey2 = createRuleKey(filesystem, "output_file_2", "diff_contents");
assertThat(ruleKey1, Matchers.not(Matchers.equalTo(ruleKey2)));
}
Aggregations