use of com.facebook.buck.rules.args.SanitizedArg in project buck by facebook.
the class CxxLinkTest method sanitizedPathsInFlagsDoNotAffectRuleKey.
@Test
public void sanitizedPathsInFlagsDoNotAffectRuleKey() {
SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
DefaultRuleKeyFactory ruleKeyFactory = new DefaultRuleKeyFactory(0, FakeFileHashCache.createFromStrings(ImmutableMap.of("ld", Strings.repeat("0", 40), "a.o", Strings.repeat("a", 40), "b.o", Strings.repeat("b", 40), "libc.a", Strings.repeat("c", 40), "different", Strings.repeat("d", 40))), pathResolver, ruleFinder);
// Set up a map to sanitize the differences in the flags.
int pathSize = 10;
DebugPathSanitizer sanitizer1 = new MungingDebugPathSanitizer(pathSize, File.separatorChar, Paths.get("PWD"), ImmutableBiMap.of(Paths.get("something"), Paths.get("A")));
DebugPathSanitizer sanitizer2 = new MungingDebugPathSanitizer(pathSize, File.separatorChar, Paths.get("PWD"), ImmutableBiMap.of(Paths.get("different"), Paths.get("A")));
// Generate a rule with a path we need to sanitize to a consistent value.
ImmutableList<Arg> args1 = ImmutableList.of(new SanitizedArg(sanitizer1.sanitize(Optional.empty()), "-Lsomething/foo"));
RuleKey ruleKey1 = ruleKeyFactory.build(new CxxLink(params, DEFAULT_LINKER, DEFAULT_OUTPUT, args1, Optional.empty(), /* cacheable */
true));
// Generate another rule with a different path we need to sanitize to the
// same consistent value as above.
ImmutableList<Arg> args2 = ImmutableList.of(new SanitizedArg(sanitizer2.sanitize(Optional.empty()), "-Ldifferent/foo"));
RuleKey ruleKey2 = ruleKeyFactory.build(new CxxLink(params, DEFAULT_LINKER, DEFAULT_OUTPUT, args2, Optional.empty(), /* cacheable */
true));
assertEquals(ruleKey1, ruleKey2);
}
Aggregations