Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions clang/test/CAS/clang-cache-session-daemon.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Check that a depscan daemon spawned on demand can serve a compilation.
// LLVM_CACHE_BUILD_SESSION_ID is what asks for one; the launcher turns it into
// -fdepscan=daemon -fdepscan-share-identifier=<id>, and the client locates the
// daemon under the system temporary directory before connecting to it.

// REQUIRES: ondisk_cas
// REQUIRES: clang-cc1daemon

// RUN: rm -rf %t && mkdir -p %t

// RUN: env LLVM_CACHE_CAS_PATH=%t/cas LLVM_CACHE_BUILD_SESSION_ID=%basename_t %clang-cache %clang -c %s -o %t/test.o -Xclang -Rcompile-job-cache 2>&1 | FileCheck %s -check-prefix=CACHE-MISS
// RUN: env LLVM_CACHE_CAS_PATH=%t/cas LLVM_CACHE_BUILD_SESSION_ID=%basename_t %clang-cache %clang -c %s -o %t/test.o -Xclang -Rcompile-job-cache 2>&1 | FileCheck %s -check-prefix=CACHE-HIT

// CACHE-MISS: remark: compile job cache miss
// CACHE-HIT: remark: compile job cache hit

int main() { return 0; }
16 changes: 14 additions & 2 deletions clang/tools/driver/cc1depscanProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "llvm/Support/Allocator.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/IOSandbox.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Signals.h"
Expand All @@ -33,6 +34,11 @@ using namespace llvm;
std::string cc1depscand::getBasePath(StringRef DaemonKey) {
assert(!DaemonKey.empty() && "Expected valid daemon key");

// Looking up the daemon's socket path is not compiler IO. On Windows,
// system_temp_directory() makes the path absolute, which the sandbox
// would reject.
auto BypassSandbox = llvm::sys::sandbox::scopedDisable();

// Construct the path.
SmallString<128> BasePath;
llvm::sys::path::system_temp_directory(/*ErasedOnReboot=*/true, BasePath);
Expand Down Expand Up @@ -243,8 +249,14 @@ Expected<ScanDaemon> ScanDaemon::launchDaemon(StringRef BasePath,
std::optional<ArrayRef<StringRef>> EnvOpt =
Env.empty() ? std::nullopt : std::optional<ArrayRef<StringRef>>(Env);

llvm::sys::ProcessInfo PI = llvm::sys::ExecuteNoWait(
Arg0, LaunchArgs, EnvOpt, {}, 0, &ErrMsg, &ExecutionFailed);
llvm::sys::ProcessInfo PI = [&] {
// Starting the daemon is not compiler IO either. On Windows,
// ExecuteNoWait() checks that the program exists before launching it,
// and the sandbox would reject those checks.
auto BypassSandbox = llvm::sys::sandbox::scopedDisable();
return llvm::sys::ExecuteNoWait(Arg0, LaunchArgs, EnvOpt, {}, 0, &ErrMsg,
&ExecutionFailed);
}();

if (ExecutionFailed || PI.Pid == llvm::sys::ProcessInfo::InvalidPid)
return llvm::createStringError(std::make_error_code(std::errc::invalid_argument),
Expand Down