Search in sources :

Example 16 with BuildJobStateFileHashes

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

the class MaterializerProjectFileHashCacheTest method testMaterializeDirectoryHelper.

private void testMaterializeDirectoryHelper(boolean materializeDuringPreloading, MaterializeFunction materializeFunction) throws IOException {
    // Scenario:
    // file hash entries for:
    // /a - folder
    // /a/b - folder
    // /a/b/c - file
    // /a/b/d - folder
    // /a/e - file
    // => preload: ensure all folders created and files touched
    // => materialize(/a): ensure all folders and sub-directories/files created
    assumeTrue(!Platform.detect().equals(Platform.WINDOWS));
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(projectDir.getRoot().toPath());
    Path pathDirA = projectFilesystem.resolve("a");
    Path pathDirAb = projectFilesystem.resolve("a/b");
    Path pathFileAbc = projectFilesystem.resolve("a/b/c");
    Path pathDirAbd = projectFilesystem.resolve("a/b/d");
    Path pathFileAe = projectFilesystem.resolve("a/e");
    Path relativePathDirA = Paths.get("a");
    Path relativePathDirAb = Paths.get("a/b");
    Path relativePathFileAbc = Paths.get("a/b/c");
    Path relativePathDirAbd = Paths.get("a/b/d");
    Path relativePathFileAe = Paths.get("a/e");
    BuildJobStateFileHashes fileHashes = new BuildJobStateFileHashes();
    BuildJobStateFileHashEntry dirAFileHashEntry = new BuildJobStateFileHashEntry();
    dirAFileHashEntry.setPath(unixPath(relativePathDirA));
    dirAFileHashEntry.setHashCode(EXAMPLE_HASHCODE.toString());
    dirAFileHashEntry.setIsDirectory(true);
    dirAFileHashEntry.setChildren(ImmutableList.of(unixPath(relativePathDirAb), unixPath(relativePathFileAe)));
    dirAFileHashEntry.setMaterializeDuringPreloading(materializeDuringPreloading);
    fileHashes.addToEntries(dirAFileHashEntry);
    BuildJobStateFileHashEntry dirAbFileHashEntry = new BuildJobStateFileHashEntry();
    dirAbFileHashEntry.setPath(unixPath(relativePathDirAb));
    dirAbFileHashEntry.setHashCode(EXAMPLE_HASHCODE.toString());
    dirAbFileHashEntry.setIsDirectory(true);
    dirAbFileHashEntry.setChildren(ImmutableList.of(unixPath(relativePathFileAbc), unixPath(relativePathDirAbd)));
    dirAbFileHashEntry.setMaterializeDuringPreloading(materializeDuringPreloading);
    fileHashes.addToEntries(dirAbFileHashEntry);
    BuildJobStateFileHashEntry fileAbcFileHashEntry = new BuildJobStateFileHashEntry();
    fileAbcFileHashEntry.setPath(unixPath(relativePathFileAbc));
    fileAbcFileHashEntry.setHashCode(EXAMPLE_HASHCODE.toString());
    fileAbcFileHashEntry.setContents(FILE_CONTENTS.getBytes(StandardCharsets.UTF_8));
    fileAbcFileHashEntry.setIsDirectory(false);
    fileAbcFileHashEntry.setMaterializeDuringPreloading(materializeDuringPreloading);
    fileHashes.addToEntries(fileAbcFileHashEntry);
    BuildJobStateFileHashEntry dirAbdFileHashEntry = new BuildJobStateFileHashEntry();
    dirAbdFileHashEntry.setPath(unixPath(relativePathDirAbd));
    dirAbdFileHashEntry.setHashCode(EXAMPLE_HASHCODE.toString());
    dirAbdFileHashEntry.setIsDirectory(true);
    dirAbdFileHashEntry.setChildren(ImmutableList.of());
    dirAbdFileHashEntry.setMaterializeDuringPreloading(materializeDuringPreloading);
    fileHashes.addToEntries(dirAbdFileHashEntry);
    BuildJobStateFileHashEntry fileAeFileHashEntry = new BuildJobStateFileHashEntry();
    fileAeFileHashEntry.setPath(unixPath(relativePathFileAe));
    fileAeFileHashEntry.setHashCode(EXAMPLE_HASHCODE.toString());
    fileAeFileHashEntry.setContents(FILE_CONTENTS_TWO.getBytes(StandardCharsets.UTF_8));
    fileAeFileHashEntry.setIsDirectory(false);
    fileAeFileHashEntry.setMaterializeDuringPreloading(materializeDuringPreloading);
    fileHashes.addToEntries(fileAeFileHashEntry);
    InlineContentsProvider inlineProvider = new InlineContentsProvider();
    ProjectFileHashCache mockFileHashCache = EasyMock.createNiceMock(ProjectFileHashCache.class);
    expect(mockFileHashCache.getFilesystem()).andReturn(projectFilesystem).atLeastOnce();
    replay(mockFileHashCache);
    MaterializerProjectFileHashCache fileMaterializer = new MaterializerProjectFileHashCache(mockFileHashCache, fileHashes, inlineProvider);
    assertFalse(pathDirA.toFile().exists());
    assertFalse(pathDirAb.toFile().exists());
    assertFalse(pathFileAbc.toFile().exists());
    assertFalse(pathDirAbd.toFile().exists());
    assertFalse(pathFileAe.toFile().exists());
    materializeFunction.execute(fileMaterializer, pathDirA);
    assertTrue(pathDirA.toFile().exists());
    assertTrue(pathDirAb.toFile().exists());
    assertTrue(pathFileAbc.toFile().exists());
    assertTrue(pathDirAbd.toFile().exists());
    assertTrue(pathFileAe.toFile().exists());
}
Also used : Path(java.nio.file.Path) BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Example 17 with BuildJobStateFileHashes

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

the class MaterializerProjectFileHashCacheTest method testSymlinkToFileWithinExternalDirectory.

public void testSymlinkToFileWithinExternalDirectory(HashCode fileHashEntryHashCode, HashCode actualHashCode, MaterializeFunction materializeFunction, int expectCallsToGetHashMethod) throws IOException {
    // Scenario:
    //  path: /project/linktoexternaldir/externalfile
    //  symlink root: /project/linktoexternaldir -> /externalDir
    // => check that /project/linktoexternaldir/externalfile -> /externalDir/externalfile
    assumeTrue(!Platform.detect().equals(Platform.WINDOWS));
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(projectDir.getRoot().toPath());
    File externalFile = externalDir.newFile("externalfile");
    Path symlinkRoot = projectFilesystem.resolve("linktoexternaldir");
    Path relativeSymlinkRoot = Paths.get("linktoexternaldir");
    // /project/linktoexternaldir/externalfile
    Path symlink = symlinkRoot.resolve("externalfile");
    Path relativeSymlink = projectFilesystem.getPathRelativeToProjectRoot(symlink).get();
    BuildJobStateFileHashEntry symlinkFileHashEntry = new BuildJobStateFileHashEntry();
    symlinkFileHashEntry.setRootSymLink(unixPath(relativeSymlinkRoot));
    symlinkFileHashEntry.setRootSymLinkTarget(unixPath(externalDir.getRoot().toPath()));
    symlinkFileHashEntry.setPath(unixPath(relativeSymlink));
    symlinkFileHashEntry.setHashCode(fileHashEntryHashCode.toString());
    BuildJobStateFileHashes fileHashes = new BuildJobStateFileHashes();
    fileHashes.addToEntries(symlinkFileHashEntry);
    FileContentsProvider mockFileProvider = EasyMock.createMock(FileContentsProvider.class);
    ProjectFileHashCache mockFileHashCache = EasyMock.createNiceMock(ProjectFileHashCache.class);
    expect(mockFileHashCache.getFilesystem()).andReturn(projectFilesystem).atLeastOnce();
    if (expectCallsToGetHashMethod > 0) {
        expect(mockFileHashCache.get(relativeSymlink)).andReturn(actualHashCode).times(expectCallsToGetHashMethod);
    }
    replay(mockFileHashCache);
    MaterializerProjectFileHashCache fileMaterializer = new MaterializerProjectFileHashCache(mockFileHashCache, fileHashes, mockFileProvider);
    assertFalse(symlink.toFile().exists());
    materializeFunction.execute(fileMaterializer, relativeSymlink);
    assertTrue(symlink.toFile().exists());
    assertThat(symlink.toRealPath(), Matchers.equalTo(externalFile.toPath().toRealPath()));
    verify(mockFileHashCache);
}
Also used : Path(java.nio.file.Path) BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) File(java.io.File)

Example 18 with BuildJobStateFileHashes

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

the class MaterializerProjectFileHashCacheTest method testEntryForRealFile.

private Path testEntryForRealFile(boolean materializeDuringPreloading, MaterializeFunction materializeFunction) throws IOException {
    assumeTrue(!Platform.detect().equals(Platform.WINDOWS));
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(projectDir.getRoot().toPath());
    Path realFileAbsPath = projectFilesystem.resolve("realfile");
    Path relativeRealFile = Paths.get("realfile");
    BuildJobStateFileHashEntry realFileHashEntry = new BuildJobStateFileHashEntry();
    realFileHashEntry.setPath(unixPath(relativeRealFile));
    realFileHashEntry.setHashCode(EXAMPLE_HASHCODE.toString());
    realFileHashEntry.setContents(FILE_CONTENTS.getBytes(StandardCharsets.UTF_8));
    realFileHashEntry.setMaterializeDuringPreloading(materializeDuringPreloading);
    BuildJobStateFileHashes fileHashes = new BuildJobStateFileHashes();
    fileHashes.addToEntries(realFileHashEntry);
    InlineContentsProvider inlineProvider = new InlineContentsProvider();
    ProjectFileHashCache mockFileHashCache = EasyMock.createNiceMock(ProjectFileHashCache.class);
    expect(mockFileHashCache.getFilesystem()).andReturn(projectFilesystem).atLeastOnce();
    replay(mockFileHashCache);
    MaterializerProjectFileHashCache fileMaterializer = new MaterializerProjectFileHashCache(mockFileHashCache, fileHashes, inlineProvider);
    materializeFunction.execute(fileMaterializer, realFileAbsPath);
    return realFileAbsPath;
}
Also used : Path(java.nio.file.Path) BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem)

Example 19 with BuildJobStateFileHashes

use of com.facebook.buck.distributed.thrift.BuildJobStateFileHashes 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 20 with BuildJobStateFileHashes

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

the class DistBuildState method createRemoteFileHashCache.

public ProjectFileHashCache createRemoteFileHashCache(ProjectFileHashCache decoratedCache) {
    BuildJobStateFileHashes remoteFileHashes = fileHashes.get(decoratedCache.getFilesystem());
    if (remoteFileHashes == null) {
        // decorated.
        return decoratedCache;
    }
    ProjectFileHashCache remoteCache = DistBuildFileHashes.createFileHashCache(decoratedCache, remoteFileHashes);
    return remoteCache;
}
Also used : BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache)

Aggregations

BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)21 Test (org.junit.Test)14 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)12 BuildJobStateFileHashEntry (com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry)11 ProjectFileHashCache (com.facebook.buck.util.cache.ProjectFileHashCache)9 Path (java.nio.file.Path)9 ArchiveMemberPath (com.facebook.buck.io.ArchiveMemberPath)6 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)4 FrontendRequest (com.facebook.buck.distributed.thrift.FrontendRequest)3 FakeProjectFileHashCache (com.facebook.buck.testutil.FakeProjectFileHashCache)3 ArrayList (java.util.ArrayList)3 BuckConfig (com.facebook.buck.cli.BuckConfig)2 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)2 FrontendResponse (com.facebook.buck.distributed.thrift.FrontendResponse)2 BroadcastEventListener (com.facebook.buck.event.listener.BroadcastEventListener)2 Parser (com.facebook.buck.parser.Parser)2 ParserConfig (com.facebook.buck.parser.ParserConfig)2 ArchiveMemberSourcePath (com.facebook.buck.rules.ArchiveMemberSourcePath)2 Cell (com.facebook.buck.rules.Cell)2 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)2