Search in sources :

Example 1 with ProjectFileHashCache

use of com.facebook.buck.util.cache.ProjectFileHashCache in project buck by facebook.

the class DistBuildSlaveExecutor method createStackOfDefaultFileHashCache.

private StackedFileHashCache createStackOfDefaultFileHashCache() throws IOException {
    ImmutableList.Builder<ProjectFileHashCache> allCachesBuilder = ImmutableList.builder();
    Cell rootCell = args.getState().getRootCell();
    // 1. Add all cells (including the root cell).
    for (Path cellPath : rootCell.getKnownRoots()) {
        Cell cell = rootCell.getCell(cellPath);
        allCachesBuilder.add(DefaultFileHashCache.createDefaultFileHashCache(cell.getFilesystem()));
    }
    // 2. Add the Operating System roots.
    allCachesBuilder.addAll(DefaultFileHashCache.createOsRootDirectoriesCaches());
    return new StackedFileHashCache(allCachesBuilder.build());
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) Cell(com.facebook.buck.rules.Cell)

Example 2 with ProjectFileHashCache

use of com.facebook.buck.util.cache.ProjectFileHashCache in project buck by facebook.

the class DistBuildFileHashesIntegrationTest method createDistBuildFileHashes.

private DistBuildFileHashes createDistBuildFileHashes(TargetGraph targetGraph, Cell rootCell) throws IOException {
    ActionGraphCache cache = new ActionGraphCache(new BroadcastEventListener());
    ActionGraphAndResolver actionGraphAndResolver = cache.getActionGraph(BuckEventBusFactory.newInstance(), true, false, targetGraph, KEY_SEED);
    BuildRuleResolver ruleResolver = actionGraphAndResolver.getResolver();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(ruleResolver);
    SourcePathResolver sourcePathResolver = new SourcePathResolver(ruleFinder);
    DistBuildCellIndexer cellIndexer = new DistBuildCellIndexer(rootCell);
    ImmutableList.Builder<ProjectFileHashCache> allCaches = ImmutableList.builder();
    allCaches.add(DefaultFileHashCache.createDefaultFileHashCache(rootCell.getFilesystem()));
    for (Path cellPath : rootCell.getKnownRoots()) {
        Cell cell = rootCell.getCell(cellPath);
        allCaches.add(DefaultFileHashCache.createDefaultFileHashCache(cell.getFilesystem()));
    }
    allCaches.addAll(DefaultFileHashCache.createOsRootDirectoriesCaches());
    StackedFileHashCache stackedCache = new StackedFileHashCache(allCaches.build());
    return new DistBuildFileHashes(actionGraphAndResolver.getActionGraph(), sourcePathResolver, ruleFinder, stackedCache, cellIndexer, MoreExecutors.newDirectExecutorService(), /* keySeed */
    KEY_SEED, rootCell);
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) ActionGraphCache(com.facebook.buck.rules.ActionGraphCache) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache) StackedFileHashCache(com.facebook.buck.util.cache.StackedFileHashCache) ActionGraphAndResolver(com.facebook.buck.rules.ActionGraphAndResolver) Cell(com.facebook.buck.rules.Cell)

Example 3 with ProjectFileHashCache

use of com.facebook.buck.util.cache.ProjectFileHashCache in project buck by facebook.

the class DistBuildFileHashesTest method cacheMaterializes.

@Test
public void cacheMaterializes() throws Exception {
    SingleFileFixture f = new SingleFileFixture(tempDir);
    List<BuildJobStateFileHashes> fileHashes = f.distributedBuildFileHashes.getFileHashes();
    ProjectFilesystem readProjectFilesystem = new ProjectFilesystem(tempDir.newFolder("read_hashes").toPath().toRealPath());
    ProjectFileHashCache mockCache = EasyMock.createMock(ProjectFileHashCache.class);
    EasyMock.expect(mockCache.getFilesystem()).andReturn(readProjectFilesystem).anyTimes();
    EasyMock.replay(mockCache);
    ProjectFileHashCache fileHashCache = DistBuildFileHashes.createFileHashCache(mockCache, fileHashes.get(0));
    assertThat(fileHashCache.willGet(readProjectFilesystem.resolve("src/A.java")), Matchers.equalTo(true));
    assertThat(fileHashCache.get(readProjectFilesystem.resolve("src/A.java")), Matchers.equalTo(f.writtenHashCode));
}
Also used : BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 4 with ProjectFileHashCache

use of com.facebook.buck.util.cache.ProjectFileHashCache in project buck by facebook.

the class DistBuildFileHashesTest method cacheReadsHashesForFiles.

@Test
public void cacheReadsHashesForFiles() throws Exception {
    SingleFileFixture f = new SingleFileFixture(tempDir);
    List<BuildJobStateFileHashes> fileHashes = f.distributedBuildFileHashes.getFileHashes();
    ProjectFilesystem readProjectFilesystem = new ProjectFilesystem(tempDir.newFolder("read_hashes").toPath().toRealPath());
    ProjectFileHashCache mockCache = EasyMock.createMock(ProjectFileHashCache.class);
    EasyMock.expect(mockCache.getFilesystem()).andReturn(readProjectFilesystem).anyTimes();
    EasyMock.replay(mockCache);
    ProjectFileHashCache fileHashCache = DistBuildFileHashes.createFileHashCache(mockCache, fileHashes.get(0));
    assertThat(fileHashCache.willGet(readProjectFilesystem.resolve(f.javaSrcPath)), Matchers.equalTo(true));
    assertThat(fileHashCache.get(readProjectFilesystem.resolve(f.javaSrcPath)), Matchers.equalTo(f.writtenHashCode));
}
Also used : BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 5 with ProjectFileHashCache

use of com.facebook.buck.util.cache.ProjectFileHashCache in project buck by facebook.

the class DistBuildFileHashesTest method readsHashesForArchiveMembers.

@Test
public void readsHashesForArchiveMembers() throws Exception {
    try (ArchiveFilesFixture f = ArchiveFilesFixture.create(archiveTempDir)) {
        List<BuildJobStateFileHashes> recordedHashes = f.distributedBuildFileHashes.getFileHashes();
        ProjectFilesystem readProjectFilesystem = new ProjectFilesystem(tempDir.newFolder("read_hashes").toPath().toRealPath());
        ProjectFileHashCache mockCache = EasyMock.createMock(ProjectFileHashCache.class);
        EasyMock.expect(mockCache.getFilesystem()).andReturn(readProjectFilesystem).anyTimes();
        EasyMock.replay(mockCache);
        ProjectFileHashCache fileHashCache = DistBuildFileHashes.createFileHashCache(mockCache, recordedHashes.get(0));
        ArchiveMemberPath archiveMemberPath = ArchiveMemberPath.of(readProjectFilesystem.resolve(f.archivePath), f.archiveMemberPath);
        assertThat(fileHashCache.willGet(archiveMemberPath), Matchers.is(true));
        assertThat(fileHashCache.get(archiveMemberPath), Matchers.is(f.archiveMemberHash));
    }
}
Also used : BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Aggregations

ProjectFileHashCache (com.facebook.buck.util.cache.ProjectFileHashCache)13 BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)9 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)9 Path (java.nio.file.Path)9 Test (org.junit.Test)4 BuildJobStateFileHashEntry (com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry)3 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)2 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)2 Cell (com.facebook.buck.rules.Cell)2 StackedFileHashCache (com.facebook.buck.util.cache.StackedFileHashCache)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 AndroidBuckConfig (com.facebook.buck.android.AndroidBuckConfig)1 AndroidDirectoryResolver (com.facebook.buck.android.AndroidDirectoryResolver)1 AndroidPlatformTarget (com.facebook.buck.android.AndroidPlatformTarget)1 DefaultAndroidDirectoryResolver (com.facebook.buck.android.DefaultAndroidDirectoryResolver)1 NoAndroidSdkException (com.facebook.buck.android.NoAndroidSdkException)1 ArtifactCache (com.facebook.buck.artifact_cache.ArtifactCache)1