================ @@ -0,0 +1,211 @@ +//===----------------------------- Client.cpp -----------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "clang/Tooling/ModuleBuildDaemon/Client.h" +#include "clang/Basic/Version.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/FrontendDiagnostic.h" +#include "clang/Tooling/ModuleBuildDaemon/SocketMsgSupport.h" +#include "clang/Tooling/ModuleBuildDaemon/SocketSupport.h" +#include "clang/Tooling/ModuleBuildDaemon/Utils.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/ScopeExit.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Support/BLAKE3.h" + +// TODO: Make portable +#if LLVM_ON_UNIX + +#include <cerrno> +#include <filesystem> +#include <fstream> +#include <signal.h> +#include <spawn.h> +#include <string> +#include <sys/socket.h> +#include <sys/stat.h> +#include <sys/un.h> +#include <unistd.h> + +using namespace clang; +using namespace llvm; +using namespace cc1modbuildd; + +std::string cc1modbuildd::getBasePath() { + llvm::BLAKE3 Hash; + Hash.update(getClangFullVersion()); + auto HashResult = Hash.final<sizeof(uint64_t)>(); + uint64_t HashValue = + llvm::support::endian::read<uint64_t, llvm::support::native>( + HashResult.data()); + std::string Key = toString(llvm::APInt(64, HashValue), 36, /*Signed*/ false); + + // Set paths + SmallString<128> BasePath; + llvm::sys::path::system_temp_directory(/*erasedOnReboot*/ true, BasePath); + llvm::sys::path::append(BasePath, "clang-" + Key); + return BasePath.c_str(); +} + +llvm::Error cc1modbuildd::attemptHandshake(int SocketFD, + DiagnosticsEngine &Diag) { + + HandshakeMsg Request{ActionType::HANDSHAKE, StatusType::REQUEST}; + std::string Buffer = getBufferFromSocketMsg(Request); + + // Send HandshakeMsg to module build daemon + Diag.Report(diag::remark_module_build_daemon) + << "Trying to send HandshakeMsg to module build daemon"; + if (llvm::Error Err = writeToSocket(Buffer, SocketFD)) + return std::move(Err); + Diag.Report(diag::remark_module_build_daemon) + << "Successfully sent HandshakeMsg to module build daemon"; + + // Receive response from module build daemon + Diag.Report(diag::remark_module_build_daemon) + << "Waiting to receive module build daemon response"; + Expected<HandshakeMsg> MaybeServerResponse = + readSocketMsgFromSocket<HandshakeMsg>(SocketFD); + if (!MaybeServerResponse) + return std::move(MaybeServerResponse.takeError()); + HandshakeMsg ServerResponse = std::move(*MaybeServerResponse); + + assert(ServerResponse.MsgAction == ActionType::HANDSHAKE && + "Response ActionType should only ever be HANDSHAKE"); + + if (ServerResponse.MsgStatus == StatusType::SUCCESS) { + Diag.Report(diag::remark_module_build_daemon) + << "Successfully received HandshakeMsg from module build daemon"; ---------------- Bigcheese wrote:
This should just be handled by the other successfully connected remark. https://github.com/llvm/llvm-project/pull/67562 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits