Skip to content

[clang][cas] Pass through LLVM_CAS_LOG env var to the depscan daemon #10360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 27, 2025
Merged
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
18 changes: 18 additions & 0 deletions clang/test/CAS/depscan-cas-log.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Ensure both the first clang process and the daemon have logging enabled.
// It's hard to check this exhaustively, but in practice if the daemon does not
// enable logging there are currently zero records in the log.

// RUN: rm -rf %t && mkdir %t
// RUN: env LLVM_CACHE_CAS_PATH=%t/cas LLVM_CAS_LOG=1 %clang \
// RUN: -cc1depscan -fdepscan=daemon -fdepscan-include-tree -o - \
// RUN: -cc1-args -cc1 -triple x86_64-apple-macosx11.0.0 -emit-obj %s -o %t/t.o -fcas-path %t/cas
// RUN: FileCheck %s --input-file %t/cas/v1.log

// CHECK: [[PID1:[0-9]*]] {{[0-9]*}}: mmap '{{.*}}v8.index'
// CHECK: [[PID1]] {{[0-9]*}}: create subtrie

// CHECK: [[PID2:[0-9]*]] {{[0-9]*}}: mmap '{{.*}}v8.index'
// Even a minimal compilation involves at least 9 records for the cache key.
// CHECK-COUNT-9: [[PID2]] {{[0-9]*}}: create record

// CHECK: [[PID1]] {{[0-9]*}}: close mmap '{{.*}}v8.index'
12 changes: 11 additions & 1 deletion clang/tools/driver/cc1depscanProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "llvm/Support/Process.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/StringSaver.h"
#include <cstdlib>

#if LLVM_ON_UNIX
#include <sys/socket.h> // FIXME: Unix-only. Not portable.
Expand Down Expand Up @@ -186,10 +187,19 @@ Expected<ScanDaemon> ScanDaemon::launchDaemon(StringRef BasePath,
return llvm::errorCodeToError(std::error_code(EC, std::generic_category()));
#endif

static constexpr const char *PassThroughEnv[] = {
"LLVM_CAS_LOG",
};
SmallVector<const char *> EnvP;
for (const char *Name : PassThroughEnv)
if (const char *Value = getenv(Name))
EnvP.push_back(Saver.save(llvm::Twine(Name) + "=" + Value).data());
EnvP.push_back(nullptr);

::pid_t Pid;
int EC = ::posix_spawn(&Pid, Args[0], /*file_actions=*/nullptr, &Attrs,
const_cast<char **>(LaunchArgs.data()),
/*envp=*/nullptr);
const_cast<char **>(EnvP.data()));
if (EC)
return llvm::errorCodeToError(std::error_code(EC, std::generic_category()));

Expand Down