Skip to content

Commit f17ee9a

Browse files
authored
Merge pull request #10360 from benlangmuir/clang-depscan-log
[clang][cas] Pass through LLVM_CAS_LOG env var to the depscan daemon
2 parents 126bcc9 + f6a775f commit f17ee9a

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

clang/test/CAS/depscan-cas-log.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Ensure both the first clang process and the daemon have logging enabled.
2+
// It's hard to check this exhaustively, but in practice if the daemon does not
3+
// enable logging there are currently zero records in the log.
4+
5+
// RUN: rm -rf %t && mkdir %t
6+
// RUN: env LLVM_CACHE_CAS_PATH=%t/cas LLVM_CAS_LOG=1 %clang \
7+
// RUN: -cc1depscan -fdepscan=daemon -fdepscan-include-tree -o - \
8+
// RUN: -cc1-args -cc1 -triple x86_64-apple-macosx11.0.0 -emit-obj %s -o %t/t.o -fcas-path %t/cas
9+
// RUN: FileCheck %s --input-file %t/cas/v1.log
10+
11+
// CHECK: [[PID1:[0-9]*]] {{[0-9]*}}: mmap '{{.*}}v8.index'
12+
// CHECK: [[PID1]] {{[0-9]*}}: create subtrie
13+
14+
// CHECK: [[PID2:[0-9]*]] {{[0-9]*}}: mmap '{{.*}}v8.index'
15+
// Even a minimal compilation involves at least 9 records for the cache key.
16+
// CHECK-COUNT-9: [[PID2]] {{[0-9]*}}: create record
17+
18+
// CHECK: [[PID1]] {{[0-9]*}}: close mmap '{{.*}}v8.index'

clang/tools/driver/cc1depscanProtocol.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/Support/Process.h"
1818
#include "llvm/Support/Signals.h"
1919
#include "llvm/Support/StringSaver.h"
20+
#include <cstdlib>
2021

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

190+
static constexpr const char *PassThroughEnv[] = {
191+
"LLVM_CAS_LOG",
192+
};
193+
SmallVector<const char *> EnvP;
194+
for (const char *Name : PassThroughEnv)
195+
if (const char *Value = getenv(Name))
196+
EnvP.push_back(Saver.save(llvm::Twine(Name) + "=" + Value).data());
197+
EnvP.push_back(nullptr);
198+
189199
::pid_t Pid;
190200
int EC = ::posix_spawn(&Pid, Args[0], /*file_actions=*/nullptr, &Attrs,
191201
const_cast<char **>(LaunchArgs.data()),
192-
/*envp=*/nullptr);
202+
const_cast<char **>(EnvP.data()));
193203
if (EC)
194204
return llvm::errorCodeToError(std::error_code(EC, std::generic_category()));
195205

0 commit comments

Comments
 (0)