Search in sources :

Example 16 with BuildJobStateFileHashEntry

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

the class RecordingProjectFileHashCache method record.

private synchronized void record(Path relPath, Optional<String> memRelPath, HashCode hashCode, List<PathWithUnixSeparators> children) {
    LOG.verbose("Recording path: [%s]", projectFilesystem.resolve(relPath).toAbsolutePath());
    Optional<Path> pathRelativeToProjectRoot = projectFilesystem.getPathRelativeToProjectRoot(relPath);
    BuildJobStateFileHashEntry fileHashEntry = new BuildJobStateFileHashEntry();
    boolean pathIsAbsolute = allRecordedPathsAreAbsolute;
    fileHashEntry.setPathIsAbsolute(pathIsAbsolute);
    Path entryKey = pathIsAbsolute ? projectFilesystem.resolve(relPath).toAbsolutePath() : pathRelativeToProjectRoot.get();
    boolean isDirectory = projectFilesystem.isDirectory(relPath);
    Path realPath = findRealPath(relPath);
    boolean realPathInsideProject = projectFilesystem.getPathRelativeToProjectRoot(realPath).isPresent();
    // meta-data about this before it is re-materialized. See findSymlinkRoot() for more details.
    if (!realPathInsideProject && !pathIsAbsolute) {
        Pair<Path, Path> symLinkRootAndTarget = findSymlinkRoot(projectFilesystem.resolve(relPath).toAbsolutePath());
        Path symLinkRoot = projectFilesystem.getPathRelativeToProjectRoot(symLinkRootAndTarget.getFirst()).get();
        fileHashEntry.setRootSymLink(new PathWithUnixSeparators(MorePaths.pathWithUnixSeparators(symLinkRoot)));
        fileHashEntry.setRootSymLinkTarget(new PathWithUnixSeparators(MorePaths.pathWithUnixSeparators(symLinkRootAndTarget.getSecond().toAbsolutePath())));
    }
    fileHashEntry.setIsDirectory(isDirectory);
    fileHashEntry.setHashCode(hashCode.toString());
    fileHashEntry.setPath(new PathWithUnixSeparators(MorePaths.pathWithUnixSeparators(entryKey)));
    if (memRelPath.isPresent()) {
        fileHashEntry.setArchiveMemberPath(memRelPath.get().toString());
    }
    if (!isDirectory && !pathIsAbsolute && realPathInsideProject) {
        try {
            // TODO(shivanker, ruibm): Don't read everything in memory right away.
            Path absPath = projectFilesystem.resolve(relPath).toAbsolutePath();
            fileHashEntry.setContents(Files.readAllBytes(absPath));
            fileHashEntry.setIsExecutable(absPath.toFile().canExecute());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else if (isDirectory && !pathIsAbsolute && realPathInsideProject) {
        fileHashEntry.setChildren(children);
    }
    fileHashEntry.setMaterializeDuringPreloading(materializeCurrentFileDuringPreloading);
    // TODO(alisdair04): handling for symlink to internal directory (including infinite loop).
    remoteFileHashes.addEntry(fileHashEntry);
}
Also used : ArchiveMemberPath(com.facebook.buck.io.ArchiveMemberPath) Path(java.nio.file.Path) BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) IOException(java.io.IOException) PathWithUnixSeparators(com.facebook.buck.distributed.thrift.PathWithUnixSeparators)

Example 17 with BuildJobStateFileHashEntry

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

the class DistBuildService method uploadTargetGraph.

public ListenableFuture<Void> uploadTargetGraph(final BuildJobState buildJobStateArg, final StampedeId stampedeId, ListeningExecutorService executorService) {
    // TODO(shivanker): We shouldn't be doing this. Fix after we stop reading all files into memory.
    final BuildJobState buildJobState = buildJobStateArg.deepCopy();
    return executorService.submit(() -> {
        // Get rid of file contents from buildJobState
        for (BuildJobStateFileHashes cell : buildJobState.getFileHashes()) {
            if (!cell.isSetEntries()) {
                continue;
            }
            for (BuildJobStateFileHashEntry file : cell.getEntries()) {
                file.unsetContents();
            }
        }
        // Now serialize and send the whole buildJobState
        StoreBuildGraphRequest storeBuildGraphRequest = new StoreBuildGraphRequest();
        storeBuildGraphRequest.setStampedeId(stampedeId);
        storeBuildGraphRequest.setBuildGraph(BuildJobStateSerializer.serialize(buildJobState));
        FrontendRequest request = new FrontendRequest();
        request.setType(FrontendRequestType.STORE_BUILD_GRAPH);
        request.setStoreBuildGraphRequest(storeBuildGraphRequest);
        makeRequestChecked(request);
        // No response expected.
        return null;
    });
}
Also used : BuildJobStateFileHashEntry(com.facebook.buck.distributed.thrift.BuildJobStateFileHashEntry) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) StoreBuildGraphRequest(com.facebook.buck.distributed.thrift.StoreBuildGraphRequest) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest)

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