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