Search in sources :

Example 1 with FakeDepFileBuildRule

use of com.facebook.buck.rules.FakeDepFileBuildRule in project buck by facebook.

the class DependencyFileRuleKeyFactoryTest method testDepFileRuleKeyImpl.

private void testDepFileRuleKeyImpl(SourcePathRuleFinder ruleFinder, SourcePathResolver pathResolver, Object fieldValueBefore, Object fieldValueAfter, ImmutableMap<Path, HashCode> hashesBefore, ImmutableMap<Path, HashCode> hashesAfter, Predicate<SourcePath> coveredInputPaths, ImmutableSet<SourcePath> interestingInputPaths, ImmutableList<DependencyFileEntry> depFileEntries, boolean expectSameKeys, ImmutableSet<SourcePath> expectedDepFileInputsAfter, String failureMessage) throws Exception {
    RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(0);
    FakeDepFileBuildRule rule1 = new FakeDepFileBuildRule("//:rule") {

        @AddToRuleKey
        final Object myField = fieldValueBefore;
    };
    rule1.setCoveredByDepFilePredicate(coveredInputPaths);
    rule1.setExistenceOfInterestPredicate(interestingInputPaths);
    FakeFileHashCache hashCache = new FakeFileHashCache(hashesBefore, true, ImmutableMap.of());
    RuleKeyAndInputs res1 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).build(rule1, depFileEntries);
    FakeDepFileBuildRule rule2 = new FakeDepFileBuildRule("//:rule") {

        @AddToRuleKey
        final Object myField = fieldValueAfter;
    };
    rule2.setCoveredByDepFilePredicate(coveredInputPaths);
    rule2.setExistenceOfInterestPredicate(interestingInputPaths);
    hashCache = new FakeFileHashCache(hashesAfter, true, ImmutableMap.of());
    RuleKeyAndInputs res2 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).build(rule2, depFileEntries);
    if (expectSameKeys) {
        assertThat(failureMessage, res2.getRuleKey(), Matchers.equalTo(res1.getRuleKey()));
    } else {
        assertThat(failureMessage, res2.getRuleKey(), Matchers.not(Matchers.equalTo(res1.getRuleKey())));
    }
    assertThat(res2.getInputs(), Matchers.equalTo(expectedDepFileInputsAfter));
}
Also used : FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FakeDepFileBuildRule(com.facebook.buck.rules.FakeDepFileBuildRule)

Example 2 with FakeDepFileBuildRule

use of com.facebook.buck.rules.FakeDepFileBuildRule in project buck by facebook.

the class DependencyFileRuleKeyFactoryTest method testKeysGetHashed.

@Test
public void testKeysGetHashed() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(0);
    BuildRuleResolver ruleResolver = newRuleResolver();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver pathResolver = new SourcePathResolver(ruleFinder);
    SourcePath unusedSourcePath = new PathSourcePath(filesystem, Paths.get("input0"));
    SourcePath sourcePath = new PathSourcePath(filesystem, Paths.get("input"));
    DependencyFileEntry dependencyFileEntry = DependencyFileEntry.fromSourcePath(sourcePath, pathResolver);
    ImmutableMap<Path, HashCode> hashes = ImmutableMap.of(pathResolver.getAbsolutePath(sourcePath), HashCode.fromInt(42));
    Predicate<SourcePath> coveredPredicate = ImmutableSet.of(sourcePath, unusedSourcePath)::contains;
    FakeDepFileBuildRule rule1 = new FakeDepFileBuildRule("//:rule") {

        @AddToRuleKey
        final Object myField1 = sourcePath;

        @AddToRuleKey
        final Object myField2 = unusedSourcePath;
    };
    rule1.setCoveredByDepFilePredicate(coveredPredicate);
    FakeFileHashCache hashCache = new FakeFileHashCache(hashes, true, ImmutableMap.of());
    RuleKeyAndInputs res1 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).build(rule1, ImmutableList.of(dependencyFileEntry));
    FakeDepFileBuildRule rule2 = new FakeDepFileBuildRule("//:rule") {

        @AddToRuleKey
        final Object myField1 = unusedSourcePath;

        @AddToRuleKey
        final Object myField2 = sourcePath;
    };
    rule2.setCoveredByDepFilePredicate(coveredPredicate);
    hashCache = new FakeFileHashCache(hashes, true, ImmutableMap.of());
    RuleKeyAndInputs res2 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).build(rule2, ImmutableList.of(dependencyFileEntry));
    assertThat(res2.getRuleKey(), Matchers.not(Matchers.equalTo(res1.getRuleKey())));
    assertThat(res2.getInputs(), Matchers.equalTo(ImmutableSet.of(sourcePath)));
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) Path(java.nio.file.Path) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) FakeDepFileBuildRule(com.facebook.buck.rules.FakeDepFileBuildRule) SourcePath(com.facebook.buck.rules.SourcePath) ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) PathSourcePath(com.facebook.buck.rules.PathSourcePath) HashCode(com.google.common.hash.HashCode) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 3 with FakeDepFileBuildRule

use of com.facebook.buck.rules.FakeDepFileBuildRule in project buck by facebook.

the class DependencyFileRuleKeyFactoryTest method testManifestKeyImpl.

private void testManifestKeyImpl(SourcePathRuleFinder ruleFinder, SourcePathResolver pathResolver, Object fieldValueBefore, Object fieldValueAfter, ImmutableMap<Path, HashCode> hashesBefore, ImmutableMap<Path, HashCode> hashesAfter, Predicate<SourcePath> coveredInputPaths, ImmutableSet<SourcePath> interestingInputPaths, boolean expectSameKeys, ImmutableSet<SourcePath> expectedDepFileInputsAfter, String failureMessage) throws Exception {
    RuleKeyFieldLoader fieldLoader = new RuleKeyFieldLoader(0);
    FakeDepFileBuildRule rule1 = new FakeDepFileBuildRule("//:rule") {

        @AddToRuleKey
        final Object myField = fieldValueBefore;
    };
    rule1.setCoveredByDepFilePredicate(coveredInputPaths);
    rule1.setExistenceOfInterestPredicate(interestingInputPaths);
    FakeFileHashCache hashCache = new FakeFileHashCache(hashesBefore, true, ImmutableMap.of());
    RuleKeyAndInputs res1 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).buildManifestKey(rule1);
    FakeDepFileBuildRule rule2 = new FakeDepFileBuildRule("//:rule") {

        @AddToRuleKey
        final Object myField = fieldValueAfter;
    };
    rule2.setCoveredByDepFilePredicate(coveredInputPaths);
    rule2.setExistenceOfInterestPredicate(interestingInputPaths);
    hashCache = new FakeFileHashCache(hashesAfter, true, ImmutableMap.of());
    RuleKeyAndInputs res2 = new DefaultDependencyFileRuleKeyFactory(fieldLoader, hashCache, pathResolver, ruleFinder).buildManifestKey(rule2);
    if (expectSameKeys) {
        assertThat(failureMessage, res2.getRuleKey(), Matchers.equalTo(res1.getRuleKey()));
    } else {
        assertThat(failureMessage, res2.getRuleKey(), Matchers.not(Matchers.equalTo(res1.getRuleKey())));
    }
    assertThat(res2.getInputs(), Matchers.equalTo(expectedDepFileInputsAfter));
}
Also used : FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FakeDepFileBuildRule(com.facebook.buck.rules.FakeDepFileBuildRule)

Aggregations

FakeDepFileBuildRule (com.facebook.buck.rules.FakeDepFileBuildRule)3 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 ArchiveMemberSourcePath (com.facebook.buck.rules.ArchiveMemberSourcePath)1 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 DefaultBuildTargetSourcePath (com.facebook.buck.rules.DefaultBuildTargetSourcePath)1 PathSourcePath (com.facebook.buck.rules.PathSourcePath)1 SourcePath (com.facebook.buck.rules.SourcePath)1 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)1 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1 HashCode (com.google.common.hash.HashCode)1 Path (java.nio.file.Path)1 Test (org.junit.Test)1