コード例 #1
0
  @Test
  public void sanitizedPathsInFlagsDoNotAffectRuleKey() {
    SourcePathResolver pathResolver =
        new SourcePathResolver(
            new BuildRuleResolver(TargetGraph.EMPTY, new BuildTargetNodeToBuildRuleTransformer()));
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
    RuleKeyBuilderFactory ruleKeyBuilderFactory =
        new DefaultRuleKeyBuilderFactory(
            FakeFileHashCache.createFromStrings(
                ImmutableMap.<String, String>builder()
                    .put("preprocessor", Strings.repeat("a", 40))
                    .put("compiler", Strings.repeat("a", 40))
                    .put("test.o", Strings.repeat("b", 40))
                    .put("test.cpp", Strings.repeat("c", 40))
                    .put("different", Strings.repeat("d", 40))
                    .put("foo/test.h", Strings.repeat("e", 40))
                    .put("path/to/a/plugin.so", Strings.repeat("f", 40))
                    .put("path/to/a/different/plugin.so", Strings.repeat("a0", 40))
                    .build()),
            pathResolver);

    // Set up a map to sanitize the differences in the flags.
    int pathSize = 10;
    DebugPathSanitizer sanitizer1 =
        new DebugPathSanitizer(
            pathSize,
            File.separatorChar,
            Paths.get("PWD"),
            ImmutableBiMap.of(Paths.get("something"), Paths.get("A")));
    DebugPathSanitizer sanitizer2 =
        new DebugPathSanitizer(
            pathSize,
            File.separatorChar,
            Paths.get("PWD"),
            ImmutableBiMap.of(Paths.get("different"), Paths.get("A")));

    // Generate a rule key for the defaults.
    ImmutableList<String> platformFlags1 = ImmutableList.of("-Isomething/foo");
    ImmutableList<String> ruleFlags1 = ImmutableList.of("-Isomething/bar");

    RuleKey ruleKey1 =
        ruleKeyBuilderFactory.build(
            CxxPreprocessAndCompile.preprocess(
                params,
                pathResolver,
                new PreprocessorDelegate(
                    pathResolver,
                    sanitizer1,
                    DEFAULT_WORKING_DIR,
                    DEFAULT_PREPROCESSOR,
                    platformFlags1,
                    ruleFlags1,
                    DEFAULT_INCLUDE_ROOTS,
                    DEFAULT_SYSTEM_INCLUDE_ROOTS,
                    DEFAULT_HEADER_MAPS,
                    DEFAULT_FRAMEWORK_ROOTS,
                    DEFAULT_FRAMEWORK_PATH_SEARCH_PATH_FUNCTION,
                    Optional.<SourcePath>absent(),
                    DEFAULT_INCLUDES),
                DEFAULT_OUTPUT,
                DEFAULT_INPUT,
                DEFAULT_INPUT_TYPE,
                sanitizer1));

    // Generate a rule key for the defaults.
    ImmutableList<String> platformFlags2 = ImmutableList.of("-Idifferent/foo");
    ImmutableList<String> ruleFlags2 = ImmutableList.of("-Idifferent/bar");

    RuleKey ruleKey2 =
        ruleKeyBuilderFactory.build(
            CxxPreprocessAndCompile.preprocess(
                params,
                pathResolver,
                new PreprocessorDelegate(
                    pathResolver,
                    sanitizer2,
                    DEFAULT_WORKING_DIR,
                    DEFAULT_PREPROCESSOR,
                    platformFlags2,
                    ruleFlags2,
                    DEFAULT_INCLUDE_ROOTS,
                    DEFAULT_SYSTEM_INCLUDE_ROOTS,
                    DEFAULT_HEADER_MAPS,
                    DEFAULT_FRAMEWORK_ROOTS,
                    DEFAULT_FRAMEWORK_PATH_SEARCH_PATH_FUNCTION,
                    Optional.<SourcePath>absent(),
                    DEFAULT_INCLUDES),
                DEFAULT_OUTPUT,
                DEFAULT_INPUT,
                DEFAULT_INPUT_TYPE,
                sanitizer2));

    assertEquals(ruleKey1, ruleKey2);
  }
コード例 #2
0
  @Test
  public void inputChangesCauseRuleKeyChangesForCompilation() {
    SourcePathResolver pathResolver =
        new SourcePathResolver(
            new BuildRuleResolver(TargetGraph.EMPTY, new BuildTargetNodeToBuildRuleTransformer()));
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
    FakeFileHashCache hashCache =
        FakeFileHashCache.createFromStrings(
            ImmutableMap.<String, String>builder()
                .put("preprocessor", Strings.repeat("a", 40))
                .put("compiler", Strings.repeat("a", 40))
                .put("test.o", Strings.repeat("b", 40))
                .put("test.cpp", Strings.repeat("c", 40))
                .put("different", Strings.repeat("d", 40))
                .put("foo/test.h", Strings.repeat("e", 40))
                .put("path/to/a/plugin.so", Strings.repeat("f", 40))
                .put("path/to/a/different/plugin.so", Strings.repeat("a0", 40))
                .build());

    // Generate a rule key for the defaults.

    RuleKey defaultRuleKey =
        new DefaultRuleKeyBuilderFactory(hashCache, pathResolver)
            .build(
                CxxPreprocessAndCompile.compile(
                    params,
                    pathResolver,
                    DEFAULT_COMPILER,
                    DEFAULT_PLATFORM_FLAGS,
                    DEFAULT_RULE_FLAGS,
                    DEFAULT_OUTPUT,
                    DEFAULT_INPUT,
                    DEFAULT_INPUT_TYPE,
                    DEFAULT_SANITIZER));

    // Verify that changing the compiler causes a rulekey change.

    RuleKey compilerChange =
        new DefaultRuleKeyBuilderFactory(hashCache, pathResolver)
            .build(
                CxxPreprocessAndCompile.compile(
                    params,
                    pathResolver,
                    new DefaultCompiler(new HashedFileTool(Paths.get("different"))),
                    DEFAULT_PLATFORM_FLAGS,
                    DEFAULT_RULE_FLAGS,
                    DEFAULT_OUTPUT,
                    DEFAULT_INPUT,
                    DEFAULT_INPUT_TYPE,
                    DEFAULT_SANITIZER));
    assertNotEquals(defaultRuleKey, compilerChange);

    // Verify that changing the operation causes a rulekey change.

    RuleKey operationChange =
        new DefaultRuleKeyBuilderFactory(hashCache, pathResolver)
            .build(
                CxxPreprocessAndCompile.preprocess(
                    params,
                    pathResolver,
                    new PreprocessorDelegate(
                        pathResolver,
                        DEFAULT_SANITIZER,
                        DEFAULT_WORKING_DIR,
                        DEFAULT_PREPROCESSOR,
                        DEFAULT_PLATFORM_FLAGS,
                        DEFAULT_RULE_FLAGS,
                        DEFAULT_INCLUDE_ROOTS,
                        DEFAULT_SYSTEM_INCLUDE_ROOTS,
                        DEFAULT_HEADER_MAPS,
                        DEFAULT_FRAMEWORK_ROOTS,
                        DEFAULT_FRAMEWORK_PATH_SEARCH_PATH_FUNCTION,
                        Optional.<SourcePath>absent(),
                        DEFAULT_INCLUDES),
                    DEFAULT_OUTPUT,
                    DEFAULT_INPUT,
                    DEFAULT_INPUT_TYPE,
                    DEFAULT_SANITIZER));
    assertNotEquals(defaultRuleKey, operationChange);

    // Verify that changing the platform flags causes a rulekey change.

    RuleKey platformFlagsChange =
        new DefaultRuleKeyBuilderFactory(hashCache, pathResolver)
            .build(
                CxxPreprocessAndCompile.compile(
                    params,
                    pathResolver,
                    DEFAULT_COMPILER,
                    ImmutableList.of("-different"),
                    DEFAULT_RULE_FLAGS,
                    DEFAULT_OUTPUT,
                    DEFAULT_INPUT,
                    DEFAULT_INPUT_TYPE,
                    DEFAULT_SANITIZER));
    assertNotEquals(defaultRuleKey, platformFlagsChange);

    // Verify that changing the rule flags causes a rulekey change.

    RuleKey ruleFlagsChange =
        new DefaultRuleKeyBuilderFactory(hashCache, pathResolver)
            .build(
                CxxPreprocessAndCompile.compile(
                    params,
                    pathResolver,
                    DEFAULT_COMPILER,
                    DEFAULT_PLATFORM_FLAGS,
                    ImmutableList.of("-other", "flags"),
                    DEFAULT_OUTPUT,
                    DEFAULT_INPUT,
                    DEFAULT_INPUT_TYPE,
                    DEFAULT_SANITIZER));
    assertNotEquals(defaultRuleKey, ruleFlagsChange);

    // Verify that changing the input causes a rulekey change.

    RuleKey inputChange =
        new DefaultRuleKeyBuilderFactory(hashCache, pathResolver)
            .build(
                CxxPreprocessAndCompile.compile(
                    params,
                    pathResolver,
                    DEFAULT_COMPILER,
                    DEFAULT_PLATFORM_FLAGS,
                    DEFAULT_RULE_FLAGS,
                    DEFAULT_OUTPUT,
                    new FakeSourcePath("different"),
                    DEFAULT_INPUT_TYPE,
                    DEFAULT_SANITIZER));
    assertNotEquals(defaultRuleKey, inputChange);
  }
コード例 #3
0
  @Test
  public void inputChangesCauseRuleKeyChangesForPreprocessing() {
    SourcePathResolver pathResolver =
        new SourcePathResolver(
            new BuildRuleResolver(TargetGraph.EMPTY, new BuildTargetNodeToBuildRuleTransformer()));
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
    FakeFileHashCache hashCache =
        FakeFileHashCache.createFromStrings(
            ImmutableMap.<String, String>builder()
                .put("preprocessor", Strings.repeat("a", 40))
                .put("compiler", Strings.repeat("a", 40))
                .put("test.o", Strings.repeat("b", 40))
                .put("test.cpp", Strings.repeat("c", 40))
                .put("different", Strings.repeat("d", 40))
                .put("foo/test.h", Strings.repeat("e", 40))
                .put("path/to/a/plugin.so", Strings.repeat("f", 40))
                .put("path/to/a/different/plugin.so", Strings.repeat("a0", 40))
                .build());

    // Generate a rule key for the defaults.

    RuleKey defaultRuleKey =
        new DefaultRuleKeyBuilderFactory(hashCache, pathResolver)
            .build(
                CxxPreprocessAndCompile.preprocess(
                    params,
                    pathResolver,
                    new PreprocessorDelegate(
                        pathResolver,
                        DEFAULT_SANITIZER,
                        DEFAULT_WORKING_DIR,
                        DEFAULT_PREPROCESSOR,
                        DEFAULT_PREPROCESSOR_PLATFORM_FLAGS,
                        DEFAULT_PREPROCESOR_RULE_FLAGS,
                        DEFAULT_INCLUDE_ROOTS,
                        DEFAULT_SYSTEM_INCLUDE_ROOTS,
                        DEFAULT_HEADER_MAPS,
                        DEFAULT_FRAMEWORK_ROOTS,
                        DEFAULT_FRAMEWORK_PATH_SEARCH_PATH_FUNCTION,
                        Optional.<SourcePath>absent(),
                        DEFAULT_INCLUDES),
                    DEFAULT_OUTPUT,
                    DEFAULT_INPUT,
                    DEFAULT_INPUT_TYPE,
                    DEFAULT_SANITIZER));

    // Verify that changing the includes does *not* cause a rulekey change, since we use a
    // different mechanism to track header changes.

    RuleKey includesChange =
        new DefaultRuleKeyBuilderFactory(hashCache, pathResolver)
            .build(
                CxxPreprocessAndCompile.preprocess(
                    params,
                    pathResolver,
                    new PreprocessorDelegate(
                        pathResolver,
                        DEFAULT_SANITIZER,
                        DEFAULT_WORKING_DIR,
                        DEFAULT_PREPROCESSOR,
                        DEFAULT_PREPROCESSOR_PLATFORM_FLAGS,
                        DEFAULT_PREPROCESOR_RULE_FLAGS,
                        ImmutableSet.of(Paths.get("different")),
                        DEFAULT_SYSTEM_INCLUDE_ROOTS,
                        DEFAULT_HEADER_MAPS,
                        DEFAULT_FRAMEWORK_ROOTS,
                        DEFAULT_FRAMEWORK_PATH_SEARCH_PATH_FUNCTION,
                        Optional.<SourcePath>absent(),
                        DEFAULT_INCLUDES),
                    DEFAULT_OUTPUT,
                    DEFAULT_INPUT,
                    DEFAULT_INPUT_TYPE,
                    DEFAULT_SANITIZER));
    assertEquals(defaultRuleKey, includesChange);

    // Verify that changing the system includes does *not* cause a rulekey change, since we use a
    // different mechanism to track header changes.

    RuleKey systemIncludesChange =
        new DefaultRuleKeyBuilderFactory(hashCache, pathResolver)
            .build(
                CxxPreprocessAndCompile.preprocess(
                    params,
                    pathResolver,
                    new PreprocessorDelegate(
                        pathResolver,
                        DEFAULT_SANITIZER,
                        DEFAULT_WORKING_DIR,
                        DEFAULT_PREPROCESSOR,
                        DEFAULT_PREPROCESSOR_PLATFORM_FLAGS,
                        DEFAULT_PREPROCESOR_RULE_FLAGS,
                        DEFAULT_INCLUDE_ROOTS,
                        ImmutableSet.of(Paths.get("different")),
                        DEFAULT_HEADER_MAPS,
                        DEFAULT_FRAMEWORK_ROOTS,
                        DEFAULT_FRAMEWORK_PATH_SEARCH_PATH_FUNCTION,
                        Optional.<SourcePath>absent(),
                        DEFAULT_INCLUDES),
                    DEFAULT_OUTPUT,
                    DEFAULT_INPUT,
                    DEFAULT_INPUT_TYPE,
                    DEFAULT_SANITIZER));
    assertEquals(defaultRuleKey, systemIncludesChange);

    // Verify that changing the header maps does *not* cause a rulekey change, since we use a
    // different mechanism to track header changes.

    RuleKey headerMapsChange =
        new DefaultRuleKeyBuilderFactory(hashCache, pathResolver)
            .build(
                CxxPreprocessAndCompile.preprocess(
                    params,
                    pathResolver,
                    new PreprocessorDelegate(
                        pathResolver,
                        DEFAULT_SANITIZER,
                        DEFAULT_WORKING_DIR,
                        DEFAULT_PREPROCESSOR,
                        DEFAULT_PREPROCESSOR_PLATFORM_FLAGS,
                        DEFAULT_PREPROCESOR_RULE_FLAGS,
                        DEFAULT_INCLUDE_ROOTS,
                        DEFAULT_SYSTEM_INCLUDE_ROOTS,
                        ImmutableSet.of(Paths.get("different")),
                        DEFAULT_FRAMEWORK_ROOTS,
                        DEFAULT_FRAMEWORK_PATH_SEARCH_PATH_FUNCTION,
                        Optional.<SourcePath>absent(),
                        DEFAULT_INCLUDES),
                    DEFAULT_OUTPUT,
                    DEFAULT_INPUT,
                    DEFAULT_INPUT_TYPE,
                    DEFAULT_SANITIZER));
    assertEquals(defaultRuleKey, headerMapsChange);

    // Verify that changing the framework roots causes a rulekey change.

    RuleKey frameworkRootsChange =
        new DefaultRuleKeyBuilderFactory(hashCache, pathResolver)
            .build(
                CxxPreprocessAndCompile.preprocess(
                    params,
                    pathResolver,
                    new PreprocessorDelegate(
                        pathResolver,
                        DEFAULT_SANITIZER,
                        DEFAULT_WORKING_DIR,
                        DEFAULT_PREPROCESSOR,
                        DEFAULT_PREPROCESSOR_PLATFORM_FLAGS,
                        DEFAULT_PREPROCESOR_RULE_FLAGS,
                        DEFAULT_INCLUDE_ROOTS,
                        DEFAULT_SYSTEM_INCLUDE_ROOTS,
                        DEFAULT_HEADER_MAPS,
                        ImmutableSet.of(
                            FrameworkPath.ofSourcePath(new FakeSourcePath("different"))),
                        DEFAULT_FRAMEWORK_PATH_SEARCH_PATH_FUNCTION,
                        Optional.<SourcePath>absent(),
                        DEFAULT_INCLUDES),
                    DEFAULT_OUTPUT,
                    DEFAULT_INPUT,
                    DEFAULT_INPUT_TYPE,
                    DEFAULT_SANITIZER));
    assertNotEquals(defaultRuleKey, frameworkRootsChange);
  }
コード例 #4
0
ファイル: ArchiveTest.java プロジェクト: sdwilsh/buck
  @Test
  public void testThatInputChangesCauseRuleKeyChanges() {
    SourcePathResolver pathResolver =
        new SourcePathResolver(
            new BuildRuleResolver(
                TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer()));
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bar");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
    FakeFileHashCache hashCache =
        FakeFileHashCache.createFromStrings(
            ImmutableMap.<String, String>builder()
                .put(AR.toString(), Strings.repeat("0", 40))
                .put(RANLIB.toString(), Strings.repeat("1", 40))
                .put("a.o", Strings.repeat("a", 40))
                .put("b.o", Strings.repeat("b", 40))
                .put("c.o", Strings.repeat("c", 40))
                .put(Paths.get("different").toString(), Strings.repeat("d", 40))
                .build());

    // Generate a rule key for the defaults.
    RuleKey defaultRuleKey =
        new DefaultRuleKeyBuilderFactory(0, hashCache, pathResolver)
            .build(
                Archive.from(
                    target,
                    params,
                    pathResolver,
                    DEFAULT_ARCHIVER,
                    ImmutableList.of(),
                    DEFAULT_RANLIB,
                    ImmutableList.of(),
                    Archive.Contents.NORMAL,
                    DEFAULT_OUTPUT,
                    DEFAULT_INPUTS));

    // Verify that changing the archiver causes a rulekey change.
    RuleKey archiverChange =
        new DefaultRuleKeyBuilderFactory(0, hashCache, pathResolver)
            .build(
                Archive.from(
                    target,
                    params,
                    pathResolver,
                    new GnuArchiver(new HashedFileTool(Paths.get("different"))),
                    ImmutableList.of(),
                    DEFAULT_RANLIB,
                    ImmutableList.of(),
                    Archive.Contents.NORMAL,
                    DEFAULT_OUTPUT,
                    DEFAULT_INPUTS));
    assertNotEquals(defaultRuleKey, archiverChange);

    // Verify that changing the output path causes a rulekey change.
    RuleKey outputChange =
        new DefaultRuleKeyBuilderFactory(0, hashCache, pathResolver)
            .build(
                Archive.from(
                    target,
                    params,
                    pathResolver,
                    DEFAULT_ARCHIVER,
                    ImmutableList.of(),
                    DEFAULT_RANLIB,
                    ImmutableList.of(),
                    Archive.Contents.NORMAL,
                    Paths.get("different"),
                    DEFAULT_INPUTS));
    assertNotEquals(defaultRuleKey, outputChange);

    // Verify that changing the inputs causes a rulekey change.
    RuleKey inputChange =
        new DefaultRuleKeyBuilderFactory(0, hashCache, pathResolver)
            .build(
                Archive.from(
                    target,
                    params,
                    pathResolver,
                    DEFAULT_ARCHIVER,
                    ImmutableList.of(),
                    DEFAULT_RANLIB,
                    ImmutableList.of(),
                    Archive.Contents.NORMAL,
                    DEFAULT_OUTPUT,
                    ImmutableList.of(new FakeSourcePath("different"))));
    assertNotEquals(defaultRuleKey, inputChange);

    // Verify that changing the type of archiver causes a rulekey change.
    RuleKey archiverTypeChange =
        new DefaultRuleKeyBuilderFactory(0, hashCache, pathResolver)
            .build(
                Archive.from(
                    target,
                    params,
                    pathResolver,
                    new BsdArchiver(new HashedFileTool(AR)),
                    ImmutableList.of(),
                    DEFAULT_RANLIB,
                    ImmutableList.of(),
                    Archive.Contents.NORMAL,
                    DEFAULT_OUTPUT,
                    DEFAULT_INPUTS));
    assertNotEquals(defaultRuleKey, archiverTypeChange);
  }