use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class RuleKeyTest method differentSeedsMakeDifferentKeys.
@Test
public void differentSeedsMakeDifferentKeys() {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver resolver = new SourcePathResolver(ruleFinder);
BuildTarget buildTarget = BuildTargetFactory.newInstance("//some:example");
BuildRule buildRule = new FakeBuildRule(buildTarget, resolver);
RuleKey empty1 = new DefaultRuleKeyFactory(0, new NullFileHashCache(), resolver, ruleFinder).build(buildRule);
RuleKey empty2 = new DefaultRuleKeyFactory(0, new NullFileHashCache(), resolver, ruleFinder).build(buildRule);
RuleKey empty3 = new DefaultRuleKeyFactory(1, new NullFileHashCache(), resolver, ruleFinder).build(buildRule);
assertThat(empty1, is(equalTo(empty2)));
assertThat(empty1, is(not(equalTo(empty3))));
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class RuleKeyTest method changingRuleKeyFieldChangesKeyWhenClassImplementsAppendToRuleKey.
@Test
public void changingRuleKeyFieldChangesKeyWhenClassImplementsAppendToRuleKey() {
BuildTarget target = BuildTargetFactory.newInstance("//cheese:peas");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FileHashCache hashCache = new StackedFileHashCache(ImmutableList.of(DefaultFileHashCache.createDefaultFileHashCache(new FakeProjectFilesystem())));
BuildRule buildRule1 = new TestRuleKeyAppendableBuildRule(params, "foo", "bar");
BuildRule buildRule2 = new TestRuleKeyAppendableBuildRule(params, "foo", "xyzzy");
RuleKey ruleKey1 = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(buildRule1);
RuleKey ruleKey2 = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder).build(buildRule2);
assertNotEquals(ruleKey1, ruleKey2);
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class RuleKeyTest method createEmptyRuleKey.
private RuleKeyBuilder<RuleKeyResult<RuleKey>> createEmptyRuleKey(SourcePathResolver resolver, SourcePathRuleFinder ruleFinder) {
FileHashCache fileHashCache = new FileHashCache() {
@Override
public void invalidate(Path path) {
}
@Override
public void invalidateAll() {
}
@Override
public HashCode get(Path path) {
return HashCode.fromString("deadbeef");
}
@Override
public HashCode get(ArchiveMemberPath archiveMemberPath) {
return HashCode.fromString("deadbeef");
}
@Override
public long getSize(Path path) {
return 0;
}
@Override
public void set(Path path, HashCode hashCode) {
}
};
BuildTarget buildTarget = BuildTargetFactory.newInstance("//some:example");
BuildRule buildRule = new FakeBuildRule(buildTarget, resolver);
return new DefaultRuleKeyFactory(0, fileHashCache, resolver, ruleFinder).newBuilderForTesting(buildRule);
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class RuleKeyTest method subclassWithNoopSetter.
@Test
public void subclassWithNoopSetter() {
class NoopSetterRuleKeyBuilder extends UncachedRuleKeyBuilder {
public NoopSetterRuleKeyBuilder(SourcePathRuleFinder ruleFinder, SourcePathResolver pathResolver, FileHashCache hashCache, RuleKeyFactory<RuleKey> defaultRuleKeyFactory) {
super(ruleFinder, pathResolver, hashCache, defaultRuleKeyFactory);
}
@Override
protected NoopSetterRuleKeyBuilder setSourcePath(SourcePath sourcePath) {
return this;
}
}
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of());
RuleKeyFactory<RuleKey> ruleKeyFactory = new DefaultRuleKeyFactory(0, hashCache, pathResolver, ruleFinder);
RuleKey nullRuleKey = new NoopSetterRuleKeyBuilder(ruleFinder, pathResolver, hashCache, ruleKeyFactory).build();
RuleKey noopRuleKey = new NoopSetterRuleKeyBuilder(ruleFinder, pathResolver, hashCache, ruleKeyFactory).setReflectively("key", new FakeSourcePath("value")).build();
assertThat(noopRuleKey, is(equalTo(nullRuleKey)));
}
use of com.facebook.buck.rules.keys.DefaultRuleKeyFactory in project buck by facebook.
the class AppleCxxPlatformsTest method constructLinkRuleKeys.
// Create and return some rule keys from a dummy source for the given platforms.
private ImmutableMap<Flavor, RuleKey> constructLinkRuleKeys(ImmutableMap<Flavor, AppleCxxPlatform> cxxPlatforms) throws NoSuchBuildTargetException {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(resolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.<String, String>builder().put("input.o", Strings.repeat("a", 40)).build()), pathResolver, ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//:target");
ImmutableMap.Builder<Flavor, RuleKey> ruleKeys = ImmutableMap.builder();
for (Map.Entry<Flavor, AppleCxxPlatform> entry : cxxPlatforms.entrySet()) {
BuildRule rule = CxxLinkableEnhancer.createCxxLinkableBuildRule(CxxPlatformUtils.DEFAULT_CONFIG, entry.getValue().getCxxPlatform(), new FakeBuildRuleParamsBuilder(target).build(), resolver, pathResolver, ruleFinder, target, Linker.LinkType.EXECUTABLE, Optional.empty(), Paths.get("output"), Linker.LinkableDepType.SHARED, ImmutableList.of(), Optional.empty(), Optional.empty(), ImmutableSet.of(), NativeLinkableInput.builder().setArgs(SourcePathArg.from(new FakeSourcePath("input.o"))).build());
ruleKeys.put(entry.getKey(), ruleKeyFactory.build(rule));
}
return ruleKeys.build();
}
Aggregations