use of com.facebook.buck.rules.NoopBuildRule in project buck by facebook.
the class DefaultRuleKeyFactoryTest method testFactoryReportsInputsAndDependenciesToCacheForBuildRule.
@Test
public void testFactoryReportsInputsAndDependenciesToCacheForBuildRule() throws IOException {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
NoopRuleKeyCache<RuleKey> noopRuleKeyCache = new NoopRuleKeyCache<>();
ProjectFilesystem filesystem = new FakeProjectFilesystem();
DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(new RuleKeyFieldLoader(0), new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem))), pathResolver, ruleFinder, noopRuleKeyCache);
// Create a sample input.
PathSourcePath input = new PathSourcePath(filesystem, filesystem.getPath("input"));
filesystem.touch(input.getRelativePath());
// Create a sample dep rule.
BuildRule dep = new EmptyRule(BuildTargetFactory.newInstance("//:dep"));
// Create a sample rule key appendable.
RuleKeyAppendable appendable = sink -> {
};
// Create a dummy build rule that uses the input.
BuildRule rule = new NoopBuildRule(new FakeBuildRuleParamsBuilder("//:target").setProjectFilesystem(filesystem).setDeclaredDeps(ImmutableSortedSet.of(dep)).build()) {
@AddToRuleKey
private final SourcePath inputField = input;
@AddToRuleKey
private final RuleKeyAppendable appendableField = appendable;
};
// Build the rule key.
factory.build(rule);
// Verify the input was properly reported to the rule key cache.
RuleKeyResult<RuleKey> result = noopRuleKeyCache.results.get(rule);
assertThat(result, Matchers.notNullValue());
assertThat(result.inputs, Matchers.containsInAnyOrder(RuleKeyInput.of(filesystem, input.getRelativePath())));
assertThat(result.deps, Matchers.containsInAnyOrder(dep, appendable));
}
use of com.facebook.buck.rules.NoopBuildRule 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.NoopBuildRule in project buck by facebook.
the class InputBasedRuleKeyFactoryTest method nestedSizeLimitExceptionHandled.
@Test
public void nestedSizeLimitExceptionHandled() throws Exception {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(0);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
final FakeProjectFilesystem filesystem = new FakeProjectFilesystem();
FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(filesystem)));
Path inputFile = filesystem.getPath("input");
filesystem.writeBytesToPath(new byte[1024], inputFile);
BuildRuleParams params = new FakeBuildRuleParamsBuilder("//:rule").setProjectFilesystem(filesystem).build();
BuildRule rule = new NoopBuildRule(params) {
@AddToRuleKey
NestedRuleKeyAppendableWithInput input = new NestedRuleKeyAppendableWithInput(new PathSourcePath(filesystem, inputFile));
};
// Verify rule key isn't calculated.
expectedException.expect(SizeLimiter.SizeLimitException.class);
new InputBasedRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder, 200).build(rule);
}
Aggregations