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()))));
}
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)));
}
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());
}
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());
}
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)));
}
Aggregations