Files
compute-runtime/shared/source/compiler_interface/linux/os_compiler_cache_helper.cpp
Diedrich, Kamil 5a4a2ab8ab feature: Add new environment variables for compiler cache
This patch add new environment variables to control compiler cache.
Works as follow: If persistent cache is set driver check if NEO_CACHE_DIR
is set. If not then driver checks XDG_CACHE_HOME - If exists
then driver create neo_compiler_cache folder, if
not then driver checks HOME directory. If each NEO_CACHE_DIR,
XDG_CACHE_HOME and HOME are not set then compiler cache is disabled.
Current support is for Linux only.

Signed-off-by: Diedrich, Kamil <kamil.diedrich@intel.com>

Related-To: NEO-4262
2023-05-12 10:21:27 +02:00

57 lines
1.5 KiB
C++

/*
* Copyright (C) 2023 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/compiler_interface/os_compiler_cache_helper.h"
#include "shared/source/os_interface/linux/sys_calls.h"
#include "shared/source/utilities/debug_settings_reader.h"
namespace NEO {
bool createCompilerCachePath(std::string &cacheDir) {
if (NEO::SysCalls::pathExists(cacheDir)) {
if (NEO::SysCalls::pathExists(cacheDir + "neo_compiler_cache")) {
cacheDir = cacheDir + "neo_compiler_cache";
return true;
}
if (NEO::SysCalls::mkdir(cacheDir + "neo_compiler_cache") == 0) {
cacheDir = cacheDir + "neo_compiler_cache";
return true;
} else {
if (errno == EEXIST) {
cacheDir = cacheDir + "neo_compiler_cache";
return true;
}
}
}
cacheDir = "";
return false;
}
bool checkDefaultCacheDirSettings(std::string &cacheDir, SettingsReader *reader) {
std::string emptyString = "";
cacheDir = reader->getSetting(reader->appSpecificLocation("XDG_CACHE_HOME"), emptyString);
if (cacheDir.empty()) {
cacheDir = reader->getSetting(reader->appSpecificLocation("HOME"), emptyString);
if (cacheDir.empty()) {
return false;
}
cacheDir = cacheDir + ".cache/";
return createCompilerCachePath(cacheDir);
}
if (NEO::SysCalls::pathExists(cacheDir)) {
return createCompilerCachePath(cacheDir);
}
return false;
}
} // namespace NEO