Search in sources :

Example 1 with SanitizedArg

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);
}
Also used : DefaultRuleKeyFactory(com.facebook.buck.rules.keys.DefaultRuleKeyFactory) RuleKey(com.facebook.buck.rules.RuleKey) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) SourcePathArg(com.facebook.buck.rules.args.SourcePathArg) StringArg(com.facebook.buck.rules.args.StringArg) SanitizedArg(com.facebook.buck.rules.args.SanitizedArg) Arg(com.facebook.buck.rules.args.Arg) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SanitizedArg(com.facebook.buck.rules.args.SanitizedArg) Test(org.junit.Test)

Aggregations

BuildTarget (com.facebook.buck.model.BuildTarget)1 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)1 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)1 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)1 RuleKey (com.facebook.buck.rules.RuleKey)1 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)1 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)1 Arg (com.facebook.buck.rules.args.Arg)1 SanitizedArg (com.facebook.buck.rules.args.SanitizedArg)1 SourcePathArg (com.facebook.buck.rules.args.SourcePathArg)1 StringArg (com.facebook.buck.rules.args.StringArg)1 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)1 Test (org.junit.Test)1