Search in sources :

Example 21 with FakeFileHashCache

use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.

the class ManifestTest method addEntryWithSourcePathsThatHaveSameRelativePaths.

@Test
public void addEntryWithSourcePathsThatHaveSameRelativePaths() throws IOException {
    RuleKey key = new RuleKey("aa");
    Path tmp1 = Files.createTempDirectory("tmp1");
    ProjectFilesystem filesystem1 = new FakeProjectFilesystem(tmp1);
    SourcePath input1 = new PathSourcePath(filesystem1, Paths.get("input.h"));
    HashCode hashCode1 = HashCode.fromInt(1);
    Path tmp2 = Files.createTempDirectory("tmp2");
    ProjectFilesystem filesystem2 = new FakeProjectFilesystem(tmp2);
    SourcePath input2 = new PathSourcePath(filesystem2, Paths.get("input.h"));
    HashCode hashCode2 = HashCode.fromInt(1);
    FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(RESOLVER.getAbsolutePath(input1), hashCode1, RESOLVER.getAbsolutePath(input2), hashCode2));
    Manifest manifest1 = new Manifest();
    manifest1.addEntry(fileHashCache, key, RESOLVER, ImmutableSet.of(input1, input2), ImmutableSet.of(input1));
    assertThat(manifest1.toMap(), Matchers.equalTo(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input1).toString(), Manifest.hashSourcePathGroup(fileHashCache, RESOLVER, ImmutableList.of(input1, input2))))));
    Manifest manifest2 = new Manifest();
    manifest2.addEntry(fileHashCache, key, RESOLVER, ImmutableSet.of(input1, input2), ImmutableSet.of(input2));
    assertThat(manifest2.toMap(), Matchers.equalTo(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input2).toString(), Manifest.hashSourcePathGroup(fileHashCache, RESOLVER, ImmutableList.of(input1, input2))))));
}
Also used : Path(java.nio.file.Path) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) HashCode(com.google.common.hash.HashCode) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 22 with FakeFileHashCache

use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.

the class ManifestTest method lookupMatch.

@Test
public void lookupMatch() throws IOException {
    RuleKey key = new RuleKey("aa");
    SourcePath input = new FakeSourcePath("input.h");
    HashCode hashCode = HashCode.fromInt(20);
    Manifest manifest = Manifest.fromMap(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input).toString(), hashCode)));
    FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(RESOLVER.getAbsolutePath(input), hashCode));
    assertThat(manifest.lookup(fileHashCache, RESOLVER, ImmutableSet.of(input)), Matchers.equalTo(Optional.of(key)));
}
Also used : FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) HashCode(com.google.common.hash.HashCode) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) Test(org.junit.Test)

Example 23 with FakeFileHashCache

use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.

the class ManifestTest method addEntryFromArchive.

@Test
public void addEntryFromArchive() throws IOException {
    Manifest manifest = new Manifest();
    RuleKey key = new RuleKey("aa");
    SourcePath input = new ArchiveMemberSourcePath(new FakeSourcePath("somewhere/a.jar"), Paths.get("Member.class"));
    HashCode hashCode = HashCode.fromInt(20);
    FileHashCache fileHashCache = new FakeFileHashCache(new HashMap<>(), ImmutableMap.of(RESOLVER.getAbsoluteArchiveMemberPath(input), hashCode), new HashMap<>());
    manifest.addEntry(fileHashCache, key, RESOLVER, ImmutableSet.of(input), ImmutableSet.of(input));
    assertThat(manifest.toMap(), Matchers.equalTo(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativeArchiveMemberPath(input).toString(), hashCode))));
}
Also used : FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) HashCode(com.google.common.hash.HashCode) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) Test(org.junit.Test)

Example 24 with FakeFileHashCache

use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.

the class ManifestTest method addEntry.

@Test
public void addEntry() throws IOException {
    Manifest manifest = new Manifest();
    RuleKey key = new RuleKey("aa");
    SourcePath input = new FakeSourcePath("input.h");
    HashCode hashCode = HashCode.fromInt(20);
    FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(RESOLVER.getAbsolutePath(input), hashCode));
    manifest.addEntry(fileHashCache, key, RESOLVER, ImmutableSet.of(input), ImmutableSet.of(input));
    assertThat(manifest.toMap(), Matchers.equalTo(ImmutableMap.of(key, ImmutableMap.of(RESOLVER.getRelativePath(input).toString(), hashCode))));
}
Also used : FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) HashCode(com.google.common.hash.HashCode) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) Test(org.junit.Test)

Example 25 with FakeFileHashCache

use of com.facebook.buck.testutil.FakeFileHashCache in project buck by facebook.

the class ManifestTest method lookupMatchAfterHashMismatch.

@Test
public void lookupMatchAfterHashMismatch() throws IOException {
    RuleKey key1 = new RuleKey("aa");
    RuleKey key2 = new RuleKey("bb");
    SourcePath input = new FakeSourcePath("input.h");
    Manifest manifest = Manifest.fromMap(ImmutableMap.of(key1, ImmutableMap.of(RESOLVER.getRelativePath(input).toString(), HashCode.fromInt(1)), key2, ImmutableMap.of(RESOLVER.getRelativePath(input).toString(), HashCode.fromInt(2))));
    FileHashCache fileHashCache = new FakeFileHashCache(ImmutableMap.of(RESOLVER.getAbsolutePath(input), HashCode.fromInt(2)));
    assertThat(manifest.lookup(fileHashCache, RESOLVER, ImmutableSet.of(input)), Matchers.equalTo(Optional.of(key2)));
}
Also used : FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) FileHashCache(com.facebook.buck.util.cache.FileHashCache) FakeFileHashCache(com.facebook.buck.testutil.FakeFileHashCache) Test(org.junit.Test)

Aggregations

FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)42 Test (org.junit.Test)38 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)24 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)24 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)22 RuleKey (com.facebook.buck.rules.RuleKey)22 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)22 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)20 Path (java.nio.file.Path)20 PathSourcePath (com.facebook.buck.rules.PathSourcePath)19 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)18 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)16 SourcePath (com.facebook.buck.rules.SourcePath)16 AddToRuleKey (com.facebook.buck.rules.AddToRuleKey)14 BuildRule (com.facebook.buck.rules.BuildRule)14 FileHashCache (com.facebook.buck.util.cache.FileHashCache)14 HashCode (com.google.common.hash.HashCode)13 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)12 BuildTarget (com.facebook.buck.model.BuildTarget)11 BorrowablePath (com.facebook.buck.io.BorrowablePath)8