use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class RuleKeyBuilderTest method testNoOp.
@Test
public void testNoOp() {
RuleKey noop = newBuilder().build();
assertEquals(noop, calcRuleKey("key", ImmutableList.of()));
assertEquals(noop, calcRuleKey("key", ImmutableList.of().iterator()));
assertEquals(noop, calcRuleKey("key", ImmutableMap.of()));
assertEquals(noop, calcRuleKey("key", ImmutableList.of(IGNORED_RULE)));
assertEquals(noop, calcRuleKey("key", Suppliers.ofInstance(IGNORED_RULE)));
assertEquals(noop, calcRuleKey("key", Optional.of(IGNORED_RULE)));
assertEquals(noop, calcRuleKey("key", Either.ofLeft(IGNORED_RULE)));
assertEquals(noop, calcRuleKey("key", Either.ofRight(IGNORED_RULE)));
assertEquals(noop, calcRuleKey("key", IGNORED_RULE));
assertEquals(noop, calcRuleKey("key", IGNORED_APPENDABLE));
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class RuleKeyBuilderTest method newBuilder.
private RuleKeyBuilder<RuleKey> newBuilder() {
Map<BuildTarget, BuildRule> ruleMap = ImmutableMap.of(TARGET_1, RULE_1, TARGET_2, RULE_2);
Map<BuildRule, RuleKey> ruleKeyMap = ImmutableMap.of(RULE_1, RULE_KEY_1, RULE_2, RULE_KEY_2);
Map<RuleKeyAppendable, RuleKey> appendableKeys = ImmutableMap.of(APPENDABLE_1, RULE_KEY_1, APPENDABLE_2, RULE_KEY_2);
BuildRuleResolver ruleResolver = new FakeBuildRuleResolver(ruleMap);
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
FakeFileHashCache hashCache = new FakeFileHashCache(ImmutableMap.of(FILESYSTEM.resolve(PATH_1), HashCode.fromInt(0), FILESYSTEM.resolve(PATH_2), HashCode.fromInt(42)), ImmutableMap.of(pathResolver.getAbsoluteArchiveMemberPath(ARCHIVE_PATH_1), HashCode.fromInt(0), pathResolver.getAbsoluteArchiveMemberPath(ARCHIVE_PATH_2), HashCode.fromInt(42)), ImmutableMap.of());
RuleKeyHasher<HashCode> hasher = new GuavaRuleKeyHasher(Hashing.sha1().newHasher());
return new RuleKeyBuilder<RuleKey>(ruleFinder, pathResolver, hashCache, hasher) {
@Override
protected RuleKeyBuilder<RuleKey> setBuildRule(BuildRule rule) {
if (rule == IGNORED_RULE) {
return this;
}
return setBuildRuleKey(ruleKeyMap.get(rule));
}
@Override
public RuleKeyBuilder<RuleKey> setAppendableRuleKey(RuleKeyAppendable appendable) {
if (appendable == IGNORED_APPENDABLE) {
return this;
}
return setAppendableRuleKey(appendableKeys.get(appendable));
}
@Override
protected RuleKeyBuilder<RuleKey> setSourcePath(SourcePath sourcePath) throws IOException {
if (sourcePath instanceof BuildTargetSourcePath) {
return setSourcePathAsRule((BuildTargetSourcePath<?>) sourcePath);
} else {
return setSourcePathDirectly(sourcePath);
}
}
@Override
protected RuleKeyBuilder<RuleKey> setNonHashingSourcePath(SourcePath sourcePath) {
return setNonHashingSourcePathDirectly(sourcePath);
}
@Override
public RuleKey build() {
return buildRuleKey();
}
};
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class FakeInputBasedRuleKeyFactory 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 RuleKeyBuilder<RuleKey>(ruleFinder, resolver, fileHashCache) {
@Override
protected RuleKeyBuilder<RuleKey> setBuildRule(BuildRule rule) {
return this;
}
@Override
protected RuleKeyBuilder<RuleKey> setReflectively(@Nullable Object val) {
return this;
}
@Override
public RuleKeyBuilder<RuleKey> setAppendableRuleKey(RuleKeyAppendable appendable) {
return this;
}
@Override
protected RuleKeyBuilder<RuleKey> setSourcePath(SourcePath sourcePath) {
return this;
}
@Override
protected RuleKeyBuilder<RuleKey> setNonHashingSourcePath(SourcePath sourcePath) {
return setNonHashingSourcePathDirectly(sourcePath);
}
@Override
public RuleKey build() {
if (oversized.contains(buildRule.getBuildTarget())) {
throw new SizeLimiter.SizeLimitException();
}
return ruleKeys.get(buildRule.getBuildTarget());
}
};
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class DefaultRuleKeyFactoryTest method fieldsFromParentClassesShouldBeAddedAndFieldsRetainOverallAlphabeticalOrdering.
@Test
public void fieldsFromParentClassesShouldBeAddedAndFieldsRetainOverallAlphabeticalOrdering() {
BuildTarget topLevelTarget = BuildTargetFactory.newInstance("//cheese:peas");
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildRule rule = new EmptyRule(topLevelTarget);
DefaultRuleKeyFactory factory = new DefaultRuleKeyFactory(0, new NullFileHashCache(), pathResolver, ruleFinder);
RuleKeyBuilder<RuleKeyResult<RuleKey>> builder = factory.newBuilderForTesting(rule);
builder.setReflectively("exoticCheese", "bavarian smoked");
builder.setReflectively("target", topLevelTarget);
RuleKey expected = builder.build().result;
class Parent extends EmptyRule {
@AddToRuleKey
private BuildTarget target;
public Parent(BuildTarget target) {
super(target);
this.target = target;
}
}
class Child extends Parent {
@AddToRuleKey
private String exoticCheese = "bavarian smoked";
public Child(BuildTarget target) {
super(target);
}
}
RuleKey seen = factory.build(new Child(topLevelTarget));
assertEquals(expected, seen);
}
use of com.facebook.buck.rules.RuleKey in project buck by facebook.
the class DefaultRuleKeyFactoryTest method testBothKeysAndValuesGetHashed.
@Test
public void testBothKeysAndValuesGetHashed() {
assertKeysGetHashed(null);
assertBothKeysAndValuesGetHashed(true, false);
assertBothKeysAndValuesGetHashed((double) 123, (double) 42);
assertBothKeysAndValuesGetHashed((float) 123, (float) 42);
// (int)
assertBothKeysAndValuesGetHashed(123, 42);
assertBothKeysAndValuesGetHashed((long) 123, (long) 42);
assertBothKeysAndValuesGetHashed((short) 123, (short) 42);
assertBothKeysAndValuesGetHashed((byte) 123, (byte) 42);
assertBothKeysAndValuesGetHashed(new byte[] { 1, 2, 3 }, new byte[] { 4, 2 });
assertBothKeysAndValuesGetHashed(DummyEnum.BLACK, DummyEnum.WHITE);
assertBothKeysAndValuesGetHashed("abc", "def");
assertBothKeysAndValuesGetHashed(Pattern.compile("regex1"), Pattern.compile("regex2"));
assertBothKeysAndValuesGetHashed(Sha1HashCode.of("a002b39af204cdfaa5fdb67816b13867c32ac52c"), Sha1HashCode.of("b67816b13867c32ac52ca002b39af204cdfaa5fd"));
assertBothKeysAndValuesGetHashed(new RuleKey("a002b39af204cdfaa5fdb67816b13867c32ac52c"), new RuleKey("b67816b13867c32ac52ca002b39af204cdfaa5fd"));
assertBothKeysAndValuesGetHashed(BuildRuleType.of("rule_type"), BuildRuleType.of("type2"));
assertBothKeysAndValuesGetHashed(BuildTargetFactory.newInstance(Paths.get("/root"), "//example/base:one"), BuildTargetFactory.newInstance(Paths.get("/root"), "//example/base:two"));
assertBothKeysAndValuesGetHashed(new SourceRoot("root1"), new SourceRoot("root2"));
// wrapper types
assertBothKeysAndValuesGetHashed(Optional.of("abc"), Optional.of("def"));
assertBothKeysAndValuesGetHashed(Either.ofLeft("abc"), Either.ofLeft("def"));
assertBothKeysAndValuesGetHashed(Either.ofRight("def"), Either.ofRight("ghi"));
assertBothKeysAndValuesGetHashed(Suppliers.ofInstance("abc"), Suppliers.ofInstance("def"));
// iterables & maps
assertBothKeysAndValuesGetHashed(Arrays.asList(1, 2, 3), Arrays.asList(4, 2));
assertBothKeysAndValuesGetHashed(ImmutableList.of("abc", "xy"), ImmutableList.of("xy", "abc"));
assertBothKeysAndValuesGetHashed(ImmutableMap.of("key", "v1"), ImmutableMap.of("key", "v2"));
// nested
assertBothKeysAndValuesGetHashed(ImmutableMap.of("key", Optional.of(ImmutableList.of(1, 2, 3))), ImmutableMap.of("key", Optional.of(ImmutableList.of(1, 2, 4))));
}
Aggregations