Search in sources :

Example 11 with BuildJobStateFileHashEntry

use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry in project buck by facebook.

the class MultiSourceContentsProviderTest method inlineContentProviderTakesPrecedence.

@Test
public void inlineContentProviderTakesPrecedence() throws IOException {
    EasyMock.replay(mockProvider);
    MultiSourceContentsProvider provider = new MultiSourceContentsProvider(mockProvider, Optional.empty());
    BuildJobStateFileHashEntry entry = new BuildJobStateFileHashEntry();
    entry.setHashCode("1234");
    entry.setContents(FILE_CONTENTS);
    Path targetAbsPath = tempDir.getRoot().toPath().resolve("my_file.txt");
    Assert.assertFalse(Files.isRegularFile(targetAbsPath));
    provider.materializeFileContents(entry, targetAbsPath);
    Assert.assertTrue(Files.isRegularFile(targetAbsPath));
    Assert.assertThat(Files.readAllBytes(targetAbsPath), Matchers.equalTo(FILE_CONTENTS));
    EasyMock.verify(mockProvider);
}
Also used : BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) Path(java.nio.file.Path) Test(org.junit.Test)

Example 12 with BuildJobStateFileHashEntry

use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry in project buck by facebook.

the class MultiSourceContentsProviderTest method serverIsUsedWhenInlineIsMissing.

@Test
public void serverIsUsedWhenInlineIsMissing() throws IOException {
    BuildJobStateFileHashEntry entry = new BuildJobStateFileHashEntry();
    entry.setHashCode("1234");
    Path targetAbsPath = tempDir.getRoot().toPath().resolve("my_file.txt");
    EasyMock.expect(mockProvider.materializeFileContents(EasyMock.eq(entry), EasyMock.eq(targetAbsPath))).andReturn(true).once();
    EasyMock.replay(mockProvider);
    MultiSourceContentsProvider provider = new MultiSourceContentsProvider(mockProvider, Optional.empty());
    Assert.assertFalse(Files.isRegularFile(targetAbsPath));
    provider.materializeFileContents(entry, targetAbsPath);
    EasyMock.verify(mockProvider);
}
Also used : BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) Path(java.nio.file.Path) Test(org.junit.Test)

Example 13 with BuildJobStateFileHashEntry

use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry in project buck by facebook.

the class RecordingFileHashLoaderTest method testRecordsDirectSymlinkToFile.

@Test
public void testRecordsDirectSymlinkToFile() throws IOException {
    // Scenario:
    // /project/linktoexternal -> /externalDir/externalfile
    // => create direct link: /project/linktoexternal -> /externalDir/externalfile
    assumeTrue(!Platform.detect().equals(Platform.WINDOWS));
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(projectDir.getRoot().toPath());
    Path externalFile = externalDir.newFile("externalfile").toPath();
    Path symlinkAbsPath = projectFilesystem.resolve("linktoexternal");
    Path symlinkRelPath = projectFilesystem.relativize(symlinkAbsPath);
    Files.createSymbolicLink(symlinkAbsPath, externalFile);
    RecordedFileHashes recordedFileHashes = new RecordedFileHashes(0);
    BuildJobStateFileHashes fileHashes = recordedFileHashes.getRemoteFileHashes();
    FakeProjectFileHashCache delegateCache = new FakeProjectFileHashCache(projectFilesystem, ImmutableMap.of(symlinkRelPath, EXAMPLE_HASHCODE));
    RecordingProjectFileHashCache recordingLoader = RecordingProjectFileHashCache.createForCellRoot(delegateCache, recordedFileHashes, new DistBuildConfig(FakeBuckConfig.builder().build()));
    recordingLoader.get(symlinkRelPath);
    assertThat(fileHashes.getEntries().size(), Matchers.equalTo(1));
    BuildJobStateFileHashEntry fileHashEntry = fileHashes.getEntries().get(0);
    assertTrue(fileHashEntry.isSetRootSymLink());
    assertThat(fileHashEntry.getRootSymLink(), Matchers.equalTo((unixPath("linktoexternal"))));
    assertTrue(fileHashEntry.isSetRootSymLink());
    assertThat(fileHashEntry.getRootSymLinkTarget(), Matchers.equalTo((unixPath(externalFile.toRealPath().toString()))));
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) FakeProjectFileHashCache(com.facebook.buck.testutil.FakeProjectFileHashCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 14 with BuildJobStateFileHashEntry

use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry in project buck by facebook.

the class MaterializerProjectFileHashCache method preloadAllFiles.

public void preloadAllFiles() throws IOException {
    for (Path absPath : remoteFileHashesByAbsPath.keySet()) {
        LOG.info("Preloading: [%s]", absPath.toString());
        BuildJobStateFileHashEntry fileHashEntry = remoteFileHashesByAbsPath.get(absPath);
        if (fileHashEntry == null || fileHashEntry.isPathIsAbsolute()) {
            continue;
        } else if (fileHashEntry.isSetMaterializeDuringPreloading() && fileHashEntry.isMaterializeDuringPreloading()) {
            Path relPath = projectFilesystem.getPathRelativeToProjectRoot(absPath).get();
            get(relPath);
        } else if (fileHashEntry.isSetRootSymLink()) {
            materializeSymlink(fileHashEntry, symlinkedPaths);
            symlinkedPaths.add(absPath);
        } else if (!fileHashEntry.isDirectory) {
            // Touch file
            projectFilesystem.createParentDirs(absPath);
            projectFilesystem.touch(absPath);
        } else {
            // Create directory
            // No need to materialize sub-dirs/files here, as there will be separate entries for those.
            projectFilesystem.mkdirs(absPath);
        }
    }
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry)

Example 15 with BuildJobStateFileHashEntry

use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry in project buck by facebook.

the class MaterializerProjectFileHashCache method materializeIfNeeded.

private void materializeIfNeeded(Path relPath, Queue<Path> remainingRelPaths) throws IOException {
    if (materializedPaths.contains(relPath)) {
        return;
    }
    LOG.info("Materializing: [%s]", relPath.toString());
    Path absPath = projectFilesystem.resolve(relPath).toAbsolutePath();
    BuildJobStateFileHashEntry fileHashEntry = remoteFileHashesByAbsPath.get(absPath);
    if (fileHashEntry == null || fileHashEntry.isPathIsAbsolute()) {
        materializedPaths.add(relPath);
        return;
    }
    if (fileHashEntry.isSetRootSymLink()) {
        if (!symlinkedPaths.contains(relPath)) {
            materializeSymlink(fileHashEntry, materializedPaths);
        }
        symlinkIntegrityCheck(fileHashEntry);
        materializedPaths.add(relPath);
        return;
    }
    // TODO(alisdair04,ruibm,shivanker): materialize directories
    if (fileHashEntry.isIsDirectory()) {
        materializeDirectory(relPath, fileHashEntry, remainingRelPaths);
        materializedPaths.add(relPath);
        return;
    }
    projectFilesystem.createParentDirs(projectFilesystem.resolve(relPath));
    // Download contents outside of sync block, so that fetches happen in parallel.
    // For a few cases we might get duplicate fetches, but this is much better than single
    // threaded fetches.
    Preconditions.checkState(provider.materializeFileContents(fileHashEntry, absPath), "[Stampede] Missing source file [%s] for FileHashEntry=[%s]", absPath, fileHashEntry);
    absPath.toFile().setExecutable(fileHashEntry.isExecutable);
    synchronized (this) {
        // as previous check wasn't inside sync block.
        if (materializedPaths.contains(relPath)) {
            return;
        }
        materializedPaths.add(relPath);
    }
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry)

Aggregations

BuildJobStateFileHashEntry (com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry)17 BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)11 Path (java.nio.file.Path)11 Test (org.junit.Test)8 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)6 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)5 ProjectFileHashCache (com.facebook.buck.util.cache.ProjectFileHashCache)3 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)2 FrontendRequest (com.facebook.buck.distributed.thrift.FrontendRequest)2 PathWithUnixSeparators (com.facebook.buck.distributed.thrift.PathWithUnixSeparators)2 FakeProjectFileHashCache (com.facebook.buck.testutil.FakeProjectFileHashCache)2 ArrayList (java.util.ArrayList)2 BuckConfig (com.facebook.buck.cli.BuckConfig)1 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)1 CASContainsResponse (com.facebook.buck.distributed.thrift.CASContainsResponse)1 FileInfo (com.facebook.buck.distributed.thrift.FileInfo)1 FrontendResponse (com.facebook.buck.distributed.thrift.FrontendResponse)1 StoreBuildGraphRequest (com.facebook.buck.distributed.thrift.StoreBuildGraphRequest)1 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)1 Parser (com.facebook.buck.parser.Parser)1