Search in sources :

Example 11 with BuildJobStateFileHashes

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

the class RecordingFileHashLoaderTest method testRecordsSymlinkToFileWithinExternalDirectory.

@Test
public void testRecordsSymlinkToFileWithinExternalDirectory() throws IOException {
    assumeTrue(!Platform.detect().equals(Platform.WINDOWS));
    // Scenario:
    // /project/linktoexternaldir/externalfile -> /externalDir/externalfile
    // => create link for parent dir: /project/linktoexternaldir -> /externalDir
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(projectDir.getRoot().toPath());
    externalDir.newFile("externalfile");
    Path symlinkRoot = projectDir.getRoot().toPath().resolve("linktoexternaldir");
    Files.createSymbolicLink(symlinkRoot, externalDir.getRoot().toPath());
    Path symlink = projectFilesystem.relativize(symlinkRoot.resolve(// /project/linktoexternaldir/externalfile
    "externalfile"));
    RecordedFileHashes recordedFileHashes = new RecordedFileHashes(0);
    BuildJobStateFileHashes fileHashes = recordedFileHashes.getRemoteFileHashes();
    FakeProjectFileHashCache delegateCache = new FakeProjectFileHashCache(projectFilesystem, ImmutableMap.of(symlink, EXAMPLE_HASHCODE));
    RecordingProjectFileHashCache recordingLoader = RecordingProjectFileHashCache.createForCellRoot(delegateCache, recordedFileHashes, new DistBuildConfig(FakeBuckConfig.builder().build()));
    recordingLoader.get(symlink);
    assertThat(fileHashes.getEntries().size(), Matchers.equalTo(1));
    BuildJobStateFileHashEntry fileHashEntry = fileHashes.getEntries().get(0);
    assertTrue(fileHashEntry.isSetRootSymLink());
    assertThat(fileHashEntry.getRootSymLink(), Matchers.equalTo((unixPath("linktoexternaldir"))));
    assertTrue(fileHashEntry.isSetRootSymLink());
    assertThat(fileHashEntry.getRootSymLinkTarget(), Matchers.equalTo((unixPath(externalDir.getRoot().toPath().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 12 with BuildJobStateFileHashes

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

the class RecordingFileHashLoaderTest method testRecordsDirectoryAndRecursivelyRecordsChildren.

@Test
public void testRecordsDirectoryAndRecursivelyRecordsChildren() throws IOException {
    // Scenario:
    // /a - folder
    // /a/b - folder
    // /a/b/c - file
    // /a/b/d - folder
    // /a/e - file
    // => entries for all files and folders.
    // => entries for dirs /a and /a/b list their direct children
    assumeTrue(!Platform.detect().equals(Platform.WINDOWS));
    ProjectFilesystem fs = new ProjectFilesystem(projectDir.getRoot().toPath());
    Path pathDirA = Files.createDirectories(fs.getRootPath().resolve("a"));
    Files.createDirectories(fs.getRootPath().resolve("a/b"));
    Files.createFile(fs.getRootPath().resolve("a/b/c"));
    Files.createDirectories(fs.getRootPath().resolve("a/b/d"));
    Files.createFile(fs.getRootPath().resolve("a/e"));
    RecordedFileHashes recordedFileHashes = new RecordedFileHashes(0);
    BuildJobStateFileHashes fileHashes = recordedFileHashes.getRemoteFileHashes();
    ProjectFileHashCache delegateCacheMock = EasyMock.createMock(ProjectFileHashCache.class);
    expect(delegateCacheMock.getFilesystem()).andReturn(fs);
    expect(delegateCacheMock.get(anyObject(Path.class))).andReturn(EXAMPLE_HASHCODE).anyTimes();
    replay(delegateCacheMock);
    RecordingProjectFileHashCache recordingLoader = RecordingProjectFileHashCache.createForCellRoot(delegateCacheMock, recordedFileHashes, new DistBuildConfig(FakeBuckConfig.builder().build()));
    recordingLoader.get(fs.relativize(pathDirA));
    assertThat(fileHashes.getEntries().size(), // all folders and files
    Matchers.equalTo(5));
    assertThat(fileHashes.getEntries(), IsCollectionContaining.hasItems(new FileHashEntryMatcher("a", true), new FileHashEntryMatcher("a/b", true), new FileHashEntryMatcher("a/b/c", false), new FileHashEntryMatcher("a/b/d", true), new FileHashEntryMatcher("a/e", false)));
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache) FakeProjectFileHashCache(com.facebook.buck.testutil.FakeProjectFileHashCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FileHashEntryMatcher(com.facebook.buck.testutil.FileHashEntryMatcher) Test(org.junit.Test)

Example 13 with BuildJobStateFileHashes

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

the class DistBuildFileHashesIntegrationTest method crossCellDoesNotCauseAbsolutePathSrcs.

@Test
public void crossCellDoesNotCauseAbsolutePathSrcs() throws Exception {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "cross_cell", temporaryFolder);
    workspace.setUp();
    ProjectFilesystem rootFs = new ProjectFilesystem(temporaryFolder.getRoot().toAbsolutePath().resolve("root_cell"));
    ProjectFilesystem secondaryFs = new ProjectFilesystem(temporaryFolder.getRoot().toAbsolutePath().resolve("secondary_cell"));
    BuckConfig rootCellConfig = FakeBuckConfig.builder().setFilesystem(rootFs).setSections("[repositories]", "cross_cell_secondary = " + secondaryFs.getRootPath().toAbsolutePath()).build();
    Cell rootCell = new TestCellBuilder().setBuckConfig(rootCellConfig).setFilesystem(rootFs).build();
    TypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
    ConstructorArgMarshaller constructorArgMarshaller = new ConstructorArgMarshaller(typeCoercerFactory);
    Parser parser = new Parser(new BroadcastEventListener(), rootCellConfig.getView(ParserConfig.class), typeCoercerFactory, constructorArgMarshaller);
    TargetGraph targetGraph = parser.buildTargetGraph(BuckEventBusFactory.newInstance(), rootCell, /* enableProfiling */
    false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
    DistBuildTargetGraphCodec targetGraphCodec = DistBuildStateTest.createDefaultCodec(rootCell, Optional.of(parser));
    BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(rootCell), createDistBuildFileHashes(targetGraph, rootCell), targetGraphCodec, targetGraph, ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
    assertNotNull(dump);
    assertEquals(2, dump.getFileHashesSize());
    List<BuildJobStateFileHashes> sortedHashes = dump.getFileHashes().stream().sorted(Comparator.comparingInt(BuildJobStateFileHashes::getCellIndex)).collect(Collectors.toList());
    BuildJobStateFileHashes rootCellHashes = sortedHashes.get(0);
    assertEquals(1, rootCellHashes.getEntriesSize());
    assertEquals("A.java", rootCellHashes.getEntries().get(0).getPath().getPath());
    BuildJobStateFileHashes secondaryCellHashes = sortedHashes.get(1);
    assertEquals(1, secondaryCellHashes.getEntriesSize());
    assertEquals("B.java", secondaryCellHashes.getEntries().get(0).getPath().getPath());
}
Also used : BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) TargetGraph(com.facebook.buck.rules.TargetGraph) TypeCoercerFactory(com.facebook.buck.rules.coercer.TypeCoercerFactory) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Parser(com.facebook.buck.parser.Parser) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Cell(com.facebook.buck.rules.Cell) ParserConfig(com.facebook.buck.parser.ParserConfig) Test(org.junit.Test)

Example 14 with BuildJobStateFileHashes

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

the class DistBuildFileHashesIntegrationTest method symlinkPathsRecordedInRootCell.

@Test
public void symlinkPathsRecordedInRootCell() throws Exception {
    Assume.assumeTrue(Platform.detect() != Platform.WINDOWS);
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "symlink", temporaryFolder);
    workspace.setUp();
    ProjectFilesystem rootFs = new ProjectFilesystem(temporaryFolder.getRoot().toAbsolutePath().resolve("root_cell"));
    Path absSymlinkFilePath = rootFs.resolve("../" + SYMLINK_FILE_NAME);
    Path symLinkPath = rootFs.resolve(SYMLINK_FILE_NAME);
    rootFs.createSymLink(symLinkPath, absSymlinkFilePath, false);
    BuckConfig rootCellConfig = FakeBuckConfig.builder().setFilesystem(rootFs).build();
    Cell rootCell = new TestCellBuilder().setBuckConfig(rootCellConfig).setFilesystem(rootFs).build();
    TypeCoercerFactory typeCoercerFactory = new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance());
    ConstructorArgMarshaller constructorArgMarshaller = new ConstructorArgMarshaller(typeCoercerFactory);
    Parser parser = new Parser(new BroadcastEventListener(), rootCellConfig.getView(ParserConfig.class), typeCoercerFactory, constructorArgMarshaller);
    TargetGraph targetGraph = parser.buildTargetGraph(BuckEventBusFactory.newInstance(), rootCell, /* enableProfiling */
    false, MoreExecutors.listeningDecorator(Executors.newSingleThreadExecutor()), ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
    DistBuildTargetGraphCodec targetGraphCodec = DistBuildStateTest.createDefaultCodec(rootCell, Optional.of(parser));
    BuildJobState dump = DistBuildState.dump(new DistBuildCellIndexer(rootCell), createDistBuildFileHashes(targetGraph, rootCell), targetGraphCodec, targetGraph, ImmutableSet.of(BuildTargetFactory.newInstance(rootFs.getRootPath(), "//:libA")));
    assertNotNull(dump);
    assertEquals(1, dump.getFileHashesSize());
    BuildJobStateFileHashes rootCellHashes = dump.getFileHashes().get(0);
    assertEquals(2, rootCellHashes.getEntriesSize());
    BuildJobStateFileHashEntry symLinkEntry = rootCellHashes.getEntries().stream().filter(x -> x.isSetRootSymLink()).findFirst().get();
    String expectedPath = temporaryFolder.getRoot().resolve(SYMLINK_FILE_NAME).toAbsolutePath().toString();
    assertEquals(MorePaths.pathWithUnixSeparators(expectedPath), symLinkEntry.getRootSymLinkTarget().getPath());
    assertEquals(SYMLINK_FILE_NAME, symLinkEntry.getRootSymLink().getPath());
    BuildJobStateFileHashEntry relPathEntry = rootCellHashes.getEntries().stream().filter(x -> !x.isPathIsAbsolute()).findFirst().get();
    assertEquals("A.java", relPathEntry.getPath().getPath());
}
Also used : Path(java.nio.file.Path) BroadcastEventListener(com.facebook.buck.event.listener.BroadcastEventListener) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) TargetGraph(com.facebook.buck.rules.TargetGraph) TypeCoercerFactory(com.facebook.buck.rules.coercer.TypeCoercerFactory) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) TestCellBuilder(com.facebook.buck.rules.TestCellBuilder) Parser(com.facebook.buck.parser.Parser) BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) BuckConfig(com.facebook.buck.cli.BuckConfig) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Cell(com.facebook.buck.rules.Cell) ParserConfig(com.facebook.buck.parser.ParserConfig) Test(org.junit.Test)

Example 15 with BuildJobStateFileHashes

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

the class DistBuildFileHashesTest method materializerWritesContents.

@Test
public void materializerWritesContents() throws Exception {
    SingleFileFixture f = new SingleFileFixture(tempDir);
    List<BuildJobStateFileHashes> fileHashes = f.distributedBuildFileHashes.getFileHashes();
    ProjectFilesystem materializeProjectFilesystem = new ProjectFilesystem(tempDir.newFolder("read_hashes").getCanonicalFile().toPath());
    ProjectFileHashCache mockCache = EasyMock.createMock(ProjectFileHashCache.class);
    EasyMock.expect(mockCache.getFilesystem()).andReturn(materializeProjectFilesystem).atLeastOnce();
    EasyMock.expect(mockCache.get(EasyMock.<Path>notNull())).andReturn(HashCode.fromInt(42)).once();
    EasyMock.replay(mockCache);
    MaterializerProjectFileHashCache materializer = new MaterializerProjectFileHashCache(mockCache, fileHashes.get(0), new InlineContentsProvider());
    materializer.get(materializeProjectFilesystem.resolve(f.javaSrcPath));
    assertThat(materializeProjectFilesystem.readFileIfItExists(f.javaSrcPath), Matchers.equalTo(Optional.of(f.writtenContents)));
}
Also used : ArchiveMemberSourcePath(com.facebook.buck.rules.ArchiveMemberSourcePath) ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) ProjectFileHashCache(com.facebook.buck.util.cache.ProjectFileHashCache) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

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