1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

Reland: [clang driver] Move default module cache from system temporary directory

This fixes a unit test. Otherwise here is the original commit:

1) Shared writable directories like /tmp are a security problem.
2) Systems provide dedicated cache directories these days anyway.
3) This also refines LLVM's cache_directory() on Darwin platforms to use
   the Darwin per-user cache directory.

Reviewers: compnerd, aprantl, jakehehrlich, espindola, respindola, ilya-biryukov, pcc, sammccall

Reviewed By: compnerd, sammccall

Subscribers: hiraditya, llvm-commits, cfe-commits

Tags: #clang, #llvm

Differential Revision: https://reviews.llvm.org/D82362
This commit is contained in:
David Zarzycki 2020-06-23 05:43:51 -04:00
parent 139cbe87ac
commit 48aa39a9ee
2 changed files with 23 additions and 14 deletions

View File

@ -1133,19 +1133,6 @@ bool home_directory(SmallVectorImpl<char> &result) {
return true;
}
bool cache_directory(SmallVectorImpl<char> &result) {
if (const char *RequestedDir = getenv("XDG_CACHE_HOME")) {
result.clear();
result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
return true;
}
if (!home_directory(result)) {
return false;
}
append(result, ".cache");
return true;
}
static bool getDarwinConfDir(bool TempDir, SmallVectorImpl<char> &Result) {
#if defined(_CS_DARWIN_USER_TEMP_DIR) && defined(_CS_DARWIN_USER_CACHE_DIR)
// On Darwin, use DARWIN_USER_TEMP_DIR or DARWIN_USER_CACHE_DIR.
@ -1171,6 +1158,27 @@ static bool getDarwinConfDir(bool TempDir, SmallVectorImpl<char> &Result) {
return false;
}
bool cache_directory(SmallVectorImpl<char> &result) {
#ifdef __APPLE__
if (getDarwinConfDir(false/*tempDir*/, result)) {
return true;
}
#else
// XDG_CACHE_HOME as defined in the XDG Base Directory Specification:
// http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
if (const char *RequestedDir = getenv("XDG_CACHE_HOME")) {
result.clear();
result.append(RequestedDir, RequestedDir + strlen(RequestedDir));
return true;
}
#endif
if (!home_directory(result)) {
return false;
}
append(result, ".cache");
return true;
}
static const char *getEnvTempDir() {
// Check whether the temporary directory is specified by an environment
// variable.

View File

@ -424,7 +424,8 @@ TEST(Support, HomeDirectory) {
}
}
#ifdef LLVM_ON_UNIX
// Apple has their own solution for this.
#if defined(LLVM_ON_UNIX) && !defined(__APPLE__)
TEST(Support, HomeDirectoryWithNoEnv) {
WithEnv Env("HOME", nullptr);